Skip to content

fix(ai-sdk): preserve reasoning parts in message conversion#11217

Merged
hannesrudolph merged 5 commits intomainfrom
reapply/pr-11196
Feb 5, 2026
Merged

fix(ai-sdk): preserve reasoning parts in message conversion#11217
hannesrudolph merged 5 commits intomainfrom
reapply/pr-11196

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Feb 5, 2026

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. via reasoning_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_content in 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:
    • our stored { type: "reasoning", text: string } content blocks → AI SDK { type: "reasoning", text } parts
    • Anthropic extended thinking blocks { type: "thinking", thinking, signature } → AI SDK { type: "reasoning", text } parts
    • message-level reasoning_content (when present) → a canonical AI SDK reasoning part (avoids duplicating with content blocks)

This keeps the AI SDK ModelMessage stream complete, so the provider package (e.g. @ai-sdk/deepseek) can decide what to send to the native API (including mapping reasoning parts back into reasoning_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

  • Removed invalid "openai-compatible" from the API-provider reasoning allowlist (it is not a ProviderName; it’s used for code-index embedding).

Tests

@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Feb 5, 2026
@roomote
Copy link
Contributor

roomote bot commented Feb 5, 2026

Oroocle Clock   See task on Roo Cloud

Re-review after latest commit: follow-up resolved; no additional issues found.

  • Ensure flattenAiSdkMessagesToStringContent still works when reasoning parts are present (avoid sending multipart content to string-only models like SambaNova DeepSeek).
  • Revisit the aiSdkProviders reasoning preserve allowlist in Task.buildCleanConversationHistory (missing AI SDK providers like gemini and vertex, or switch to a capability-based check).
Previous reviews

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

- Add isAiSdkProvider() method to ApiHandler interface
- Default implementation in BaseProvider returns false
- Override to return true in 11 AI SDK providers:
  deepseek, fireworks, mistral, groq, xai, cerebras,
  sambanova, huggingface, gemini, vertex, openai-compatible
- Update Task.ts to use dynamic detection instead of hardcoded Set
- Add method to FakeAIHandler and update test mocks
- Strip reasoning parts when flattening messages for string-only models
- Allow flattening when message contains only text and reasoning parts
- Add tests for reasoning part handling in string-only model contexts

This addresses the review feedback about ensuring flattenAiSdkMessagesToStringContent
works correctly when reasoning parts are present (e.g., SambaNova DeepSeek).
@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Feb 5, 2026
@hannesrudolph hannesrudolph merged commit 1b75d59 into main Feb 5, 2026
13 checks passed
@hannesrudolph hannesrudolph deleted the reapply/pr-11196 branch February 5, 2026 17:48
@github-project-automation github-project-automation bot moved this from New to Done in Roo Code Roadmap Feb 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AI SDK message conversion loses assistant reasoning/thinking content

3 participants