fix(agent): do not persist runtime context metadata in session history

This commit is contained in:
Kim
2026-02-26 14:12:37 +08:00
parent cc425102ac
commit 45ae410f05

View File

@@ -467,6 +467,14 @@ class AgentLoop:
content = entry["content"]
if len(content) > self._TOOL_RESULT_MAX_CHARS:
entry["content"] = content[:self._TOOL_RESULT_MAX_CHARS] + "\n... (truncated)"
if (
entry.get("role") == "user"
and isinstance(entry.get("content"), str)
and entry["content"].startswith(ContextBuilder._RUNTIME_CONTEXT_TAG)
):
# Runtime metadata is injected per-turn for model context only; do not persist it
# into long-lived session history to avoid semantic drift and repetitive replies.
continue
if entry.get("role") == "user" and isinstance(entry.get("content"), list):
entry["content"] = [
{"type": "text", "text": "[image]"} if (