You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I ran into this as I was researching differences between AI SDK's streamText() and DurableAgent's implementation. I came upon sanitizeProviderMetadataForToolCall() and tried to find out why it exists in the first place. Is there a reason why reasoning is not tracked or is that an oversight?
Problem
When DurableAgent's tool loop continues to the next step, the assistant message sent back to the model only contains tool-call parts — reasoning content is omitted:
This means reasoning models (OpenAI o-series, Anthropic extended thinking, Gemini thinking) lose access to their own prior reasoning during multi-step tool loops in DurableAgent, but not in streamText.
Impact
OpenAI itemId workaround would become unnecessary. PR fix(ai): strip openai itemID from tool call metadata #889 strips itemId from OpenAI metadata because it references reasoning items that aren't in the conversation. If reasoning items were preserved, itemId references would be valid and no sanitization would be needed.
Parity with AI SDK.streamText preserves reasoning across steps. DurableAgent should too.
Proposed Fix
The reasoning data is already available — chunksToStep() in do-stream-step.ts collects reasoning chunks into the step result. The fix is to include reasoning content parts in the assistant message alongside tool-call parts in stream-text-iterator.ts, mirroring what toResponseMessages() does in the AI SDK.
This would also allow removing sanitizeProviderMetadataForToolCall() and the provider-specific itemId stripping from PR #889.
I ran into this as I was researching differences between AI SDK's
streamText()and DurableAgent's implementation. I came uponsanitizeProviderMetadataForToolCall()and tried to find out why it exists in the first place. Is there a reason why reasoning is not tracked or is that an oversight?Problem
When DurableAgent's tool loop continues to the next step, the assistant message sent back to the model only contains tool-call parts — reasoning content is omitted:
The AI SDK's own
streamTextincludes reasoning parts in the assistant message viatoResponseMessages():This means reasoning models (OpenAI o-series, Anthropic extended thinking, Gemini thinking) lose access to their own prior reasoning during multi-step tool loops in DurableAgent, but not in
streamText.Impact
OpenAI
itemIdworkaround would become unnecessary. PR fix(ai): strip openai itemID from tool call metadata #889 stripsitemIdfrom OpenAI metadata because it references reasoning items that aren't in the conversation. If reasoning items were preserved,itemIdreferences would be valid and no sanitization would be needed.Reasoning model quality during tool loops. As raised in Bug: DurableAgent + OpenAI Responses API fails on tool calls due to missing required
reasoningitem #880 by @bhuvaneshprasad: "without (itemId + reasoningItem) or previousResponseId, the code will still function, but I'm unclear on whether the reasoning models would be able to access and leverage the prior reasoning text to improve performance." This was never answered and the workaround was merged instead.Parity with AI SDK.
streamTextpreserves reasoning across steps. DurableAgent should too.Proposed Fix
The reasoning data is already available —
chunksToStep()indo-stream-step.tscollects reasoning chunks into the step result. The fix is to include reasoning content parts in the assistant message alongside tool-call parts instream-text-iterator.ts, mirroring whattoResponseMessages()does in the AI SDK.This would also allow removing
sanitizeProviderMetadataForToolCall()and the provider-specificitemIdstripping from PR #889.Context
reasoningitem #880 — OpenAI Responses API fails on tool calls due to missing reasoning itemitemIdfrom metadatapreviousResponseIdthoughtSignaturedropped (fixed in fix(ai): preserve providerMetadata as providerOptions in multi-turn tool calls #733, but reasoning content still not preserved)