fix: preserve DeepSeek reasoning_content through condense and API transmission #10222
+347
−20
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Problem
DeepSeek's interleaved thinking mode requires
reasoning_contentto be passed back during multi-turn tool call sequences. After context condensing, this field was being lost, causing 400 API errors with the message:Root Cause
The
buildCleanConversationHistory()function in Task.ts was strippingreasoning_contentfrom assistant messages before sending them to the API. According to the DeepSeek API documentation:Changes
Added
reasoning_contentfield toApiMessagetype - This ensures the type system properly tracks this field through the codebase.Updated condense logic to preserve
reasoning_content- AddedgetReasoningContent()helper function and ensured messages retained after condensing preserve their reasoning content.Fixed turn alternation - After condensing, the summary message (assistant) followed by kept messages could create consecutive assistant messages. Added logic to inject an empty user message when needed to maintain proper turn alternation.
Updated
buildCleanConversationHistory()- Now preservesreasoning_contenton assistant messages when sending to the API.Added comprehensive tests - Tests verify reasoning content preservation and turn alternation fixes.
Testing
Documentation Reference
Important
Preserve
reasoning_contentin DeepSeek API messages to prevent errors and ensure proper turn alternation in message condensing.reasoning_contentingetKeepMessagesWithToolBlocks()andbuildCleanConversationHistory()to prevent DeepSeek API errors.getKeepMessagesWithToolBlocks().reasoning_contenttoApiMessagetype inapiMessages.ts.getKeepMessagesWithToolBlocks()inindex.tsto handlereasoning_contentand turn alternation.buildCleanConversationHistory()inTask.tsto includereasoning_contentin API messages.index.spec.tsto verifyreasoning_contentpreservation and turn alternation logic.This description was created by
for 5028d0c. You can customize this summary. It will automatically update as commits are pushed.