fix(agent): persist shortcut commands without polluting LLM context

Shortcut commands (e.g. /help, /pairing) skip BUILD and SAVE states,
so their turns were never persisted to the session.  This caused WebUI
chats to appear empty after _turn_end because history hydration reads
from the session file.

Fix by persisting the user message and assistant response inside
_state_command, but tag them with _command=True so Session.get_history
filters them out of LLM context.  /new is excluded because it
intentionally clears the session.

- AgentLoop._persist_user_message_early now accepts **kwargs so
  _state_command can pass _command=True for the user turn.
- Session.get_history skips messages with _command=True.
This commit is contained in:
chengyongru
2026-05-14 23:51:58 +08:00
committed by Xubin Ren
parent 8b724d510e
commit 26665823e3
3 changed files with 51 additions and 0 deletions
+2
View File
@@ -139,6 +139,8 @@ class Session:
out: list[dict[str, Any]] = []
for message in sliced:
if message.get("_command"):
continue
content = message.get("content", "")
role = message.get("role")
if role == "assistant" and isinstance(content, str):