Skip to content

Missing reasoning_content field in the assistant message for DeepSeek API implementation #17523

@dixoxib

Description

@dixoxib

Description

Description

When using DeepSeek models with thinking mode enabled (either via reasoner model IDs or thinking option), assistant messages after the last user message were not receiving an (empty) reasoning_content field. This caused issues with the DeepSeek API's thinking mode behavior, where every assistant message in thinking mode must provide a reasoning_content field, even if empty.

Steps to Reproduce

  1. Use a DeepSeek model with thinking mode enabled (e.g., deepseek-reasoner model, or any DeepSeek model with thinking: { type: "enabled" } option)
  2. Send a conversation with multiple turns (user -> assistant -> user -> assistant)
  3. Observe that assistant messages after the last user message do not have reasoning_content set, when previously empty.
  4. The DeepSeek API returns error 400 in this scenario

Expected Behavior

ALL assistant messages after the last user message should have an empty reasoning_content field when thinking mode is enabled for DeepSeek models, to comply with API expectations.

Actual Behavior

Only assistant messages with non-empty reasoning content received the reasoning_content field. Assistant messages with empty reasoning content after the last user message did not have the field set.

Root Cause

The ProviderTransform.message function in packages/opencode/src/provider/transform.ts only added reasoning_content when there was actual reasoning text present, but deepseek requires also empty "" reasoning_content fields.

Solution

Modified the logic to:

  1. Detect when thinking mode is enabled for DeepSeek models (via model capabilities, model ID, or thinking option)
  2. Find the index of the last user message in the conversation
  3. For all assistant messages after that index, set an empty reasoning_content field
  4. Maintain backward compatibility for non-thinking mode usage

Affected Models

  • All DeepSeek models when thinking mode is enabled
  • deepseek-reasoner models
  • DeepSeek models with thinking: { type: "enabled" } option

Related Issues/PRs

#9397, #5577,

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions