Skip to content

[Feature] Topic-to-Profile routing: dispatch messages to different profiles based on Telegram topic/thread #10143

@willy-scr

Description

@willy-scr

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:

  1. Checks topic_profiles for a matching chat_id + thread_id
  2. If matched, spawns/forwards to the target profile's AIAgent (different model, skills, SOUL.md, memory)
  3. 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

  1. Multiple bots — current workaround, but requires N tokens and N processes
  2. Dynamic skill/model switching per topic — possible via extra.topic_config in gateway, but doesn't isolate memory or system prompts
  3. External proxy/router — adds complexity and latency

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3Low — cosmetic, nice to havecomp/gatewayGateway runner, session dispatch, deliveryplatform/telegramTelegram bot adaptertype/featureNew feature or request

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions