Skip to content

feat(slack): add strict_mention mode to prevent agent-to-agent loops#14117

Closed
hhhonzik wants to merge 1 commit into
NousResearch:mainfrom
hhhonzik:feat/slack-strict-mention
Closed

feat(slack): add strict_mention mode to prevent agent-to-agent loops#14117
hhhonzik wants to merge 1 commit into
NousResearch:mainfrom
hhhonzik:feat/slack-strict-mention

Conversation

@hhhonzik

Copy link
Copy Markdown
Contributor

Summary

Adds a new strict_mention Slack config flag. When enabled, the bot only replies to messages that explicitly @-tag it — all forms of thread auto-engagement are disabled.

Why

Currently, once a bot is @-mentioned in a thread, slack.py:1125-1131 registers the thread in _mentioned_threads and the bot replies to every subsequent message in that thread (regardless of mention).

When two Hermes agents share a thread (e.g. one agent delegating tasks to another via Slack), this causes infinite acknowledgement loops:

  1. Agent A @-tags Agent B with a task
  2. Agent B completes, replies in thread
  3. Agent A sees the reply (its own thread → auto-trigger via _bot_message_ts)
  4. Agent A acks ()
  5. Agent B sees the ack (its mentioned thread → auto-trigger via _mentioned_threads)
  6. Agent B acks ()
  7. Loop forever

require_mention=true doesn't help because it only gates the first mention — the auto-engagement paths bypass it entirely.

Behavior

Config Behavior
strict_mention=false (default) Unchanged — current behavior
strict_mention=true Only direct @-mentions in the current message trigger a reply. Thread continuity, bot-started threads, and active sessions are all ignored. Mentions also do not register the thread in _mentioned_threads.

Config

gateways:
  slack:
    extra:
      strict_mention: true

Or via env: SLACK_STRICT_MENTION=true.

Test Plan

  • With strict_mention=false (default): existing thread auto-engagement still works (regression check)
  • With strict_mention=true: bot replies only to messages containing <@bot_uid>
  • With strict_mention=true: thread is NOT added to _mentioned_threads even after a mention (verified by re-replying without mention → no response)
  • DMs unaffected (gating only applies in channels)
  • free_response_channels still take precedence over strict mode

Related

Discovered via Planepoints agent-to-agent loop where a tester agent (Ringo) and the primary Hermes agent ack-looped each other dozens of times in a single thread before manual intervention.

When `strict_mention=true` (or env SLACK_STRICT_MENTION=true), the bot
only replies to messages that explicitly @-tag it. All thread auto-
engagement paths are disabled: bot-started threads, previously-
mentioned threads, and active sessions are all ignored.

Default is False so existing bots are unaffected.

Motivation: when two Hermes agents share a thread, the previously-
mentioned thread auto-trigger (slack.py:1107-1109) causes infinite
acknowledgement loops — one bot acks, the other sees the ack as a
thread reply, replies, and so on. Strict mode breaks the loop by
requiring a fresh @mention for every response.
@alt-glitch alt-glitch added type/feature New feature or request P2 Medium — degraded but workaround exists comp/gateway Gateway runner, session dispatch, delivery platform/slack Slack app adapter labels Apr 22, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Competing fix with #12258 (same strict_mention feature). Also directly addresses #8019 (require_mention bypassed in active threads).

teknium1 pushed a commit that referenced this pull request Apr 26, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in #14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
teknium1 pushed a commit that referenced this pull request Apr 26, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in #14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
@teknium1

Copy link
Copy Markdown
Contributor

Merged via #16193 — the _mentioned_threads skip you caught is included as commit 34e3763 with your authorship preserved. @ching-kaching's #12258 landed as the base (it had the helper + config bridge + test suite); your diagnosis of the agent-to-agent ack loop hole and the _mentioned_threads registration fix were essential to making strict mode actually work. Credited to both of you.
#16193

@teknium1 teknium1 closed this Apr 26, 2026
ulasbilgen pushed a commit to ulasbilgen/hermes-adhd-agent that referenced this pull request May 1, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
donald131 pushed a commit to donald131/hermes-agent that referenced this pull request May 2, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
02356abc pushed a commit to 02356abc/hermes-agent that referenced this pull request May 14, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
dannyJ848 pushed a commit to dannyJ848/hermes-agent that referenced this pull request May 17, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
gweeteve pushed a commit to gweeteve/hermes-agent that referenced this pull request Jun 2, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
Egavasyug pushed a commit to Egavasyug/hermes-agent that referenced this pull request Jun 10, 2026
…is on

Extends the strict_mention feature so an @mention in strict mode no
longer persistently tags the thread as 'mentioned'. Without this, the
thread's first mention would permanently auto-trigger the bot on every
subsequent message — which is exactly what strict_mention is designed
to prevent. Closes the agent-to-agent ack loop hole hhhonzik identified
in NousResearch#14117.

Co-authored-by: hhhonzik <me@janstepanovsky.cz>
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 P2 Medium — degraded but workaround exists platform/slack Slack app adapter type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants