AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

[Langchain-Deepseek] _Get_request_payload Drops Reasoning_content From Prior Assistant Messages, Causing 400 Errors On Tool Calls

ChatDeepSeek's message serialization omits `reasoning_content` from AIMessage.additional_kwargs, causing DeepSeek API 400 errors in multi-turn tool-calling conversations when the model requires the previous reasoning content to be passed back.

highConfidence 85%LangchainMemoryRetrieverslangchain-coreAffected V1.1.0

Origin Analysis

The `_get_request_payload` method (and/or its underlying message converter) builds OpenAI-style message dicts by copying only known fields like role, content, and tool_calls, ignoring custom `additional_kwargs` such as `reasoning_content`. DeepSeek's thinking mode API contract requires that `reasoning_content` from prior assistant messages be included in follow-up requests, so its omission leads to invalid_request_error 400 responses.
Run the following with langchain-deepseek 1.1.0: ```python from langchain_deepseek.chat_models import ChatDeepSeek from langchain_core.messages import AIMessage, HumanMessage model = ChatDeepSeek(model="deepseek-v4-flash", api_key="fake_api_key") messages = [ HumanMessage(content="Hello!"), AIMessage( content="Hello, can i help you?", additional_kwargs={"reasoning_content": "Simple greeting, Just greet back in English casually."} ) ] print(model._get_request_payload(messages)) ``` Observe that the assistant message dict lacks `reasoning_content`. When such messages are sent in a multi-round conversation with tool calls, the API returns `openai.BadRequestError: 400 - The 'reasoning_content' in the thinking mode must be passed back to the API.`

Fixing Code Block

Edge Case Audit

This is a temporary workaround that relies on the current signature and return shape of _get_request_payload. If upstream changes the method or the payload structure, the patch may need adjustment. The `not in` guard already avoids redundant injection if an official fix later adds the field natively. Users should only use reasoning-capable DeepSeek models; passing reasoning_content to non-reasoning models might cause API errors. Rollback is simply removing the monkey-patch block and upgrading to a version that includes the official fix.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state