Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend/copilot-bot): only answer other bots when @mentioned (#13174)

Bently8cc307208d1c
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
index 9dfaca7e9f..10482a8251 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter.py
@@ -222,9 +222,13 @@ class DiscordAdapter(PlatformAdapter):
await self._on_message_callback(ctx, self)
def _should_ignore_message(self, message: discord.Message) -> bool:
- return (
- self._client.user is not None and message.author.id == self._client.user.id
- )
+ if self._client.user is not None and message.author.id == self._client.user.id:
+ return True
+ # Other bots reach us only by @mentioning us; without this gate two
+ # bots in a shared thread (our own dev + prod included) loop forever.
+ if message.author.bot:
+ return not self._is_mentioned(message)
+ return False
def _is_mentioned(self, message: discord.Message) -> bool:
if message.guild is None:
diff --git a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py
index 9bf1ccb9f9..91f54f6acf 100644
--- a/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py
+++ b/autogpt_platform/backend/backend/copilot/bot/adapters/discord/adapter_test.py
@@ -143,10 +143,24 @@ class TestShouldIgnoreMessage:
assert adapter._should_ignore_message(msg) is True
- def test_allows_other_bot_message(self):
- adapter, _ = _bare_adapter(bot_id=1000)
+ def test_ignores_unmentioned_bot_message(self):
+ # A bot that doesn't @mention us is skipped — otherwise two bots
+ # sharing a thread (our own dev + prod included) loop forever.
+ adapter, client = _bare_adapter(bot_id=1000)
+ msg = _message("hi", [])
+ msg.author = MagicMock(id=2000, bot=True)
+ msg.guild = MagicMock()
+ client.user.mentioned_in.return_value = False
+
+ assert adapter._should_ignore_message(msg) is True
+
+ def test_allows_mentioned_bot_message(self):
+ # Another bot can still reach us by explicitly @mentioning us.
+ adapter, client = _bare_adapter(bot_id=1000)
msg = _message("hi", [])
msg.author = MagicMock(id=2000, bot=True)
+ msg.guild = MagicMock()
+ client.user.mentioned_in.return_value = True
assert adapter._should_ignore_message(msg) is False