From c8bfb1db8f52c42d37a4448471cf452633598f96 Mon Sep 17 00:00:00 2001 From: Teknium <127238744+teknium1@users.noreply.github.com> Date: Fri, 13 Mar 2026 12:34:11 -0700 Subject: [PATCH] fix(gateway): add platform-specific notes to session context prompt (#1184) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tell the agent what it CANNOT do on Slack and Discord — no searching channel history, no pinning messages, no managing channels/roles. Prevents the agent from hallucinating capabilities it doesn't have and promising actions it can't deliver. Addresses user feedback: agent says 'I'll search your Slack history' then goes silent because no Slack-specific tools exist. --- gateway/session.py | 20 ++++++++++++++++++++ tests/gateway/test_session.py | 23 ++++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/gateway/session.py b/gateway/session.py index f6ede44f4..3e42db4fe 100644 --- a/gateway/session.py +++ b/gateway/session.py @@ -177,6 +177,26 @@ def build_session_context_prompt(context: SessionContext) -> str: elif context.source.user_id: lines.append(f"**User ID:** {context.source.user_id}") + # Platform-specific behavioral notes + if context.source.platform == Platform.SLACK: + lines.append("") + lines.append( + "**Platform notes:** You are running inside Slack. " + "You do NOT have access to Slack-specific APIs — you cannot search " + "channel history, pin/unpin messages, manage channels, or list users. " + "Do not promise to perform these actions. If the user asks, explain " + "that you can only read messages sent directly to you and respond." + ) + elif context.source.platform == Platform.DISCORD: + lines.append("") + lines.append( + "**Platform notes:** You are running inside Discord. " + "You do NOT have access to Discord-specific APIs — you cannot search " + "channel history, pin messages, manage roles, or list server members. " + "Do not promise to perform these actions. If the user asks, explain " + "that you can only read messages sent directly to you and respond." + ) + # Connected platforms platforms_list = ["local (files on this machine)"] for p in context.connected_platforms: diff --git a/tests/gateway/test_session.py b/tests/gateway/test_session.py index e25a0a9c7..b5808a99d 100644 --- a/tests/gateway/test_session.py +++ b/tests/gateway/test_session.py @@ -182,7 +182,7 @@ class TestBuildSessionContextPrompt: platforms={ Platform.DISCORD: PlatformConfig( enabled=True, - token="fake-discord-token", + token="fake-d...oken", ), }, ) @@ -197,6 +197,27 @@ class TestBuildSessionContextPrompt: prompt = build_session_context_prompt(ctx) assert "Discord" in prompt + assert "cannot search" in prompt.lower() or "do not have access" in prompt.lower() + + def test_slack_prompt_includes_platform_notes(self): + config = GatewayConfig( + platforms={ + Platform.SLACK: PlatformConfig(enabled=True, token="fake"), + }, + ) + source = SessionSource( + platform=Platform.SLACK, + chat_id="C123", + chat_name="general", + chat_type="group", + user_name="bob", + ) + ctx = build_session_context(source, config) + prompt = build_session_context_prompt(ctx) + + assert "Slack" in prompt + assert "cannot search" in prompt.lower() + assert "pin" in prompt.lower() def test_discord_prompt_with_channel_topic(self): """Channel topic should appear in the session context prompt."""