Skip to content

The agent that grows with you

fix: keep reasoning_details on the iteration-summary messages; the transport drops it per route

teknium142bdab86ab6c
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index f8a07dd1fe8..ac10d92af11 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -2058,9 +2058,11 @@ _EMPTY_SUMMARY_RESPONSE = "I reached the iteration limit and couldn't generate a
def _iteration_summary_api_messages(agent, messages: list) -> list:
"""Wire-ready messages for the summary call, mirroring the main loop's api_messages build
- (sidecar substitution, tool-call repair, thinking-only drop, underscore-key sweep)."""
- from agent.transports.chat_completions import _route_replays_reasoning_details
+ (sidecar substitution, tool-call repair, thinking-only drop, underscore-key sweep).
+ ``reasoning_details`` is kept: the anthropic_messages converter rebuilds signed thinking
+ blocks from it, and the chat-completions transport already drops it on the wire for routes
+ that do not replay it (``_chat_summary_attempt`` -> ``_build_api_kwargs``)."""
needs_sanitize = agent._should_sanitize_tool_calls()
sanitize_model = agent.model
if needs_sanitize and agent.provider == "moa":
@@ -2073,8 +2075,6 @@ def _iteration_summary_api_messages(agent, messages: list) -> list:
agent._copy_reasoning_content_for_api(msg, api_msg)
for key in _SUMMARY_FOREIGN_MESSAGE_KEYS:
api_msg.pop(key, None)
- if not _route_replays_reasoning_details(getattr(agent, "base_url", None)):
- api_msg.pop("reasoning_details", None)
# Mirror of the transport's role-qualified strip: ``name`` is
# schema-foreign on tool results only (strict providers reject with
# "contains item with unknown key name"); it stays on user/assistant.
diff --git a/tests/agent/test_iteration_summary_reasoning_details.py b/tests/agent/test_iteration_summary_reasoning_details.py
new file mode 100644
index 00000000000..267eb942b21
--- /dev/null
+++ b/tests/agent/test_iteration_summary_reasoning_details.py
@@ -0,0 +1,44 @@
+"""The max-iterations summary call treats ``reasoning_details`` per api_mode: the
+anthropic_messages converter rebuilds signed thinking blocks from it, so the summary messages
+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 pytest
+
+from agent.chat_completion_helpers import _build_api_kwargs_for_mode, _iteration_summary_api_messages
+from run_agent import AIAgent
+
+_HISTORY = [
+ {"role": "user", "content": "q"},
+ {"role": "assistant", "content": "", "tool_calls": [{"id": "t1", "type": "function", "function": {"name": "f", "arguments": "{}"}}],
+ "reasoning_details": [{"type": "thinking", "thinking": "x", "signature": "SIG"}]},
+ {"role": "tool", "tool_call_id": "t1", "content": "r"},
+]
+
+
+def make_agent(tmp_path, monkeypatch):
+ monkeypatch.setenv("HERMES_HOME", str(tmp_path))
+
+ def _make(base_url, provider):
+ agent = AIAgent(api_key="k", base_url=base_url, provider=provider, model="m", quiet_mode=True,
+ skip_context_files=True, skip_memory=True)
+ agent._cached_system_prompt = "SYS"
+ return agent
+ return _make
+
+
+def test_anthropic_summary_messages_keep_reasoning_details(make_agent):
+ agent = make_agent("https://api.anthropic.com", "anthropic")
+ assert agent.api_mode == "anthropic_messages"
+ out = _iteration_summary_api_messages(agent, [dict(m) for m in _HISTORY])
+ assistant = next(m for m in out if m.get("role") == "assistant")
+ assert assistant["reasoning_details"] == _HISTORY[1]["reasoning_details"]
+
+
+def test_strict_chat_route_summary_wire_drops_reasoning_details(make_agent):
+ agent = make_agent("https://api.groq.com/openai/v1", "custom")
+ assert agent.api_mode == "chat_completions"
+ 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"])