Summary
Allow a single Telegram bot to route messages from different forum topics (threads) to different Hermes profiles, so each topic can be handled by a specialized agent with its own model, skills, memory, and system prompt.
Current Behavior
- Each profile runs its own gateway with its own bot token → 1 bot = 1 profile
- Within a profile,
build_session_key() creates separate sessions per thread_id, but all threads are still handled by the same agent (same model, same skills, same system prompt)
- To have different agent behavior per topic, users must run N separate bots (N Telegram bot tokens, N gateway processes), which is impractical for large setups
Proposed Behavior
Add config-based routing so that a single gateway can dispatch incoming messages to different profiles based on chat_id + thread_id:
# In the gateway profile's config.yaml
telegram:
topic_profiles:
- match:
chat_id: "-1001234567890"
thread_id: "1939"
profile: "coding-assistant"
- match:
chat_id: "-1001234567890"
thread_id: "42"
profile: "research-agent"
- match:
chat_id: "-1001234567890"
thread_id: "99"
profile: "polymarket-trader"
When a message arrives, the gateway:
- Checks
topic_profiles for a matching chat_id + thread_id
- If matched, spawns/forwards to the target profile's AIAgent (different model, skills, SOUL.md, memory)
- If no match, falls back to the current behavior (handle with own profile)
Why This Matters
- Single bot, multiple specialists: One Telegram bot serving a community group, where each forum topic has a purpose-built agent (coding, research, trading, CS)
- Resource efficient: No need for 10 separate bot tokens and 10 gateway processes
- Better UX: Users stay in one group, interact naturally via topics — no need to DM different bots
Implementation Notes
- The routing layer would sit in
gateway/platforms/telegram.py between message receipt and session dispatch
- The target profile's
AIAgent could be spawned in-process (load profile config + create agent instance) or forwarded via IPC
- Session keys would need to incorporate the target profile to avoid collision
- This is conceptually similar to
dm_topics (which routes DMs to forum topics), but at the profile/agent level
Alternatives Considered
- Multiple bots — current workaround, but requires N tokens and N processes
- Dynamic skill/model switching per topic — possible via
extra.topic_config in gateway, but doesn't isolate memory or system prompts
- External proxy/router — adds complexity and latency
Related
Summary
Allow a single Telegram bot to route messages from different forum topics (threads) to different Hermes profiles, so each topic can be handled by a specialized agent with its own model, skills, memory, and system prompt.
Current Behavior
build_session_key()creates separate sessions per thread_id, but all threads are still handled by the same agent (same model, same skills, same system prompt)Proposed Behavior
Add config-based routing so that a single gateway can dispatch incoming messages to different profiles based on
chat_id+thread_id:When a message arrives, the gateway:
topic_profilesfor a matchingchat_id+thread_idWhy This Matters
Implementation Notes
gateway/platforms/telegram.pybetween message receipt and session dispatchAIAgentcould be spawned in-process (load profile config + create agent instance) or forwarded via IPCdm_topics(which routes DMs to forum topics), but at the profile/agent levelAlternatives Considered
extra.topic_configin gateway, but doesn't isolate memory or system promptsRelated
gateway/session.py—build_session_key()already handles thread_id isolationgateway/platforms/telegram.py—_dm_topicsconfig pattern as precedent