Skip to content

GH-6026: Pass reasoning_content back to DeepSeek API in multi-turn conversations#6189

Open
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:gh-6026-deepseek-reasoning-content-multi-turn
Open

GH-6026: Pass reasoning_content back to DeepSeek API in multi-turn conversations#6189
suryateja-g13 wants to merge 1 commit into
spring-projects:mainfrom
suryateja-g13:gh-6026-deepseek-reasoning-content-multi-turn

Conversation

@suryateja-g13
Copy link
Copy Markdown
Contributor

Summary

  • Fixes DeepSeekChatModel.createRequest() to forward reasoning_content from DeepSeekAssistantMessage when rebuilding conversation history for subsequent API calls
  • DeepSeek reasoning models (deepseek-reasoner) require the reasoning_content field to be echoed back in ASSISTANT messages in the conversation history — without it, the API returns HTTP 400: "The reasoning_content in the thinking mode must be passed back to the API."
  • Previously createRequest() always passed null as reasoning_content in ChatCompletionMessage for ASSISTANT turns, silently dropping the stored value
  • The fix checks whether the incoming AssistantMessage is actually a DeepSeekAssistantMessage and, if so, reads getReasoningContent() and passes it forward
  • Plain AssistantMessage (non-reasoning models like deepseek-chat) still emit null reasoning_content and are unaffected

Test plan

  • ./mvnw -pl models/spring-ai-deepseek test -Dtest="DeepSeekChatCompletionRequestTests" — 3 tests pass (1 existing + 2 new)
  • New test reasoningContentIsPassedBackForDeepSeekAssistantMessage verifies the reasoning content is forwarded
  • New test nullReasoningContentIsOmittedForPlainAssistantMessage verifies non-reasoning models are unaffected

Fixes: #6026

…sations

When DeepSeek reasoning models (e.g. deepseek-reasoner) return reasoning_content,
the API requires that field to be echoed back in subsequent request messages.
The previous createRequest() always passed null as the last argument of
ChatCompletionMessage for ASSISTANT turns, silently dropping the stored
reasoning_content and causing HTTP 400 errors on second and later turns.

Fix: when mapping an AssistantMessage back to a ChatCompletionMessage, check
whether it is a DeepSeekAssistantMessage and, if so, forward its
getReasoningContent() value. Plain AssistantMessage instances (non-reasoning
models) are unaffected and still emit null reasoning_content.

Fixes: spring-projects#6026

Signed-off-by: Gorre Surya <suryateja.g13@gmail.com>
@suryateja-g13
Copy link
Copy Markdown
Contributor Author

The CI failure is the pre-existing flaky test WebClientStreamableHttpTransportErrorHandlingIT.testSessionRecoveryAfter404 in the MCP WebFlux transport integration test suite — unrelated to this PR (tracked in #5563). This test fails intermittently across many PRs that touch unrelated parts of the codebase.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[DeepSeek] HTTP 400 Error in Thinking Mode: reasoning_content not passed back to API in multi-turn conversations

1 participant