From 03f23f10e1efb7467f4a7d29370ba3dc47a25da7 Mon Sep 17 00:00:00 2001 From: Shannon Sands Date: Sat, 11 Apr 2026 07:45:32 +1000 Subject: [PATCH] =?UTF-8?q?feat:=20multi-agent=20Discord=20filtering=20?= =?UTF-8?q?=E2=80=94=20skip=20messages=20addressed=20to=20other=20bots?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace the simple DISCORD_IGNORE_NO_MENTION check with bot-aware multi-agent filtering. When multiple agents share a channel: - If other bots are @mentioned but this bot is not → stay silent - If only humans are mentioned but not this bot → stay silent - Messages with no mentions still flow to _handle_message for the existing DISCORD_REQUIRE_MENTION check - DMs are unaffected (always handled) This prevents both agents from responding when only one is addressed. --- gateway/platforms/discord.py | 39 ++++++++++++++++++++++++------------ 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/gateway/platforms/discord.py b/gateway/platforms/discord.py index 1de4464286e..dcf05a16257 100644 --- a/gateway/platforms/discord.py +++ b/gateway/platforms/discord.py @@ -606,22 +606,35 @@ class DiscordAdapter(BasePlatformAdapter): if not self._client.user or self._client.user not in message.mentions: return # "all" falls through to handle_message - - # If the message @mentions other users but NOT the bot, the - # sender is talking to someone else — stay silent. Only - # applies in server channels; in DMs the user is always - # talking to the bot (mentions are just references). - # Controlled by DISCORD_IGNORE_NO_MENTION (default: true). - _ignore_no_mention = os.getenv( - "DISCORD_IGNORE_NO_MENTION", "true" - ).lower() in ("true", "1", "yes") - if _ignore_no_mention and message.mentions and not isinstance(message.channel, discord.DMChannel): - _bot_mentioned = ( + + # Multi-agent filtering: if the message mentions specific bots + # but NOT this bot, the sender is talking to another agent — + # stay silent. Messages with no bot mentions (general chat) + # still fall through to _handle_message for the existing + # DISCORD_REQUIRE_MENTION check. + # + # This replaces the older DISCORD_IGNORE_NO_MENTION logic + # with bot-aware filtering that works correctly when multiple + # agents share a channel. + if not isinstance(message.channel, discord.DMChannel) and message.mentions: + _self_mentioned = ( self._client.user is not None and self._client.user in message.mentions ) - if not _bot_mentioned: - return # Talking to someone else, don't interrupt + _other_bots_mentioned = any( + m.bot and m != self._client.user + for m in message.mentions + ) + # If other bots are mentioned but we're not → not for us + if _other_bots_mentioned and not _self_mentioned: + return + # If humans are mentioned but we're not → not for us + # (preserves old DISCORD_IGNORE_NO_MENTION=true behavior) + _ignore_no_mention = os.getenv( + "DISCORD_IGNORE_NO_MENTION", "true" + ).lower() in ("true", "1", "yes") + if _ignore_no_mention and not _self_mentioned and not _other_bots_mentioned: + return await self._handle_message(message)