Skip to content

Conversation

@yurekami
Copy link

Summary

Fixes #34166

When using deepseek-reasoner with tool calling, multi-turn conversations fail with:

Missing `reasoning_content` field in the assistant message at message index 1

Root Cause: The parent's _get_request_payload method doesn't preserve the reasoning_content field from additional_kwargs when converting AIMessage to the payload format.

Changes

  • Modified _get_request_payload to extract reasoning_content from AIMessage.additional_kwargs before calling the parent method
  • Added logic to include reasoning_content in the assistant message payload for multi-turn conversations
  • For deepseek-reasoner models, automatically add empty reasoning_content if not present (DeepSeek API requires this field)

Test plan

Added 3 new unit tests:

  • test_get_request_payload_preserves_reasoning_content - verifies reasoning_content is preserved from additional_kwargs
  • test_get_request_payload_adds_empty_reasoning_for_reasoner - verifies empty reasoning_content is added for reasoner models
  • test_get_request_payload_no_reasoning_for_non_reasoner - verifies non-reasoner models don't get reasoning_content added

Disclaimer

This PR was generated with assistance from an AI agent (Claude Code).

🤖 Generated with Claude Code

Fixes langchain-ai#34166

When using `deepseek-reasoner` with tool calling, the second API call
fails with "Missing `reasoning_content` field in the assistant message".
This occurs because the parent's `_get_request_payload` method doesn't
preserve the `reasoning_content` field from `additional_kwargs` when
converting messages to the payload format.

Changes:
- Modified `_get_request_payload` to extract `reasoning_content` from
  `AIMessage.additional_kwargs` before calling the parent method
- Added logic to include `reasoning_content` in the assistant message
  payload for multi-turn conversations
- For `deepseek-reasoner` models, automatically add empty
  `reasoning_content` if not present (API requires this field)

This ensures that when resending conversation history to the DeepSeek
API, the `reasoning_content` field is properly included in assistant
messages, fixing the 400 error in multi-turn tool calling scenarios.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@github-actions github-actions bot added integration PR made that is related to a provider partner package integration deepseek `langchain-deepseek` package issues & PRs labels Dec 28, 2025
@mdrxy mdrxy changed the title deepseek: preserve reasoning_content in multi-turn conversations fix(deepseek): preserve reasoning_content in multi-turn conversations Dec 29, 2025
@github-actions github-actions bot added the fix For PRs that implement a fix label Dec 29, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

deepseek `langchain-deepseek` package issues & PRs fix For PRs that implement a fix integration PR made that is related to a provider partner package integration

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[langchain-deepseek] Missing reasoning_content in request payload when using deepseek-reasoner with tool calling

1 participant