fix(agent): scope the Bot Mode protocol section to canonical Bot Chat sessions

Per review: the protocol belongs only in official Bot Mode interactions,
not every session on a managed install. The prompt builder now injects
the section only when the agent's session row is titled "Bot Chat"
(BOT_CHAT_TITLE, matching the desktop's createCanonicalChat pin and the
`hermes -p <bot> chat -c "Bot Chat"` resume target). Regular sessions
never carry it; the desktop composer middleware owns @mention sends.

Title is read once at first prompt build and the rendered prompt is
cached + DB-restored — cache-safe. E2E against the real AIAgent +
SessionDB: absent in an untitled session, present in Bot Chat,
byte-stable across rebuilds, absent after retitle, absent with the
flag off. Overhead unchanged (~916B, Bot Chat sessions only).
This commit is contained in:
Teknium
2026-08-16 11:35:52 -07:00
parent d516496cef
commit 78a4693eef
3 changed files with 36 additions and 20 deletions
+16 -12
View File
@@ -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 <bot> 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 <bot> 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
+15 -5
View File
@@ -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 <name> 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] = {}
+5 -3
View File
@@ -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 <bot> 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.