langchain - 💡(How to fix) Fix ChatDeepSeek drops reasoning_content on outbound requests, breaking multi-turn / tool-using flows with reasoner models [1 comments, 2 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
langchain-ai/langchain#37389Fetched 2026-05-14 03:28:44
View on GitHub
Comments
1
Participants
2
Timeline
3
Reactions
0
Author
Timeline (top)
closed ×1commented ×1labeled ×1

Error Message

openai.BadRequestError: Error code: 400 - {'error': {'message': 'The reasoning_content in the thinking mode must be passed back to the API.', ...}}

Code Example

from langchain_core.tools import tool
from langchain_deepseek import ChatDeepSeek
from langgraph.prebuilt import create_react_agent

@tool
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

llm = ChatDeepSeek(model="deepseek-reasoner")  # or any reasoner model
agent = create_react_agent(llm, [add])
agent.invoke({"messages": [("user", "What is 17 + 25? Use the add tool.")]})

---

openai.BadRequestError: Error code: 400 - {'error': {'message':
  'The `reasoning_content` in the thinking mode must be passed back to the API.',
  ...}}
RAW_BUFFERClick to expand / collapse

Package

langchain-deepseek 1.0.1

Problem

ChatDeepSeek._create_chat_result captures reasoning_content from API responses into AIMessage.additional_kwargs, but the outbound path inherited from BaseChatOpenAI._get_request_payload (via _convert_message_to_dict in langchain_openai.chat_models.base) drops it when serializing assistant messages back to the API.

DeepSeek's reasoner models (e.g. deepseek-reasoner) require the prior turn's reasoning_content to be echoed back on each multi-turn request, and reject the call with HTTP 400 otherwise:

The reasoning_content in the thinking mode must be passed back to the API.

This is documented at https://api-docs.deepseek.com/guides/reasoning_model under "Multi-round conversation".

Effect

Single-shot invoke() works fine. Any agent loop that follows a model response with a tool result and then re-invokes the model breaks immediately on the second turn — including create_react_agent / create_agent in LangGraph, or any custom loop that re-sends conversation history with tool messages.

Reproduction

from langchain_core.tools import tool
from langchain_deepseek import ChatDeepSeek
from langgraph.prebuilt import create_react_agent

@tool
def add(a: int, b: int) -> int:
    """Add two numbers."""
    return a + b

llm = ChatDeepSeek(model="deepseek-reasoner")  # or any reasoner model
agent = create_react_agent(llm, [add])
agent.invoke({"messages": [("user", "What is 17 + 25? Use the add tool.")]})

Result on the second turn (after the tool returns):

openai.BadRequestError: Error code: 400 - {'error': {'message':
  'The `reasoning_content` in the thinking mode must be passed back to the API.',
  ...}}

Proposed fix

Override _get_request_payload to mirror additional_kwargs["reasoning_content"] onto outbound assistant message dicts — symmetrical with the inbound capture already done in _create_chat_result.

Happy to open a PR if a maintainer can approve this approach and assign me. Branch is ready at https://github.com/skychiu/langchain/tree/fix/deepseek-echo-reasoning-content (unit tests included, lint and existing tests still pass).

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

langchain - 💡(How to fix) Fix ChatDeepSeek drops reasoning_content on outbound requests, breaking multi-turn / tool-using flows with reasoner models [1 comments, 2 participants]