Skip to content

feat(telegram): topic-to-profile routing for forum topics - #47236

Closed
nikreifer-bit wants to merge 1 commit into
NousResearch:mainfrom
nikreifer-bit:feat/topic-to-profile-routing-v2
Closed

feat(telegram): topic-to-profile routing for forum topics#47236
nikreifer-bit wants to merge 1 commit into
NousResearch:mainfrom
nikreifer-bit:feat/topic-to-profile-routing-v2

Conversation

@nikreifer-bit

Copy link
Copy Markdown

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 — Added routing_profile: Optional[str] field to SessionSource
  • telegram.py_topic_profiles dict from config.extra.topic_profiles; _resolve_topic_profile() matches (chat_id, thread_id) with empty-thread-id fallback; _apply_topic_profile_routing() called before handle_message for text, location, and photo/sticker/vision messages
  • run.py_load_profile_config() reads a named profile's config.yaml; overrides user config when routing_profile is set on the event source

Config format

telegram:
  topic_profiles:
    - match: {chat_id: "-1001234567890", thread_id: "2460"}
      profile: "fitness"

Behavior

  • Exact match: chat_id + thread_id → target profile
  • Fallback: chat_id + empty thread_id (messages without thread_id)
  • No match: keeps current behavior (default profile)
  • Target profile gets its own model, tools, skills, memory, and SOUL.md

Testing

Tested live on a production instance — fitness forum topic routes to fitness profile, yielding profile-scoped responses.

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
@alt-glitch alt-glitch added type/feature New feature or request comp/gateway Gateway runner, session dispatch, delivery platform/telegram Telegram bot adapter P3 Low — cosmetic, nice to have labels Jun 16, 2026

@tonydwb tonydwb left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 teknium1 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py moved to plugins/platforms/telegram/adapter.py in 476d8d9ccbee1b36d8fb6f4fabc0081c3e996cd2.
  • 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 proposed routing_profile field 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 stamping source.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.
"""

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@teknium1 teknium1 added sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform labels Jul 14, 2026
@teknium1

Copy link
Copy Markdown
Contributor

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 topic_profiles use case maps directly:

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: general

The 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 agent:<profile> session namespace.

Docs: https://hermes-agent.nousresearch.com/docs/user-guide/multi-profile-gateways

Thanks for the contribution — closing as superseded by the merged implementation.

@teknium1 teknium1 closed this Jul 15, 2026
@teknium1 teknium1 added the area/profiles Multi-profile isolation, HERMES_HOME scoping label Jul 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/profiles Multi-profile isolation, HERMES_HOME scoping comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/telegram Telegram bot adapter sweeper:blast-moderate Sweeper blast radius: moderate — a subsystem or single platform sweeper:risk-compatibility Sweeper risk: may break existing users, config, migrations, defaults, or upgrades sweeper:risk-message-delivery Sweeper risk: may drop, duplicate, misroute, or suppress messages sweeper:risk-security-boundary Sweeper risk: may affect sandboxing, auth, credentials, or sensitive data sweeper:risk-session-state Sweeper risk: may lose/corrupt/mis-associate session or context state type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants