Preserve Responses API reasoning items during tool continuations
Problem
The responses-api backend currently handles response messages and function calls, but drops reasoning output items in both streaming and non-streaming flows. Chat.SupportedItem also has no representation for reasoning items, so manual context replay sends the function call and function_call_output without the reasoning items that accompanied the call.
OpenAI recommends passing reasoning items back with tool outputs for reasoning models, either through previous_response_id or by replaying all relevant output items unchanged. Dropping them can reduce tool-calling quality, increase reasoning-token usage, or break continuation behavior as reasoning support evolves.
Reference: https://developers.openai.com/api/docs/guides/reasoning#keeping-reasoning-items-in-context
Scope
- retain reasoning output items from streaming and non-streaming Responses calls
- preserve item IDs, encrypted content, summaries, and ordering without mutation
- replay relevant reasoning items alongside function calls and function outputs
- keep bounded history, compaction, cancellation, speculative turns, and out-of-band responses correct
- preserve provider-issued function-call IDs needed by exact manual replay
Acceptance criteria
- a Responses turn containing
reasoningfollowed byfunction_callcan accept a matchingfunction_call_outputon the next request - the next request includes the original reasoning and function-call items in their original order
- streaming and non-streaming regression tests cover the complete tool continuation
- existing non-reasoning and OpenAI-compatible provider behavior remains covered
Source: huggingface/speech-to-speech