Skip to content

Conversation

@hannesrudolph
Copy link
Collaborator

@hannesrudolph hannesrudolph commented Dec 20, 2025

Problem

DeepSeek's interleaved thinking mode requires reasoning_content to be passed back during multi-turn tool call sequences. After context condensing, this field was being lost, causing 400 API errors with the message:

Missing reasoning_content field in the assistant message at message index 1

Root Cause

The buildCleanConversationHistory() function in Task.ts was stripping reasoning_content from assistant messages before sending them to the API. According to the DeepSeek API documentation:

Since the tool invocation process in thinking mode requires users to pass back reasoning_content to the API, if your code does not correctly pass back reasoning_content, the API will return a 400 error.

Changes

  1. Added reasoning_content field to ApiMessage type - This ensures the type system properly tracks this field through the codebase.

  2. Updated condense logic to preserve reasoning_content - Added getReasoningContent() helper function and ensured messages retained after condensing preserve their reasoning content.

  3. 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.

  4. Updated buildCleanConversationHistory() - Now preserves reasoning_content on assistant messages when sending to the API.

  5. Added comprehensive tests - Tests verify reasoning content preservation and turn alternation fixes.

Testing

  • All 41 condense tests pass
  • All 20 r1-format tests pass
  • Full test suite passes (4923 tests)

Documentation Reference


Important

Preserve reasoning_content in DeepSeek API messages to prevent errors and ensure proper turn alternation in message condensing.

  • Behavior:
    • Preserve reasoning_content in getKeepMessagesWithToolBlocks() and buildCleanConversationHistory() to prevent DeepSeek API errors.
    • Ensure turn alternation by extending keep range backwards in getKeepMessagesWithToolBlocks().
  • Types:
    • Add reasoning_content to ApiMessage type in apiMessages.ts.
  • Functions:
    • Update getKeepMessagesWithToolBlocks() in index.ts to handle reasoning_content and turn alternation.
    • Modify buildCleanConversationHistory() in Task.ts to include reasoning_content in API messages.
  • Tests:
    • Add tests in index.spec.ts to verify reasoning_content preservation and turn alternation logic.

This description was created by Ellipsis for 5028d0c. You can customize this summary. It will automatically update as commits are pushed.

…nsmission

DeepSeek's interleaved thinking mode requires reasoning_content to be passed
back during multi-turn tool call sequences. After context condensing, this
field was being lost, causing 400 API errors.

Root cause: buildCleanConversationHistory() was stripping reasoning_content
from assistant messages before sending to the API.

Changes:
- Add reasoning_content field to ApiMessage type
- Preserve reasoning_content during condense operations
- Fix turn alternation to prevent consecutive assistant messages after summary
- Pass reasoning_content through buildCleanConversationHistory() to API
- Add comprehensive tests for the fix

See: https://api-docs.deepseek.com/guides/thinking_mode#tool-calls
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. bug Something isn't working labels Dec 20, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 20, 2025

Oroocle Clock   See task on Roo Cloud

Reviewed. No issues found.

  • No issues found

Mention @roomote in a comment to request specific changes to this pull request or fix all unresolved issues.

@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. size:L This PR changes 100-499 lines, ignoring generated files.

Projects

Status: Triage

Development

Successfully merging this pull request may close these issues.

2 participants