spring-ai icon indicating copy to clipboard operation
spring-ai copied to clipboard

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

Open suryateja-g13 opened this issue 6 months ago • 1 comments

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

  • [x] ./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

suryateja-g13 avatar May 27 '26 16:05 suryateja-g13

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.

suryateja-g13 avatar May 27 '26 16:05 suryateja-g13