Skip to content

feat: handle reasoning summary events from OpenAI Responses API#1958

Open
sagimedina1 wants to merge 2 commits intostrands-agents:mainfrom
sagimedina1:fix/openai-reasoning-summary-events
Open

feat: handle reasoning summary events from OpenAI Responses API#1958
sagimedina1 wants to merge 2 commits intostrands-agents:mainfrom
sagimedina1:fix/openai-reasoning-summary-events

Conversation

@sagimedina1
Copy link
Copy Markdown

Summary

GPT-5.x models with reasoning.summary="auto"|"concise"|"detailed" emit response.reasoning_summary_text.delta events for readable reasoning summaries. The existing handler only covers response.reasoning_text.delta (used by o1/o3 for encrypted reasoning), so reasoning summary content is silently dropped during streaming.

This PR adds:

  • Handling for response.reasoning_summary_text.delta — treated identically to response.reasoning_text.delta, emitting reasoningContent content blocks
  • Pass-through for associated metadata events (response.reasoning_summary_part.added/done, response.reasoning_summary_text.done)

Motivation

When using GPT-5.4 with reasoning={"effort": "low", "summary": "auto"} through OpenAIResponsesModel, the API returns reasoning summaries as response.reasoning_summary_text.delta events. Without this fix, those events are ignored and no reasoningContent blocks appear in the stream — even though the model is actively reasoning.

Tested by comparing stream_async() output with and without this change:

  • Before: 0 reasoning events in the stream
  • After: reasoning content blocks stream correctly with delta.keys: ['reasoningContent']

Test plan

  • All 2395 existing unit tests pass (hatch test)
  • Formatter passes (hatch fmt --formatter)
  • Linter passes (hatch fmt --linter)
  • Manual verification: stream_async() with GPT-5.4-mini + reasoning.summary="auto" produces reasoningContent content blocks

GPT-5.x models with `reasoning.summary="auto"|"concise"|"detailed"`
emit `response.reasoning_summary_text.delta` events for readable
reasoning summaries. The existing handler only covers
`response.reasoning_text.delta` (used by o1/o3 for encrypted reasoning).

This adds handling for the summary variant so reasoning content flows
through the streaming pipeline as `reasoningContent` content blocks,
matching the existing behavior for `response.reasoning_text.delta`.

Also skips the associated metadata events
(`response.reasoning_summary_part.added/done`,
`response.reasoning_summary_text.done`) that don't carry streaming
content.
When conversation history contains reasoningContent blocks from a
previous reasoning model response (e.g., GPT-5.x with summary="auto"),
_format_request_message_content crashes because it doesn't know how
to convert them to OpenAI Responses API format.

This adds reasoningContent to the skip list alongside toolResult and
toolUse, so reasoning blocks are filtered out when re-sending
conversation history to the model.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant