Skip to content

The agent that grows with you

fix(agent): don't promote Anthropic summarized thinking to the final answer

Teknium0b088a78a6f5
diff --git a/agent/turn_final_response.py b/agent/turn_final_response.py
index 6ebc40503d3..5d299c6c2bf 100644
--- a/agent/turn_final_response.py
+++ b/agent/turn_final_response.py
@@ -95,12 +95,22 @@ def finish_text_response(
# from a real reply on every history surface (#111761). The row keeps ``content``
# empty with the text in its reasoning fields and carries the promoted text as the
# ``api_content`` sidecar, so the next turn still replays it byte-identically.
+ # Anthropic thinking (signed ``thinking`` block, or a plugin's ``*.native_assistant`` carrier
+ # of native Claude turns) is a summary written by a separate model, never the answer: it
+ # takes the empty-response continuation below instead.
_content = assistant_message.content
_promoted = None
if (
finish_reason == "stop"
and not assistant_message.tool_calls
and (_content is None or (isinstance(_content, str) and not _content.strip()))
+ and not any(
+ isinstance(d, dict) and (
+ (d.get("type") in ("thinking", "redacted_thinking") and (d.get("signature") or d.get("data")))
+ or str(d.get("type") or "").endswith(".native_assistant")
+ )
+ for d in getattr(assistant_message, "reasoning_details", None) or ()
+ )
):
_promoted = agent._extract_reasoning(assistant_message) or None
if _promoted:
diff --git a/tests/agent/test_reasoning_only_stop_persistence.py b/tests/agent/test_reasoning_only_stop_persistence.py
index 063fcab0f60..507d34dcad9 100644
--- a/tests/agent/test_reasoning_only_stop_persistence.py
+++ b/tests/agent/test_reasoning_only_stop_persistence.py
@@ -175,3 +175,52 @@ def test_genuine_reasoning_only_answer_with_tools_still_promotes_on_first_call(l
])
assert result["api_calls"] == 1
assert result["final_response"] == answer
+
+
+# ── Anthropic summarized thinking is not an answer ──────────────────────────────────────────
+
+SUMMARY = "The user asks for 391's factors; checking divisibility by 17 gives 23."
+
+
+def test_anthropic_signed_thinking_only_stop_continues_instead_of_promoting(loop_agent):
+ """Claude 4.7+/5.x thinking arrives as a ``display: "summarized"`` block written by a separate
+ summarizer model. A thinking-only ``end_turn`` must take the empty-response continuation, not
+ return the summary as the answer; the next call's text is the answer."""
+ from types import SimpleNamespace
+
+ def _anthropic(*blocks):
+ return SimpleNamespace(content=list(blocks), stop_reason="end_turn", stop_details=None,
+ model="claude-opus-5-5", usage=None)
+
+ loop_agent.api_mode = "anthropic_messages"
+ loop_agent.provider = "anthropic"
+ thinking_only = _anthropic(SimpleNamespace(type="thinking", thinking=SUMMARY, signature="sig-abc"))
+ answer = _anthropic(SimpleNamespace(type="text", text="391 = 17 x 23."))
+ with (
+ patch.object(loop_agent, "_interruptible_api_call", side_effect=[thinking_only, answer]),
+ patch.object(loop_agent, "_interruptible_streaming_api_call", side_effect=[thinking_only, answer]),
+ patch.object(loop_agent, "_persist_session"),
+ patch.object(loop_agent, "_save_trajectory"),
+ patch.object(loop_agent, "_cleanup_task_resources"),
+ ):
+ result = loop_agent.run_conversation("factor 391")
+
+ assert result["final_response"] == "391 = 17 x 23."
+ assert result["api_calls"] == 2
+
+
+def test_native_claude_carrier_thinking_only_stop_continues_instead_of_promoting(loop_agent):
+ """Same contract for a chat_completions plugin replaying native Claude turns through a
+ ``<provider>.native_assistant`` reasoning_details carrier (claude-subscription-directsdk)."""
+ from tests.agent.test_run_agent import _mock_response
+
+ carrier = [{"type": "claude-subscription-directsdk-experimental.native_assistant", "version": 1,
+ "messages": [{"role": "assistant", "content": [
+ {"type": "thinking", "thinking": SUMMARY, "signature": "sig-abc"}]}]}]
+ result = _run(loop_agent, [
+ _mock_response(content=None, finish_reason="stop", reasoning_content=SUMMARY, reasoning_details=carrier),
+ _mock_response(content="391 = 17 x 23.", finish_reason="stop"),
+ ])
+
+ assert result["final_response"] == "391 = 17 x 23."
+ assert result["api_calls"] == 2