Skip to content

The agent that grows with you

fix: reasoning-only streams whose deltas carry reasoning only in model_extra no longer fail as empty

Xingkai9836c987ea6e96
diff --git a/agent/chat_completion_helpers.py b/agent/chat_completion_helpers.py
index 18a9c9452de..f4516390359 100644
--- a/agent/chat_completion_helpers.py
+++ b/agent/chat_completion_helpers.py
@@ -2970,6 +2970,10 @@ class _StreamingCall(StreamingWaitMonitor):
usage_obj = chunk.usage
reasoning_text = getattr(delta, "reasoning_content", None) or getattr(delta, "reasoning", None)
+ # Same ``model_extra`` fallback as the non-streaming path: a reasoning-only stream
+ # whose deltas carry only this field otherwise trips the empty-stream guard (#56516).
+ if reasoning_text is None and isinstance(getattr(delta, "model_extra", None), dict):
+ reasoning_text = delta.model_extra.get("reasoning_content") or delta.model_extra.get("reasoning")
if reasoning_text:
# Summary-part models omit the separator between markdown blocks; re-insert it.
reasoning_text = separate_glued_reasoning_blocks(
diff --git a/contributors/emails/[email protected] b/contributors/emails/[email protected]
new file mode 100644
index 00000000000..6558bc87e64
--- /dev/null
+++ b/contributors/emails/[email protected]
@@ -0,0 +1 @@
+Xingkai98
diff --git a/tests/agent/test_run_agent.py b/tests/agent/test_run_agent.py
index 27ef25667bb..ec21547df60 100644
--- a/tests/agent/test_run_agent.py
+++ b/tests/agent/test_run_agent.py
@@ -6685,6 +6685,24 @@ class TestStreamingApiCall:
assert resp.choices[0].message.content is None
assert resp.choices[0].message.tool_calls is None
+ @pytest.mark.parametrize("carrier", ["reasoning_content", "reasoning"])
+ def test_reasoning_only_in_delta_model_extra_counts_as_stream_output(self, agent, carrier):
+ """Reasoning that reaches the stream only via ``delta.model_extra`` is real output:
+ the empty-stream guard must not fire and the text must survive (#56516)."""
+ def _extra_delta(text):
+ return SimpleNamespace(content=None, tool_calls=None, model_extra={carrier: text})
+
+ chunks = [
+ SimpleNamespace(model="m", choices=[SimpleNamespace(delta=_extra_delta("thinking "), finish_reason=None)]),
+ SimpleNamespace(model="m", choices=[SimpleNamespace(delta=_extra_delta("only"), finish_reason="length")]),
+ ]
+ agent.client.chat.completions.create.return_value = iter(chunks)
+
+ resp = agent._interruptible_streaming_api_call({"messages": []})
+
+ assert resp.choices[0].message.content is None
+ assert resp.choices[0].message.reasoning_content == "thinking only"
+ assert resp.choices[0].finish_reason == "length"
def test_model_name_captured(self, agent):
chunks = [