Skip to content

The agent that grows with you

docs(discord): clarify deployed bot handoff behavior and verify ingress

simpolism2c5504bf2618
diff --git a/plugins/platforms/discord/adapter.py b/plugins/platforms/discord/adapter.py
index 382740a2feb..7c529f99a93 100644
--- a/plugins/platforms/discord/adapter.py
+++ b/plugins/platforms/discord/adapter.py
@@ -4872,6 +4872,9 @@ class DiscordAdapter(DiscordMediaMixin, BasePlatformAdapter):
Config: ``discord.bots_require_inline_mention`` (or env
``DISCORD_BOTS_REQUIRE_INLINE_MENTION``).
"""
+ configured = self.config.extra.get("bots_require_inline_mention")
+ if isinstance(configured, str):
+ return configured.lower() in {"true", "1", "yes", "on"}
return self._extra_or_env_flag(
"bots_require_inline_mention", "DISCORD_BOTS_REQUIRE_INLINE_MENTION", "true", truthy=True
)
diff --git a/tests/gateway/test_discord_free_response.py b/tests/gateway/test_discord_free_response.py
index 9548facbe3b..0f715a381f2 100644
--- a/tests/gateway/test_discord_free_response.py
+++ b/tests/gateway/test_discord_free_response.py
@@ -232,10 +232,13 @@ async def test_discord_accepts_and_strips_bot_mentions_when_required(adapter, mo
async def test_unmentioned_bot_chunks_join_recent_tag_batch(adapter, monkeypatch):
monkeypatch.setenv("DISCORD_REQUIRE_MENTION", "true")
monkeypatch.setenv("DISCORD_AUTO_THREAD", "false")
- adapter._text_batch_delay_seconds = 0.01
- adapter._text_batch_split_delay_seconds = 0.02
+ monkeypatch.setenv("DISCORD_ALLOW_BOTS", "mentions")
+ adapter._ready_event.set()
+ adapter._text_batch_delay_seconds = 0.6
+ adapter._text_batch_split_delay_seconds = 2.0
channel = FakeTextChannel(channel_id=321)
bot_user = adapter._client.user
+ bot_user.bot = True
tagged = make_message(
channel=channel,
content=f"<@{bot_user.id}> first chunk",
@@ -248,12 +251,12 @@ async def test_unmentioned_bot_chunks_join_recent_tag_batch(adapter, monkeypatch
third = make_message(channel=channel, content="third chunk")
third.id = 125
third.author.bot = True
- adapter._record_bot_tag_debounce(tagged)
-
- assert await adapter._handle_message(tagged, role_authorized=True) is True
- assert await adapter._handle_message(second, role_authorized=True) is True
- assert await adapter._handle_message(third, role_authorized=True) is True
- await asyncio.sleep(0.03)
+ assert await adapter._dispatch_discord_message(tagged) is True
+ assert await adapter._dispatch_discord_message(second) is True
+ assert await adapter._dispatch_discord_message(third) is True
+ await asyncio.wait_for(
+ asyncio.gather(*adapter._pending_text_batch_tasks.values()), timeout=5.0,
+ )
adapter.handle_message.assert_awaited_once()
event = adapter.handle_message.await_args.args[0]
@@ -276,11 +279,12 @@ async def test_short_tagged_bot_chunk_waits_for_followup_window(adapter, monkeyp
tagged.author.bot = True
adapter._record_bot_tag_debounce(tagged)
- assert await adapter._handle_message(tagged, role_authorized=True) is True
- await asyncio.sleep(0.03)
- adapter.handle_message.assert_not_awaited()
-
- await asyncio.sleep(0.07)
+ # Assert the selected quiet period without a wall-clock race on busy CI.
+ with patch.object(discord_platform.asyncio, "sleep", new_callable=AsyncMock) as sleep:
+ assert await adapter._handle_message(tagged, role_authorized=True) is True
+ adapter.handle_message.assert_not_awaited()
+ await asyncio.gather(*adapter._pending_text_batch_tasks.values())
+ sleep.assert_awaited_once_with(adapter._text_batch_split_delay_seconds)
adapter.handle_message.assert_awaited_once()
diff --git a/website/docs/user-guide/messaging/discord.md b/website/docs/user-guide/messaging/discord.md
index 7f49a5275a8..e8011da1d79 100644
--- a/website/docs/user-guide/messaging/discord.md
+++ b/website/docs/user-guide/messaging/discord.md
@@ -307,7 +307,7 @@ Discord behavior is controlled through two files: **`~/.hermes/.env`** for crede
| `DISCORD_IGNORE_NO_MENTION` | No | `true` | When `true`, the bot stays silent if a message `@mentions` other users but does **not** mention the bot. Prevents the bot from jumping into conversations directed at other people. Only applies in server channels, not DMs. |
| `DISCORD_AUTO_THREAD` | No | `true` | When `true`, automatically creates a new thread for every `@mention` in a text channel, so each conversation is isolated (similar to Slack behavior). Messages already inside threads or DMs are unaffected. |
| `DISCORD_ALLOW_BOTS` | No | `"none"` | Controls how the bot handles messages from other Discord bots. `"none"` — ignore all other bots. `"mentions"` — only accept bot messages that `@mention` Hermes. `"all"` — accept all bot messages. By default, either enabled mode still requires a literal inline mention; see the next setting. |
-| `DISCORD_BOTS_REQUIRE_INLINE_MENTION` | No | `true` | Require bot-authored messages to contain a literal `<@BOT_ID>` / `<@!BOT_ID>` token. Discord reply pings only populate mention metadata and do not trigger Hermes. Set to `false` only for trusted relay integrations that depend on unmentioned bot messages or reply pings. Human-authored messages are unaffected. |
+| `DISCORD_BOTS_REQUIRE_INLINE_MENTION` | No | `true` | Require a literal `<@BOT_ID>` / `<@!BOT_ID>` token to start a bot handoff. Reply metadata alone does not start one. Brief same-sender/channel continuations are admitted as described below. Set to `false` only for trusted relays needing legacy admission. Human messages are unaffected. |
| `DISCORD_REACTIONS` | No | `true` | When `true`, the bot adds emoji reactions to messages during processing (👀 when starting, ✅ on success, ❌ on error). Set to `false` to disable reactions entirely. |
| `DISCORD_IGNORED_CHANNELS` | No | — | Comma-separated channel IDs where the bot **never** responds, even when `@mentioned`. Takes priority over all other channel settings. |
| `DISCORD_ALLOWED_CHANNELS` | No | — | Comma-separated channel IDs. When set, the bot **only** responds in these channels (plus DMs if allowed). Overrides `config.yaml` `discord.allowed_channels`. Combine with `DISCORD_IGNORED_CHANNELS` to express allow/deny rules. |
@@ -325,11 +325,31 @@ Discord behavior is controlled through two files: **`~/.hermes/.env`** for crede
| `HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS` | No | `0.6` | Grace window the adapter waits before flushing a queued text chunk. Useful for smoothing streamed output. |
| `HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS` | No | `2.0` | Longer quiet period for near-limit Discord splits and continuation chunks from a recently tagged bot in the same channel. |
-:::tip Bot-to-bot handoffs require hard mentions
-`DISCORD_ALLOW_BOTS` defaults to `"none"`. When you opt into `"mentions"` or `"all"`, bot-authored messages must contain a literal inline mention of Hermes by default. Discord's automatic replied-user ping does not count, so replying to another bot cannot silently invoke it again.
+### Bot-to-bot handoffs: tag once, collect the burst
-This permits deliberate handoffs and multi-turn collaboration between bots: each bot must explicitly type the next bot's mention on every turn it wants that bot to process, so a reply on its own never re-triggers the peer. When a bot's tagged handoff is longer than one Discord message, the unmentioned continuation chunks it sends within `HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS` of the tag (same sender, same channel or thread) are batched into the same turn instead of being dropped; this is a proximity window, so an unrelated message from that bot inside it joins the batch. The gateway's bot loop guard remains as a backstop: after 20 bot-authored messages in one channel inside 5 minutes, further bot messages there are dropped for 10 minutes (tunable under `gateway.bot_loop_guard` in `config.yaml`; human messages are never counted). Set `discord.bots_require_inline_mention: false` only for a trusted relay integration that intentionally depends on unmentioned bot messages or reply pings; doing so restores the reply-loop risk.
-:::
+Bot input remains opt-in (`DISCORD_ALLOW_BOTS=none` by default). When enabled with `mentions` or `all`, **starting a bot handoff requires a literal `<@BOT_ID>` / `<@!BOT_ID>` in the message content by default**. Discord's automatic reply ping alone does not start a handoff. Human-authored messages retain their existing mention behavior.
+
+After an admitted bot mention, Hermes briefly accepts unmentioned follow-ups from **that same bot in that same channel or thread**. Text follow-ups enter the existing text batcher, so a rapidly split response can reach the agent together without repeating the tag on every part. No special sender protocol or part markers are required.
+
+For example, bot A sends `<@BOT_B_ID> Here is the review …`, followed immediately by two untagged text chunks in the same thread. Bot B admits those chunks during the continuation window and batches them with the tagged text. After the window expires, an untagged message or reply ping cannot start another handoff under the default policy. Explicit reciprocal tags remain supported; this prevents accidental reply-metadata loops, not intentionally continued conversations.
+
+#### Timing and limits
+
+The admission window lasts `max(HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS, HERMES_DISCORD_TEXT_BATCH_SPLIT_DELAY_SECONDS)` after the admitted mention (2 seconds with the defaults). An unmentioned continuation **does not extend that admission deadline**. Separately, each queued text chunk restarts the batch's quiet timer; a tagged bot batch uses the split quiet period even when its first chunk is short. These settings control receiver batching, not sender pacing. Disabling text batching (`HERMES_DISCORD_TEXT_BATCH_DELAY_SECONDS=0`) also disables continuation admission.
+
+This is a short-burst heuristic, not guaranteed multipart delivery. A delayed chunk outside the window needs its own mention under the default policy. Unrelated messages from the same bot and channel inside the window can also be admitted. The exception is not restricted to text: attachments and commands may pass admission, but only text enters this batcher; other message types follow their normal handling. Existing channel restrictions and `DISCORD_ALLOW_BOTS=none` still apply. History/backfill behavior is unchanged. The gateway's bot loop guard remains as a backstop: after 20 bot-authored messages in one channel inside 5 minutes, further bot messages there are dropped for 10 minutes (tunable under `gateway.bot_loop_guard` in `config.yaml`; human messages are never counted).
+
+#### Compatibility with trusted relays
+
+The inline-mention requirement now defaults to **true** (previously false), including when `DISCORD_ALLOW_BOTS=all`. If an existing relay intentionally relies on reply pings or unmentioned bot messages, retain the old admission behavior explicitly:
+
+```yaml
+discord:
+ bots_require_inline_mention: false
+```
+
+The existing `DISCORD_BOTS_REQUIRE_INLINE_MENTION=false` environment override is also supported when the YAML option is unset. With this opt-out, `mentions` accepts Discord's resolved mentions, including reply pings, and `all` removes the bot-specific mention requirement; other channel mention rules still apply. An admitted reply ping can also open the continuation window in this compatibility mode. Use it only for trusted relays because it restores the accidental reply-loop risk.
+>>>>>>> 94d8ccfe3bd (docs(discord): clarify deployed bot handoff behavior and verify ingress)
### Config File (`config.yaml`)