feat: handle reasoning summary events from OpenAI Responses API#1958
Open
sagimedina1 wants to merge 2 commits intostrands-agents:mainfrom
Open
feat: handle reasoning summary events from OpenAI Responses API#1958sagimedina1 wants to merge 2 commits intostrands-agents:mainfrom
sagimedina1 wants to merge 2 commits intostrands-agents:mainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
GPT-5.x models with
reasoning.summary="auto"|"concise"|"detailed"emitresponse.reasoning_summary_text.deltaevents for readable reasoning summaries. The existing handler only coversresponse.reasoning_text.delta(used by o1/o3 for encrypted reasoning), so reasoning summary content is silently dropped during streaming.This PR adds:
response.reasoning_summary_text.delta— treated identically toresponse.reasoning_text.delta, emittingreasoningContentcontent blocksresponse.reasoning_summary_part.added/done,response.reasoning_summary_text.done)Motivation
When using GPT-5.4 with
reasoning={"effort": "low", "summary": "auto"}throughOpenAIResponsesModel, the API returns reasoning summaries asresponse.reasoning_summary_text.deltaevents. Without this fix, those events are ignored and noreasoningContentblocks appear in the stream — even though the model is actively reasoning.Tested by comparing
stream_async()output with and without this change:delta.keys: ['reasoningContent']Test plan
hatch test)hatch fmt --formatter)hatch fmt --linter)stream_async()with GPT-5.4-mini +reasoning.summary="auto"producesreasoningContentcontent blocks