From 7efd91d4b465c26b151b3f5991727ec23e56b875 Mon Sep 17 00:00:00 2001 From: alt-glitch Date: Sat, 25 Apr 2026 00:11:26 +0530 Subject: [PATCH] feat(session): inject Discord IDs block when discord tool is loaded MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When DISCORD_BOT_TOKEN is set — meaning the discord tool actually loads — emit a dedicated IDs block in the session context prompt so the agent can call ``fetch_messages``, ``pin_message``, etc. with real identifiers instead of probing. Currently only ``thread_id`` was exposed as a raw ID (via the ``description`` string). The agent in a Discord thread had to guess that the thread ID doubles as a channel ID for the REST API (it does), and it had no way to reference the parent channel, the guild, or the triggering message at all. The block adapts to context: - Thread: guild / parent channel / thread / message - Channel: guild / channel / message - (DM has no guild/channel IDs worth listing; only message) Discord isn't in _PII_SAFE_PLATFORMS, so IDs ship unredacted. --- gateway/session.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/gateway/session.py b/gateway/session.py index 495c95d56..b5d02edde 100644 --- a/gateway/session.py +++ b/gateway/session.py @@ -285,13 +285,26 @@ def build_session_context_prompt( "that you can only read messages sent directly to you and respond." ) elif context.source.platform == Platform.DISCORD: - # Only emit the "no Discord APIs" disclaimer when the discord tool - # can't load. The tool self-gates on DISCORD_BOT_TOKEN at registry - # check time, so matching that condition keeps the prompt honest: + # The discord tool self-gates on DISCORD_BOT_TOKEN at registry + # check time. Match that condition so the prompt stays honest: # with a token the agent has fetch_messages/search_members/ - # create_thread (and optionally discord_admin); without one it - # really is limited to reading/replying via the gateway. - if not (os.environ.get("DISCORD_BOT_TOKEN") or "").strip(): + # create_thread (and optionally discord_admin) and should know + # the IDs it can call them with; without one it really is + # limited to reading/replying via the gateway. + if (os.environ.get("DISCORD_BOT_TOKEN") or "").strip(): + src = context.source + id_lines = ["", "**Discord IDs (for the `discord` / `discord_admin` tools):**"] + if src.guild_id: + id_lines.append(f" - Guild: `{src.guild_id}`") + if src.thread_id and src.parent_chat_id: + id_lines.append(f" - Parent channel: `{src.parent_chat_id}`") + id_lines.append(f" - Thread: `{src.thread_id}` (use as `channel_id` for fetch_messages etc.)") + else: + id_lines.append(f" - Channel: `{src.chat_id}`") + if src.message_id: + id_lines.append(f" - Triggering message: `{src.message_id}`") + lines.extend(id_lines) + else: lines.append("") lines.append( "**Platform notes:** You are running inside Discord. "