diff --git a/agent/system_prompt.py b/agent/system_prompt.py index 2a32e03f15..1e8d1ba7db 100644 --- a/agent/system_prompt.py +++ b/agent/system_prompt.py @@ -584,20 +584,24 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None) # Probe failure must never block prompt build. pass - # Bot Mode teammate protocol — when the desktop's Bot Mode manages this - # install (any profile carries ui_meta['hermes-bots']), every session of - # every profile learns the bot-to-bot messaging protocol, including - # headless `hermes -p chat` sessions started by a teammate. Silent - # on non-Bot-Mode installs and when the profile's SOUL.md already carries - # the section (legacy plugin-side append). Deterministic per (process, - # home) — cache-safe. Gated by config.yaml ``agent.bot_mode_protocol`` - # (default True). + # Bot Mode teammate protocol — injected ONLY into a bot's canonical + # "Bot Chat" session (the conversation teammate bots message into via + # `hermes -p chat --in ~ -c "Bot Chat"` and the desktop pins), on + # installs where Bot Mode manages profiles (ui_meta['hermes-bots']). + # Regular sessions never carry it — the desktop's composer middleware + # owns the @mention send path. Title is read once at first build and the + # rendered prompt is cached + DB-restored, so this is cache-safe. + # Gated by config.yaml ``agent.bot_mode_protocol`` (default True). if getattr(agent, "_bot_mode_protocol", True): try: - from tools.bot_mode_probe import get_bot_mode_protocol_section - _bot_section = get_bot_mode_protocol_section(_agent_home(agent)) - if _bot_section: - post_workspace_parts.append(_bot_section) + from tools.bot_mode_probe import BOT_CHAT_TITLE, get_bot_mode_protocol_section + _sdb = getattr(agent, "_session_db", None) + _sid = getattr(agent, "session_id", None) + _title = _sdb.get_session_title(_sid) if (_sdb and _sid) else None + if (_title or "").strip() == BOT_CHAT_TITLE: + _bot_section = get_bot_mode_protocol_section(_agent_home(agent)) + if _bot_section: + post_workspace_parts.append(_bot_section) except Exception: pass diff --git a/tools/bot_mode_probe.py b/tools/bot_mode_probe.py index 7fe9078c0a..97bc57c684 100644 --- a/tools/bot_mode_probe.py +++ b/tools/bot_mode_probe.py @@ -1,10 +1,15 @@ -"""Bot Mode roster probe — stable-tier system prompt section. +"""Bot Mode roster probe — canonical Bot Chat system prompt section. When the desktop's Bot Mode manages this install (any profile carries a -``ui_meta['hermes-bots']`` block in its profile.yaml), every session of every -profile gets a short "Messaging other agents" section so bots can hand off -@mentions and reply to bot-to-bot DMs — including headless CLI sessions -started by another bot via ``hermes -p chat``. +``ui_meta['hermes-bots']`` block in its profile.yaml), a bot's canonical +"Bot Chat" session — and ONLY that session — gets a short "Messaging other +agents" section so the bot can receive teammate DMs, reply with attribution, +and hand off @mentions. Regular sessions never carry the section; the +desktop's composer middleware owns the @mention send path there. + +The caller (agent/system_prompt.py) enforces the session-title gate against +``BOT_CHAT_TITLE``; this module answers "is this install Bot-Mode-managed, +and what should the section say for this profile". This replaces the plugin-side SOUL.md backfill: the protocol is injected by the core at prompt-build time instead of appended to user-authored SOUL @@ -30,6 +35,11 @@ from pathlib import Path _PROTOCOL_HEADING = "## Messaging other agents" +# The canonical per-bot conversation title — the only session shape that +# receives the protocol section. Must match the desktop plugin's +# createCanonicalChat title and the `-c "Bot Chat"` resume target. +BOT_CHAT_TITLE = "Bot Chat" + _lock = threading.Lock() _cached: dict[str, str] = {} diff --git a/website/docs/user-guide/desktop.md b/website/docs/user-guide/desktop.md index b76170ece9..d18ab7cb11 100644 --- a/website/docs/user-guide/desktop.md +++ b/website/docs/user-guide/desktop.md @@ -176,9 +176,11 @@ them into sections, and open group chats where several bots deliberate. Bots message each other: type `@researcher have a look at this` in any chat and the active bot hands the message off and reports back, and bots reach each other's Bot Chats directly (`hermes -p chat`). The backend teaches -every session the messaging protocol automatically (config -`agent.bot_mode_protocol`, default on) — including headless CLI sessions a -teammate bot starts — so handoffs work without touching your SOUL.md. +each bot's canonical **Bot Chat** session the messaging protocol +automatically (config `agent.bot_mode_protocol`, default on) — including +when a teammate bot opens it headlessly from the CLI — so bot-to-bot +replies and handoffs work without touching your SOUL.md, and your regular +sessions stay untouched. Don't want it? Flip it off in **Settings → Plugins → Bots** — the roster, routines pane, and composer middleware unregister live, no restart needed.