Skip to content

The agent that grows with you

fix(agent): Bot Chat gate reads a session-title hint before the DB

Teknium72bae0e91a84
diff --git a/agent/agent_init.py b/agent/agent_init.py
index b6b1ca486ac..ebfda99fe93 100644
--- a/agent/agent_init.py
+++ b/agent/agent_init.py
@@ -1909,6 +1909,10 @@ def init_agent(
# Bot Mode teammate protocol section (tools/bot_mode_probe.py) — pure
# filesystem reads, no warm needed. Silent on non-Bot-Mode installs.
agent._bot_mode_protocol = bool(_agent_section.get("bot_mode_protocol", True))
+ # Session-title hint for the "Bot Chat" gate: hosts that defer the DB
+ # title write past the first prompt build (tui_gateway pending_title)
+ # set this so the gate doesn't depend on write ordering.
+ agent._session_title_hint = None
# Per-platform prompt-hint overrides (config.yaml → platform_hints).
# Lets an enterprise admin append to or replace Hermes' built-in
diff --git a/agent/system_prompt.py b/agent/system_prompt.py
index 1e8d1ba7db7..a7d707ffd8a 100644
--- a/agent/system_prompt.py
+++ b/agent/system_prompt.py
@@ -595,10 +595,12 @@ def build_system_prompt_parts(agent: Any, system_message: Optional[str] = None)
if getattr(agent, "_bot_mode_protocol", True):
try:
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:
+ _title = str(getattr(agent, "_session_title_hint", "") or "").strip()
+ if not _title:
+ _sdb = getattr(agent, "_session_db", None)
+ _sid = getattr(agent, "session_id", None)
+ _title = str((_sdb.get_session_title(_sid) if (_sdb and _sid) else None) or "").strip()
+ if _title == BOT_CHAT_TITLE:
_bot_section = get_bot_mode_protocol_section(_agent_home(agent))
if _bot_section:
post_workspace_parts.append(_bot_section)
diff --git a/tui_gateway/server.py b/tui_gateway/server.py
index b57e63ca010..0fe842ff4db 100644
--- a/tui_gateway/server.py
+++ b/tui_gateway/server.py
@@ -2375,6 +2375,14 @@ def _start_agent_build(sid: str, session: dict) -> None:
finally:
_clear_session_context(tokens)
+ # Bot Mode gate hint: the DB title lands post-first-turn
+ # (pending_title), but the system prompt builds at turn START —
+ # hand the agent its intended title so the "Bot Chat" protocol
+ # gate (agent/system_prompt.py) doesn't depend on write order.
+ _title_hint = str(current.get("pending_title") or "").strip()
+ if _title_hint:
+ agent._session_title_hint = _title_hint
+
# Session DB row deferred to first run_conversation() call.
# pending_title applied post-first-message (see cli.exec handler).
current["agent"] = agent