diff --git a/plugins/platforms/slack/adapter.py b/plugins/platforms/slack/adapter.py index a34c995cc81f5..736598dba88f4 100644 --- a/plugins/platforms/slack/adapter.py +++ b/plugins/platforms/slack/adapter.py @@ -3936,10 +3936,13 @@ def _build_identity_prompt(self, team_id: str = "") -> str: return "" return ( f"You are connected to this Slack workspace as the bot " - f'"@{name}". In messages, each line is prefixed with the sender\'s ' - f"name, and mentions are shown as @DisplayName. Only treat a " - f'message as directed at you when it mentions "@{name}" ' - f"specifically; a mention of any other participant is not a " + f'"@{name}". The adapter already applied mention and channel ' + f"routing; treat every delivered turn as intentionally routed to " + f'you. Your routing mention "@{name}" may have been stripped from ' + f'the visible text — do not reject or ignore a message solely ' + f'because "@{name}" is absent. In messages, each line is prefixed ' + f"with the sender's name, and visible mentions are shown as " + f"@DisplayName; a mention of any other participant is not a " f"mention of you, even if their name is similar." ) diff --git a/tests/gateway/test_slack.py b/tests/gateway/test_slack.py index fca22ee1c5cb0..d9acaefaf6b02 100644 --- a/tests/gateway/test_slack.py +++ b/tests/gateway/test_slack.py @@ -1864,6 +1864,38 @@ async def test_channel_mention_strips_bot_id(self, adapter): assert msg_event.text == "what's the weather?" assert "<@U_BOT>" not in msg_event.text + @pytest.mark.asyncio + async def test_accepted_mention_prompt_trusts_adapter_routing(self, adapter): + """Cleaned text must not make the model revalidate an accepted mention.""" + adapter.config.extra.update({"require_mention": True, "strict_mention": True}) + adapter._bot_display_name = "TestBot" + adapter._team_bot_names = {"T123": "WorkspaceBot"} + event = { + "text": "<@U_BOT> Hi", + "user": "U_USER", + "channel": "C123", + "channel_type": "channel", + "team": "T123", + "ts": "1234567890.000001", + } + + await adapter._handle_slack_message(event) + + adapter.handle_message.assert_awaited_once() + msg_event = adapter.handle_message.await_args.args[0] + prompt = msg_event.channel_prompt + assert msg_event.text == "Hi" + assert "@WorkspaceBot" in prompt + assert "already applied" in prompt + assert "may have been stripped" in prompt + assert "do not reject or ignore" in prompt + assert "intentionally routed" in prompt + assert "not a mention of you" in prompt + assert "Only treat a message as directed" not in prompt + + @pytest.mark.asyncio + + @pytest.mark.asyncio async def test_allow_bots_mentions_ignores_bot_user_without_current_mention(