hermes - ✅(Solved) Fix [Feature]: Opt-in DISCORD_THREAD_REQUIRE_MENTION for multi-bot threads [1 pull requests, 1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
NousResearch/hermes-agent#25312Fetched 2026-05-14 03:47:23
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Author
Timeline (top)
labeled ×4commented ×1cross-referenced ×1

Root Cause

But it's an active footgun in multi-bot threads. I run a research Discord with multiple AI agents (Hermes, Codex via Codex CLI, Claude via Claude Code, etc.) in shared threads where I address one bot per turn. The current default means: address Codex → Codex fires (good) → Hermes also fires (bad, because the message wasn't for it) → cross-replies, burned credits, and channel spam.

Fix Action

Fixed

PR fix notes

PR #25313: feat(discord): add thread_require_mention for multi-bot threads

Description (problem / solution / changelog)

What does this PR do?

Adds opt-in discord.thread_require_mention config (env: DISCORD_THREAD_REQUIRE_MENTION), default false so existing behavior is unchanged. When set to true, threads are gated the same way channels are — the bot no longer auto-responds to non-mentioned messages in a thread just because it has previously participated. Explicit @mention is the only trigger when enabled.

This fixes an active footgun in multi-bot threads. By default, once Hermes joins a thread, it auto-responds to every message in that thread without needing further @mention — fine for one-on-one conversations, but in shared multi-bot threads (e.g. a research Discord with several agents), every other bot also fires on every message you send to any one bot, burning credits and spamming the channel. Author has hit this personally; not hypothetical.

The change is deliberately conservative — add the knob, keep the default — so existing 1:1 Discord deployments behave exactly as they do today.

Related Issue

Fixes #25312

Type of Change

  • ✨ New feature (non-breaking change that adds functionality)

Changes Made

  • gateway/platforms/discord.py: new _discord_thread_require_mention() helper (config.extra → env → default false), mirroring the existing _discord_require_mention() shape. The in_bot_thread shortcut in _handle_message now ANDs with not _discord_thread_require_mention() so the shortcut is suppressed when the new knob is enabled.
  • gateway/config.py: yaml→env bridge for discord.thread_require_mention, mirroring the existing require_mention bridge two lines above. Without this, config.yaml settings wouldn't reach the helper at runtime — same pattern, same precedence (env wins over yaml).
  • hermes_cli/config.py: add thread_require_mention: False to DEFAULT_CONFIG['discord'].
  • tests/gateway/test_discord_free_response.py:
    • 4 new tests covering: default behavior (in-thread shortcut still works), enabled behavior (mention required in threads), enabled+mentioned (mention still passes through), and yaml-via-config.extra path.
    • Fixture cleanup for the adapter fixture — clears DISCORD_* env vars at fixture entry. Found in development: existing tests in this file are environment-fragile (a contributor with DISCORD_THREAD_REQUIRE_MENTION=true set in their shell sees test_discord_bot_thread_skips_mention_requirement fail). Adding the existing test's needed env vars to the fixture's cleanup list makes the whole file robust to shell environment state.
  • tests/gateway/test_config.py: 2 new tests for the yaml→env bridge — one covering apply-from-yaml, one covering env-precedence-over-yaml (matching how the existing require_mention bridge works).
  • website/docs/user-guide/messaging/discord.md:
    • New DISCORD_THREAD_REQUIRE_MENTION row in the env-var table
    • New thread_require_mention entry in the YAML example
    • New #### discord.thread_require_mention prose section with the multi-bot rationale and a code example
    • Cross-link from the auto_thread section pointing at the new knob

How to Test

Unit tests (6 new, all impacted files green):

pytest tests/gateway/test_discord_free_response.py tests/gateway/test_config.py -q

(70 passed locally.)

Manual — multi-bot thread reproduction:

  1. Configure two Hermes-style bots in the same Discord server, both with discord.require_mention: true.
  2. Open a thread, @mention Bot A. Bot A responds in the thread.
  3. @mention Bot B in the same thread. Both bots respond — A because it's "already in the thread," B because it was mentioned. ← the footgun.
  4. Set discord.thread_require_mention: true on both bots (or via DISCORD_THREAD_REQUIRE_MENTION=true). Restart gateway.
  5. @mention Bot B again. Only Bot B responds.

Or for a quick env-only check on one bot:

export DISCORD_THREAD_REQUIRE_MENTION=true
# restart gateway
# in an existing bot-thread, send "hello" without @mention
# expected: bot stays silent (was: bot replies)

Checklist

Code

  • I've read the Contributing Guide
  • My commit messages follow Conventional Commits
  • I searched for existing PRs — no duplicate
  • My PR contains only changes related to this feature (including the fixture-cleanup that the new test would otherwise depend on being clean)
  • I've run impacted test files; all pass
  • I've added tests — 6 new tests covering helper, gating logic, yaml→env bridge, env precedence
  • I've tested on my platform: Ubuntu 24.04

Documentation & Housekeeping

  • I've updated relevant documentation — website/docs/user-guide/messaging/discord.md updated in three places (env-var table, YAML example, new prose section + cross-link)
  • cli-config.yaml.example — the example file doesn't currently have a runtime discord: settings block (settings live in env vars), so following the existing pattern: documented in website docs, not example yaml. Happy to add an example block if preferred.
  • CONTRIBUTING.md / AGENTS.md — N/A, no architecture/workflow change
  • Cross-platform impact — N/A, purely server-side adapter logic
  • Tool descriptions/schemas — N/A

Changed files

  • gateway/config.py (modified, +2/-0)
  • gateway/platforms/discord.py (modified, +28/-2)
  • hermes_cli/config.py (modified, +1/-0)
  • tests/gateway/test_config.py (modified, +37/-0)
  • tests/gateway/test_discord_free_response.py (modified, +84/-0)
  • website/docs/user-guide/messaging/discord.md (modified, +17/-1)

Code Example

in_bot_thread = is_thread and thread_id in self._threads

if require_mention and not is_free_channel and not in_bot_thread:
    if self._client.user not in message.mentions and not mention_prefix:
        return  # ← thread shortcut bypasses mention check

---

# config.yaml
discord:
  require_mention: true
  thread_require_mention: true   # multi-bot setup
RAW_BUFFERClick to expand / collapse

Problem or Use Case

By default, once Hermes has participated in a Discord thread (auto-created on @mention or replied in once), it auto-responds to every subsequent message in that thread without needing further @mentions. This is the right default for one-on-one conversations and most channel threads — keeps the conversation flowing without @ clutter.

But it's an active footgun in multi-bot threads. I run a research Discord with multiple AI agents (Hermes, Codex via Codex CLI, Claude via Claude Code, etc.) in shared threads where I address one bot per turn. The current default means: address Codex → Codex fires (good) → Hermes also fires (bad, because the message wasn't for it) → cross-replies, burned credits, and channel spam.

I've hit this personally in active sessions. It's not hypothetical — every multi-bot thread in require_mention=true mode reproduces it.

The current behavior in production code (gateway/platforms/discord.py's _handle_message):

in_bot_thread = is_thread and thread_id in self._threads

if require_mention and not is_free_channel and not in_bot_thread:
    if self._client.user not in message.mentions and not mention_prefix:
        return  # ← thread shortcut bypasses mention check

in_bot_thread = true whenever Hermes has ever participated in the thread, which short-circuits the require_mention gate. There's no way to ask Hermes to stop doing that without disabling require_mention entirely (which would also stop it from responding in shared channels) or never having Hermes participate in shared threads (which defeats the point of using it in a team Discord).

Proposed Solution

Add a discord.thread_require_mention config key (env: DISCORD_THREAD_REQUIRE_MENTION), default false to preserve existing behavior. When true, the in-thread mention shortcut is disabled — threads gate the same way channels do (require explicit @mention).

# config.yaml
discord:
  require_mention: true
  thread_require_mention: true   # multi-bot setup

Explicit @mentions continue to work as expected — this just turns off the implicit "you're in this thread so everything is for you" assumption.

Alternatives Considered

1. Flip the default to thread_require_mention=true. I considered this — Anthropic's Claude Code Discord MCP plugin does require explicit @mention in every channel/thread (no in-thread shortcut at all), which is the more conservative default for shared spaces. But that would change behavior for every existing Hermes Discord deployment, most of which use Hermes 1:1 where the current default is correct and pleasant. The opt-in knob preserves all existing setups.

2. Detect "multi-bot thread" automatically (e.g. if multiple bots have posted recently, require mentions). This adds heuristic complexity for a use case that's well-served by an explicit user choice. Author preference is "expose the knob, don't infer intent" (matching how require_mention, free_response_channels, no_thread_channels already work in this adapter).

3. Disable require_mention entirely and rely on user discipline. Doesn't scale — users will address bots informally ("hey codex") and not always with structured mentions.

Feature Type

Gateway / messaging improvement

Scope

Small (single file, < 50 lines of production code; +30 lines gateway/platforms/discord.py, +1 line hermes_cli/config.py, +2 lines gateway/config.py)

Contribution

  • I'd like to implement this myself and submit a PR

(PR ready: [#XXX])

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING