Repository navigation
Description
Observed Behavior
Telegram has topics in forum supergroups and, since Bot API 9.3, in private chats with bots that enable forum topic mode. Each topic is a separate conversation, but agent-framework-hosting-telegram treats the whole chat as one:
telegram_session_idreturnstelegram:<bot_id>:<chat_id>for every message in a forum group (andtelegram:<bot_id>:<user_id>for every message in a private chat), so messages from different topics share one agent session and one history. A question asked in topic "Project A" is answered with context from topic "Project B".telegram_from_run(and thesendPhotooperations fromtelegram_from_streaming_run) build payloads with onlychat_idand have no way to setmessage_thread_id, which the Bot API uses to address a topic. The agent's reply is not posted in the topic the user wrote in.
Nothing in the package or in the samples under python/samples/04-hosting/ reads message_thread_id or is_topic_message.
Expected Behavior
- Messages from different topics of the same forum get different session ids, while messages in the General topic and in ordinary groups keep today's
telegram:<bot_id>:<chat_id>. - A reply to a topic message can be sent back into that topic.
Steps to Reproduce
- Build two
messageupdates for the same forum supergroup (chat.is_forum: true) withis_topic_message: trueand differentmessage_thread_idvalues. - Call
telegram_session_idon both. - Call
telegram_from_runwith the group's chat id.
Minimal Reproduction
from agent_framework import AgentResponse, Content, Message
from agent_framework_hosting_telegram import telegram_from_run, telegram_session_id
def update(thread_id: int, text: str) -> dict:
return {
"update_id": 1,
"message": {
"message_id": 10 + thread_id,
"message_thread_id": thread_id,
"is_topic_message": True,
"chat": {"id": -1001234567890, "type": "supergroup", "is_forum": True},
"from": {"id": 42, "is_bot": False, "first_name": "A"},
"text": text,
},
}
print(telegram_session_id(update(3, "plan for project A"), bot_id=1))
print(telegram_session_id(update(7, "plan for project B"), bot_id=1))
print(telegram_from_run(AgentResponse(messages=[Message("assistant", [Content.from_text(text="ok")])]), chat_id=-1001234567890))Output on main (92838b6):
telegram:1:-1001234567890
telegram:1:-1001234567890
{'method': 'sendMessage', 'payload': {'chat_id': -1001234567890, 'text': 'ok'}}
Package Versions
agent-framework-core: 1.26.0, agent-framework-hosting-telegram: 1.0.0a261106
Python Version
Python 3.12
Operating System
Windows
Regression
No, it has never handled topics.
Additional Context
The topic should be detected with is_topic_message, not with message_thread_id alone: the Bot API describes message_thread_id as the id of "a message thread or forum topic", so it is also present on ordinary supergroup reply threads, which should keep the chat-level session.
A possible direction, for discussion only:
telegram_session_idappends the thread id for topic messages:telegram:<bot_id>:<chat_or_user_id>:<message_thread_id>. This changes session ids for bots already running in topic chats, so it may need to be opt-in.telegram_from_runandtelegram_from_streaming_runaccept an optionalmessage_thread_idand add it tosendMessage/sendPhotopayloads (editMessageTextanddeleteMessageaddress a message id and need no change).- A small
telegram_message_thread_id(update)helper next totelegram_chat_id.
I would be glad to implement this after agreement on the direction.
AI assistance: the analysis, the reproduction and this report were prepared with an AI coding assistant; I ran the reproduction and checked the output above.
Acknowledgements
- I searched existing issues and did not find a duplicate.
- I personally verified this behavior and the reproduction details are authentic.
- I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
github-actions commentedon Nov 13, 2026
Reproduced on main (92838b6) with a locally constructed test based on the reported behavior: two forum-topic updates with different
message_thread_idyield the sametelegram_session_id, andtelegram_from_runemits asendMessagepayload with onlychat_id/text. Run: https://github.com/microsoft/agent-framework/actions/runs/43523082062Support boundary: unclear. I found no maintained spec, ADR, or public doc stating whether Telegram topics are in scope for
agent-framework-hosting-telegram, so whether this is a bug or a scope change (and whether session-id changes should be opt-in) is a maintainer decision. Routed to the package owner.