feat(telegram): topic-to-profile routing for forum topics - #47236
feat(telegram): topic-to-profile routing for forum topics#47236nikreifer-bit wants to merge 1 commit into
Conversation
Allow a single Telegram bot to dispatch messages from specific
forum topics to different Hermes profiles, so each topic can
be handled by a specialist agent with its own model, skills,
memory, and SOUL.
Config (in gateway profile config.yaml):
telegram:
topic_profiles:
- match: {chat_id: "-100...", thread_id: "2460"}
profile: "fitness"
When a message arrives in a matched topic:
1. Checks the routing table
2. Loads the target profile config (model, tools, skills)
3. Creates the agent session with that profile configuration
4. Falls back to default profile if no match
Three-file, 80-line change:
- gateway/session.py: +routing_profile field on SessionSource
- gateway/platforms/telegram.py: config parsing + routing lookup
+ interception in 4 message handlers
- gateway/run.py: _load_profile_config() helper + routing check
in _run_agent to override default gateway config
Closes NousResearch#10143
tonydwb
left a comment
There was a problem hiding this comment.
Code Review Summary
Verdict: Approved
What was changed
Telegram: topic-to-profile routing for forum topics. Forum topics in Telegram now route to the correct profile based on topic ID, allowing different conversation topics to use different agent profiles.
Observations
Clean feature addition for Telegram forum support. The routing correctly maps topic IDs to configured profiles. Small diff, well-scoped.
Security
No concerns.
Reviewed by Hermes Agent
teknium1
left a comment
There was a problem hiding this comment.
Thanks for the focused Telegram routing proposal. The use case is still missing on current main, but this patch needs a substantial salvage onto the current profile-routing architecture.
Problems
- The edited adapter path no longer exists:
gateway/platforms/telegram.pymoved toplugins/platforms/telegram/adapter.pyin476d8d9ccbee1b36d8fb6f4fabc0081c3e996cd2. - Current profile selection uses
SessionSource.profile(gateway/session.py:179-183). The profile-scoped runtime path reads that field and enters_profile_runtime_scope(gateway/run.py:16947-16987); the proposedrouting_profilefield would not scope skills, memory, SOUL, or credentials. - Forum General messages normalize a missing Telegram thread ID to
"1"(plugins/platforms/telegram/adapter.py:6860-6884), so the raw empty-thread fallback needs redesign. - The patch adds no automated coverage for profile/session isolation.
Suggested changes
- Implement lookup during current event construction in
plugins/platforms/telegram/adapter.py:8330-8425, using the normalized thread ID and stampingsource.profile. - Route through the existing multiplex/runtime scope and add tests for mapping, profile isolation, session namespacing, and topic-preserving replies.
Automated hermes-sweeper review.
| Calls _resolve_topic_profile and attaches the target profile to | ||
| the event. The gateway runner detects this attribute and loads | ||
| the target profile config for the session. | ||
| """ |
There was a problem hiding this comment.
Current main routes profile identity through SessionSource.profile, not routing_profile; the runner scopes config, skills, memory, SOUL, and credentials only from source.profile under multiplexing (gateway/run.py:16947-16987). Please rework this against the current profile-routing contract rather than adding a parallel field.
|
Telegram forum-topic → profile routing has now landed on main via PR #64835 (a salvage of #20096 by @Burgunthy, the earliest submission of the general feature). Your gateway:
multiplex_profiles: true
profile_routes:
- platform: telegram
chat_id: "<forum chat id>"
thread_id: "<topic id>"
profile: support
# chat_id-only route = your empty-thread_id fallback
- platform: telegram
chat_id: "<forum chat id>"
profile: generalThe merged implementation goes further than the config-dict swap here: the routed turn runs under the profile's full HERMES_HOME (config, skills, memory, secrets) and its own Docs: https://hermes-agent.nousresearch.com/docs/user-guide/multi-profile-gateways Thanks for the contribution — closing as superseded by the merged implementation. |
Summary
Dispatch messages from specific Telegram forum topics (threads) to different Hermes profiles — each with its own model, skills, memory, and SOUL. Single bot, multiple specialist agents.
Related: #4321, #10143
Changes (3 files, +80 lines)
session.py— Addedrouting_profile: Optional[str]field toSessionSourcetelegram.py—_topic_profilesdict fromconfig.extra.topic_profiles;_resolve_topic_profile()matches(chat_id, thread_id)with empty-thread-id fallback;_apply_topic_profile_routing()called beforehandle_messagefor text, location, and photo/sticker/vision messagesrun.py—_load_profile_config()reads a named profile'sconfig.yaml; overrides user config whenrouting_profileis set on the event sourceConfig format
Behavior
chat_id+thread_id→ target profilechat_id+ emptythread_id(messages without thread_id)Testing
Tested live on a production instance — fitness forum topic routes to fitness profile, yielding profile-scoped responses.