Skip to content

Conversation

@wangxiaolong100
Copy link
Contributor

@wangxiaolong100 wangxiaolong100 commented Dec 2, 2025

Related GitHub Issue

Closes: #9744

Roo Code Task Context (Optional)

N/A

Description

This PR adds native tool calling support for the deepseek-reasoner model in thinking mode, as per the DeepSeek API documentation.

Key implementation details:

  • Override createMessage in DeepSeekHandler: When using deepseek-reasoner with native tool protocol, use convertToOpenAiMessages instead of convertToR1Format to properly handle:

    • tool_calls in assistant messages
    • role: "tool" messages with tool_call_id for tool results
  • Create dedicated OpenAI client: Since the parent class's client is private, a separate deepSeekClient is created in DeepSeekHandler for native tool calling requests.

  • Delegation pattern: For all other cases (XML protocol or deepseek-chat model), the implementation delegates to the parent class to maintain backward compatibility.

Why this change is needed:

The existing convertToR1Format function only handles text and image message types, but doesn't process tool_use and tool_result blocks required for native tool calling. This causes issues when using deepseek-reasoner with native tools enabled.

Test Procedure

  1. Configure Roo Code to use DeepSeek provider with deepseek-reasoner model
  2. Set tool protocol to native in the profile settings
  3. Start a task that requires tool usage (e.g., file operations, terminal commands)
  4. Verify that:
    • The model can make tool calls successfully
    • Tool results are properly returned to the model
    • reasoning_content (thinking chain) is still captured and displayed
    • Multi-turn tool calling works correctly

Pre-Submission Checklist

  • Issue Linked: This PR is linked to an approved GitHub Issue (see "Related GitHub Issue" above).
  • Scope: My changes are focused on the linked issue (one major feature/fix per PR).
  • Self-Review: I have performed a thorough self-review of my code.
  • Testing: New and/or updated tests have been added to cover my changes (if applicable).
  • Documentation Impact: I have considered if my changes require documentation updates (see "Documentation Updates" section below).
  • Contribution Guidelines: I have read and agree to the Contributor Guidelines.

Screenshots / Videos

N/A - This is a backend/API change with no UI impact.

Documentation Updates

  • No documentation updates are required.

Additional Notes

  • This implementation follows the official DeepSeek API documentation for thinking mode with tool calling
  • The change is minimal and focused - only affects deepseek-reasoner + native protocol combination
  • Backward compatibility is maintained for all other scenarios

Get in Touch

haha.w


Important

Adds native tool calling support for deepseek-reasoner in DeepSeekHandler by overriding createMessage and creating a dedicated OpenAI client.

  • Behavior:
    • Overrides createMessage in DeepSeekHandler to support deepseek-reasoner with native tool protocol using convertToOpenAiMessages.
    • Handles tool_calls and role: "tool" messages with tool_call_id.
    • Delegates to parent class for non-native protocols or other models.
  • Client:
    • Creates deepSeekClient in DeepSeekHandler for native tool calling requests.
  • Misc:
    • Uses XmlMatcher to process reasoning content and tool calls.
    • Adjusts processUsageMetrics to handle DeepSeek's usage metrics.

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

- Add custom createMessage override for DeepSeekHandler
- Use convertToOpenAiMessages for native tool protocol to properly handle
  tool_calls in assistant messages and tool role messages for results
- Create dedicated OpenAI client for native tool calling support
- Delegate to parent implementation for XML protocol or deepseek-chat model

Reference: https://api-docs.deepseek.com/zh-cn/guides/thinking_mode#工具调用
@dosubot dosubot bot added size:L This PR changes 100-499 lines, ignoring generated files. enhancement New feature or request labels Dec 2, 2025
@roomote
Copy link
Contributor

roomote bot commented Dec 2, 2025

Rooviewer Clock   See task on Roo Cloud

Review complete. The change adds defaultToolProtocol: "native" to the deepseek-reasoner model configuration, setting a sensible default for native tool calling in thinking mode. The change is type-safe, well-commented, and aligns with the DeepSeek API documentation.

Previous reviews

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

@wangxiaolong100 wangxiaolong100 changed the title feat(deepseek): support native tool calling for deepseek-reasoner feat(deepseek): support native tool calling for deepseek-reasoner V3.2 Dec 2, 2025
@hannesrudolph hannesrudolph added the Issue/PR - Triage New issue. Needs quick review to confirm validity and assign labels. label Dec 2, 2025
Co-authored-by: ellipsis-dev[bot] <65095814+ellipsis-dev[bot]@users.noreply.github.com>
Added defaultToolProtocol for DeepSeek R1 mode.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request 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.

[ENHANCEMENT] Add native tool calling support for DeepSeek Reasoner model

2 participants