Skip to content

The agent that grows with you

test(agent): summary prefix parity with the main send path

Yuan Li52d0d7c8e554
diff --git a/tests/agent/test_iteration_summary_reasoning_details.py b/tests/agent/test_iteration_summary_reasoning_details.py
index 267eb942b21..53a63cfadbb 100644
--- a/tests/agent/test_iteration_summary_reasoning_details.py
+++ b/tests/agent/test_iteration_summary_reasoning_details.py
@@ -3,6 +3,8 @@ anthropic_messages converter rebuilds signed thinking blocks from it, so the sum
must keep it; a strict chat-completions route drops it on the wire via the same kwargs
builder the main loop uses (hermes-agent#70233)."""
+import json
+
import pytest
from agent.chat_completion_helpers import _build_api_kwargs_for_mode, _iteration_summary_api_messages
@@ -42,3 +44,35 @@ def test_strict_chat_route_summary_wire_drops_reasoning_details(make_agent):
api_messages = _iteration_summary_api_messages(agent, [dict(m) for m in _HISTORY])
kwargs = _build_api_kwargs_for_mode(agent, api_messages)
assert all("reasoning_details" not in m for m in kwargs["messages"])
+
+
+class TestSummaryPrefixParity:
+ """The summary request must close with the same normalization the main send
+ path applies (assemble_api_request): canonical tool-call argument JSON and
+ stripped string content — otherwise the summary's prefix diverges from every
+ prior request and prefix-caching providers re-read the whole conversation
+ (hermes-agent#123002)."""
+
+ def test_canonicalizes_tool_call_arguments_and_strips_content(self, make_agent):
+ agent = make_agent("https://api.groq.com/openai/v1", "custom")
+ history = [
+ {"role": "user", "content": " q "},
+ {"role": "assistant", "content": " thinking out loud ", "tool_calls": [
+ {"id": "t1", "type": "function",
+ "function": {"name": "f", "arguments": '{"b": 1, "a": 2}'}},
+ ]},
+ {"role": "tool", "tool_call_id": "t1", "content": " r "},
+ ]
+ snapshot = [dict(m) for m in history]
+ out = _iteration_summary_api_messages(agent, history)
+
+ assistant = next(m for m in out if m.get("role") == "assistant")
+ args = assistant["tool_calls"][0]["function"]["arguments"]
+ assert args == json.dumps({"a": 2, "b": 1}, separators=(",", ":"), sort_keys=True)
+
+ # Same whitespace contract as the main path: string content stripped on the
+ # wire copy, history untouched.
+ by_role = {m["role"]: m for m in out if m.get("role") in {"user", "tool"}}
+ assert by_role["user"]["content"] == "q"
+ assert by_role["tool"]["content"] == "r"
+ assert history == snapshot # send-path rewrites never reach the transcript