spring-ai
spring-ai copied to clipboard
GH-6026: Pass reasoning_content back to DeepSeek API in multi-turn conversations
Summary
- Fixes
DeepSeekChatModel.createRequest()to forwardreasoning_contentfromDeepSeekAssistantMessagewhen rebuilding conversation history for subsequent API calls - DeepSeek reasoning models (
deepseek-reasoner) require thereasoning_contentfield 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 passednullasreasoning_contentinChatCompletionMessagefor ASSISTANT turns, silently dropping the stored value - The fix checks whether the incoming
AssistantMessageis actually aDeepSeekAssistantMessageand, if so, readsgetReasoningContent()and passes it forward - Plain
AssistantMessage(non-reasoning models likedeepseek-chat) still emitnullreasoning_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
reasoningContentIsPassedBackForDeepSeekAssistantMessageverifies the reasoning content is forwarded - New test
nullReasoningContentIsOmittedForPlainAssistantMessageverifies non-reasoning models are unaffected
Fixes: #6026
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.