Skip to content

fix(deepseek): ensure reasoning_content is included in multi-turn tool chains#13203

Open
dixoxib wants to merge 5 commits intovercel:mainfrom
dixoxib:deepseek-thinking-mode-fix
Open

fix(deepseek): ensure reasoning_content is included in multi-turn tool chains#13203
dixoxib wants to merge 5 commits intovercel:mainfrom
dixoxib:deepseek-thinking-mode-fix

Conversation

@dixoxib
Copy link
Copy Markdown

@dixoxib dixoxib commented Mar 8, 2026

Background

When using DeepSeek's thinking mode with multi-turn tool calls, the reasoning_content field was not being properly included in assistant messages. DeepSeek API which expects reasoning_content to be present in all assistant messages within the current thinking chain, even if empty, else responding with error 400.

Summary

Modified packages/deepseek/src/chat/convert-to-deepseek-chat-messages.ts to ensure reasoning_content is included for every assistant message in the current thinking chain when thinking mode is enabled. The fix ensures that when thinking mode is active and tool calls are present, an empty reasoning_content string is provided if no reasoning content exists, maintaining API compatibility with DeepSeek's requirements.

Manual Verification

  • Verified that existing test fixtures for reasoning mode continue to work correctly
  • Tested multi-turn conversations with tool calls in thinking mode using the DeepSeek provider
  • Confirmed that the fix doesn't break non-thinking mode conversations
  • Validated that JSON response format handling remains unchanged

Checklist

  • Tests have been added / updated (for bug fixes / features)
  • Documentation has been added / updated (for bug fixes / features)
  • A patch changeset for relevant packages has been added (for bug fixes / features - run pnpm changeset in the project root)
  • I have reviewed this pull request (self-review)

Future Work

Fix edge cases on DeepSeek API behavior if there's a need.

…l chains

When thinking mode is enabled, include empty reasoning_content in assistant turns that are part of a multi-turn tool chain to avoid 400 errors from DeepSeek API.
@tigent tigent Bot added ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/deepseek Issues related to the @ai-sdk/deepseek provider labels Mar 8, 2026
@dixoxib dixoxib force-pushed the deepseek-thinking-mode-fix branch from fe5895b to 66fc369 Compare March 8, 2026 17:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai/provider related to a provider package. Must be assigned together with at least one `provider/*` label bug Something isn't working as documented provider/deepseek Issues related to the @ai-sdk/deepseek provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant