fix(ai-sdk): preserve reasoning parts in message conversion#11196
Open
hannesrudolph wants to merge 3 commits intomainfrom
Open
fix(ai-sdk): preserve reasoning parts in message conversion#11196hannesrudolph wants to merge 3 commits intomainfrom
hannesrudolph wants to merge 3 commits intomainfrom
Conversation
Contributor
Review status: 1 issue remaining after latest commit.
Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues. |
dc385a4 to
b0a3feb
Compare
mrubens
reviewed
Feb 5, 2026
| // Preserve plain-text reasoning blocks for: | ||
| // - models explicitly opting in via preserveReasoning | ||
| // - AI SDK providers (provider packages decide what to include in the native request) | ||
| const aiSdkProviders = new Set([ |
Collaborator
There was a problem hiding this comment.
Is there a way to figure this out dynamically? I’m worried about forgetting to update this when we add them
mrubens
approved these changes
Feb 5, 2026
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.
Problem
When using AI-SDK-backed providers (notably DeepSeek
deepseek-reasoner) across tool-call turns, the provider may require the assistant's reasoning to be round-tripped (e.g. viareasoning_content). We were dropping that reasoning during our Anthropic → AI SDK message conversion, which can cause DeepSeek to reject follow-up requests after a tool call.Context: DeepSeek “thinking mode” requires returning
reasoning_contentin subsequent requests within the same turn when tool calls are involved.Closes #11199
What changed
1) Preserve reasoning through the AI SDK conversion layer
convertToAiSdkMessages()now converts:{ type: "reasoning", text: string }content blocks → AI SDK{ type: "reasoning", text }parts{ type: "thinking", thinking, signature }→ AI SDK{ type: "reasoning", text }partsreasoning_content(when present) → a canonical AI SDK reasoning part (avoids duplicating with content blocks)This keeps the AI SDK
ModelMessagestream complete, so the provider package (e.g.@ai-sdk/deepseek) can decide what to send to the native API (including mapping reasoning parts back intoreasoning_content).2) Store reasoning as structured content in task history (instead of
<think>tags)Task.addToApiConversationHistory()now persists reasoning as a dedicated first assistant content block (type: "reasoning"), rather than embedding<think>...</think>into the text.This enables consistent round-tripping and avoids mixing reasoning into user-visible text.
3) Cleanup
"openai-compatible"from the API-provider reasoning allowlist (it is not aProviderName; it’s used for code-index embedding).Tests
ai-sdk.spec.tsreasoning-preservation.test.ts