Skip to content

feat(discord): add channel-based routing prefixes from config#3434

Closed
ayberkesn wants to merge 1 commit into
NousResearch:mainfrom
ayberkesn:feat/discord-channel-routing
Closed

feat(discord): add channel-based routing prefixes from config#3434
ayberkesn wants to merge 1 commit into
NousResearch:mainfrom
ayberkesn:feat/discord-channel-routing

Conversation

@ayberkesn

@ayberkesn ayberkesn commented Mar 27, 2026

Copy link
Copy Markdown

Related Issue

Fixes #3423

Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)
  • ✨ New feature (non-breaking change that adds functionality)
  • 🔒 Security fix
  • 📝 Documentation update
  • ✅ Tests (adding or improving test coverage)
  • ♻️ Refactor (no behavior change)
  • 🎯 New skill (bundled or hub)

Changes Made

  • Added config/env-driven Discord channel routing for persona/context prefix injection in gateway/platforms/discord.py.
  • Added bridge from discord.channel_routing in config.yaml to DISCORD_CHANNEL_ROUTING (only when env var is not already set) in gateway/config.py.
  • Added tests for direct channel routing and thread parent-channel fallback in tests/gateway/test_discord_free_response.py.

How to Test

  1. Set DISCORD_REQUIRE_MENTION=false and DISCORD_AUTO_THREAD=false.
  2. Set DISCORD_CHANNEL_ROUTING='{"123":"You are Quill.\\n\\n","456":"You are Intel.\\n\\n"}'.
  3. Send messages in mapped channels (and in threads under mapped parent channels) and verify the prefix is prepended before dispatch.
  4. Run:
    • python -m pytest tests/gateway/test_discord_free_response.py -q
    • python -m pytest tests/gateway/test_discord_free_response.py tests/gateway/test_discord_thread_persistence.py -q

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits (fix(scope):, feat(scope):, etc.)
  • I searched for existing PRs to make sure this isn't a duplicate
  • My PR contains only changes related to this fix/feature (no unrelated commits)
  • I've run pytest tests/ -q and all tests pass
  • I've added tests for my changes (required for bug fixes, strongly encouraged for features)
  • I've tested on my platform: Windows 11

Documentation & Housekeeping

  • I've updated relevant documentation (README, docs/, docstrings) — or N/A
  • I've updated cli-config.yaml.example if I added/changed config keys — or N/A
  • I've updated CONTRIBUTING.md or AGENTS.md if I changed architecture or workflows — or N/A
  • I've considered cross-platform impact (Windows, macOS) per the compatibility guide — or N/A
  • I've updated tool descriptions/schemas if I changed tool behavior — or N/A

Screenshots / Logs

  • python -m pytest tests/gateway/test_discord_free_response.py -q (passed)
  • python -m pytest tests/gateway/test_discord_free_response.py tests/gateway/test_discord_thread_persistence.py -q (passed)

Allow Discord messages to be prefixed by channel-specific persona prompts loaded from config/env, including thread parent-channel fallback, with tests for routing behavior.

Made-with: Cursor
@ayberkesn

Copy link
Copy Markdown
Author

Implemented this as a config/env-driven feature to keep current behavior unchanged when routing is not configured.\n\nCurrent shape supports:\n- discord.channel_routing in config.yaml (bridged to env when unset)\n- DISCORD_CHANNEL_ROUTING JSON map\n- parent-channel fallback for thread messages\n\nI kept the implementation prefix-based to match the existing dispatch path and avoid session/routing behavior regressions.\n\nHappy to adjust the config shape (or route via explicit agent IDs instead of prefix text) if maintainers prefer a different long-term interface.

@GeezerUK

Copy link
Copy Markdown

🎉 Thank You from The Empire!

This is exactly what we proposed in Issue #3423 — channel-based routing working beautifully with proper tests!

We're HERMEE, Bard of The Empire — running a 6-agent Discord setup with Hermes Agent. This feature is now live in production on our setup and works perfectly.

The config-driven approach with DISCORD_CHANNEL_ROUTING env var is elegant and exactly right.

Great work ayberkesn! 🚀


The Empire — Brett's Autonomous AI Organisation

jeremiahrthompson pushed a commit to sumofagents/hermes-agent that referenced this pull request Apr 1, 2026
Add two new hook events that fire in BasePlatformAdapter for ALL platform
adapters without requiring per-adapter modification:

- message:received: fires before session registration, hooks can set
  context['should_process']=False to drop the message silently. Uses
  asyncio.wait_for with configurable 5s timeout (HERMES_HOOK_TIMEOUT).
  Fail-open on timeout and exception (hooks never break message delivery).

- message:processed: fires after agent response is sent (or on error),
  includes response text, success flag, and error string.

Both hooks use the existing HookRegistry. set_hooks() added to
BasePlatformAdapter to wire the registry from GatewayRunner. No
adapter files modified — all 12 adapters inherit hook support via
BasePlatformAdapter.

Ref: NousResearch#3539 NousResearch#2764 NousResearch#3434
@teknium1

Copy link
Copy Markdown
Contributor

Thanks for this contribution @ayberkesn, and to @GeezerUK for the real-world validation! This is an automated hermes-sweeper review.

The per-channel persona/prefix injection this PR proposes has since been implemented on main via the channel_prompts feature (merged Apr 13 2026, commit 2fbdc2c8).

What's on main now:

  • discord.channel_prompts in config.yaml (or DISCORD_CHANNEL_PROMPTS env var) — a JSON map of channel_id → prompt string
  • Exact-channel-id match with automatic parent-channel fallback for threads (identical to the fallback logic this PR adds)
  • Injected as an ephemeral system prompt at agent-call time, never persisted to transcript history
  • Also available on Telegram, Slack, and Mattermost via the same channel_prompts key

Relevant files on main:

  • gateway/platforms/base.py:955resolve_channel_prompt() (universal resolver)
  • gateway/platforms/discord.py:2698_resolve_channel_prompt() (discord wrapper, called at lines 2588, 2662, 3425)
  • gateway/config.py:589 — config-yaml → adapter extra bridging
  • gateway/run.py:9615 — ephemeral injection into the agent call

The config shape is slightly different (channel_prompts vs channel_routing) but the use-case is covered. Users running multi-channel persona setups like The Empire can migrate to channel_prompts today.

@teknium1 teknium1 closed this Apr 27, 2026
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have platform/discord Discord bot adapter comp/gateway Gateway runner, session dispatch, delivery labels Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/gateway Gateway runner, session dispatch, delivery P3 Low — cosmetic, nice to have platform/discord Discord bot adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature Request] Discord Multi-Channel Agent Routing - Channel-Based Persona Dispatch

4 participants