Skip to content

fix: #2155 DeepSeek reasoning_content missing in tool call messages - #2328

Merged
seratch merged 4 commits into
openai:mainfrom
wahmd:fix/deepseek-reasoning-content
Jan 19, 2026
Merged

fix: #2155 DeepSeek reasoning_content missing in tool call messages#2328
seratch merged 4 commits into
openai:mainfrom
wahmd:fix/deepseek-reasoning-content

Conversation

@wahmd

@wahmd wahmd commented Jan 18, 2026

Copy link
Copy Markdown
Contributor

This PR fixes issue #2155 (400 error on tool calls due to missing reasoning_content in reconstructed assistant messages.)

Root Cause: When DeepSeek returns a response with reasoning_content and tool_calls, the SDK converts it to:

  • A ResponseReasoningItem (stores reasoning in summary field)
  • A ResponseFunctionToolCall (stores tool call)

On the next API call, Converter.items_to_messages() reconstructs the assistant message with tool calls, but was only handling reasoning content for Anthropic/Claude models (via thinking blocks), not DeepSeek.

Solution: The fix follows the same pattern as Anthropic's thinking blocks but uses DeepSeek's reasoning_content field instead. It:

  1. Extracts reasoning text from the summary field when processing reasoning items for DeepSeek models
  2. Stores it temporarily in pending_reasoning_content
  3. Adds it to the assistant message when tool calls are processed

Checks

  • I've added new tests
  • I've run make lint and make format (linter shows only import resolution warnings, not code issues)
  • I've made sure tests pass

Note: The fix works for both code paths:

  • LiteLLM path: When using LitellmModel with model="deepseek/deepseek-reasoner"
  • OpenAI ChatCompletions path: When using OpenAIChatCompletionsModel with model="deepseek-reasoner" and DeepSeek's OpenAI-compatible endpoint

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 5dbdcc302a

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/models/chatcmpl_converter.py
@seratch

seratch commented Jan 18, 2026

Copy link
Copy Markdown
Member

@codex review again

@seratch
seratch marked this pull request as draft January 18, 2026 23:03
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Chef's kiss.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

- Add pending_reasoning_content tracking for DeepSeek models
- Extract reasoning content from summary field in reasoning items
- Apply reasoning_content to assistant messages with tool_calls
- Works for both LiteLLM and OpenAI ChatCompletions paths

Fixes openai#2155
@wahmd
wahmd force-pushed the fix/deepseek-reasoning-content branch from f8c3a0f to c7fddce Compare January 19, 2026 00:08
@seratch

seratch commented Jan 19, 2026

Copy link
Copy Markdown
Member

can you fix the lint issue?

Comment thread tests/test_agent_runner_sync.py
@wahmd
wahmd marked this pull request as ready for review January 19, 2026 00:34

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: df5e138c48

ℹ️ About Codex in GitHub

Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".

Comment thread src/agents/models/chatcmpl_converter.py
@seratch

seratch commented Jan 19, 2026

Copy link
Copy Markdown
Member

can you fix the mypy error?

@seratch seratch added this to the 0.6.x milestone Jan 19, 2026
@seratch
seratch merged commit 8455af0 into openai:main Jan 19, 2026
9 checks passed
@Sourav-Nandy-ai

Copy link
Copy Markdown

Hi Waleed,

Your fix for DeepSeek's missing reasoning_content field on tool-call messages is the kind of correctness fix where confirming "the crash is gone" and confirming "tool-call behavior actually stabilized across a distribution of runs" are two different questions. The first is easy to eyeball, while the second usually is not.

Since you would find out anyway if you tried it, I want to mention that when I first looked at this PR, the OpenAI Agents SDK integration for agent-eval (agent_regress) would have crashed on the very first call against any agent. It was calling a method that does not exist on the SDK's Agent class.

That is fixed now. It calls the SDK's actual Runner.run() entrypoint, and I independently reproduced this end-to-end against a live openai-agents install (with 6 out of 6 integration tests passing) rather than just a unit-test mock.

I am not claiming I have run agent-eval against your DeepSeek and tool-call scenario specifically, as I have not. However, the underlying idea (running an agent N times pre-fix and N times post-fix to get a Mann-Whitney p-value, Cohen's d, and bootstrap CI instead of simply eyeballing whether the 400 error is gone) is built exactly for provider-specific fixes like this one.

Given you are building EMR tooling where a silent tool-call behavior shift would actually matter, I would be interested in your take on whether this is useful now that the integration itself is not broken on contact.

You can find the repository here: https://github.com/RudrenduPaul/agent-eval

Best,
Sourav

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants