ISSUE DESCRIPTION [Feature] Map thinkinglevel to DeepSeek thinking fields 🎯 The Goal /…
- User
ISSUE DESCRIPTION
[Feature] Map thinking_level to DeepSeek thinking fields
🎯 The Goal / Use Case
DeepSeek is currently treated as an OpenAI-compatible provider in PicoClaw, but its thinking-mode controls do not match the internal
thinking_levelabstraction 1:1.Please implement correct DeepSeek thinking mapping so that:
- explicit
thinking_level: "off"automatically disables DeepSeek thinking mode - thinking-enabled levels are translated to DeepSeek's documented OpenAI-compatible fields
- DeepSeek users can rely on the same
thinking_levelconfig without needing manualextra_bodyoverrides
💡 Proposed Solution
Add DeepSeek-specific request shaping on the OpenAI-compatible path.
Suggested mapping:
thinking_level: "off"->thinking: { "type": "disabled" }thinking_level: "high"->thinking: { "type": "enabled" }+reasoning_effort: "high"thinking_level: "xhigh"->thinking: { "type": "enabled" }+reasoning_effort: "max"
If
low/mediumare kept as valid internal levels, they can follow DeepSeek's documented compatibility behavior and map toreasoning_effort: "high".🛠 Potential Implementation (Optional)
PR #2898 already introduced explicit
thinking_level: "off"handling for several OpenAI-compatible providers and added provider-specific disable-field shaping.This issue is to extend that work for DeepSeek specifically:
- add DeepSeek request shaping on the OpenAI-compatible provider path
- map internal thinking levels to DeepSeek's
thinkingandreasoning_effortfields - ensure explicit
offis sent even when DeepSeek does not advertise generic thinking support viaSupportsThinking() - add tests covering both request shaping and fallback/rewrite paths if applicable
🚦 Impact & Roadmap Alignment
- This is a Core Feature
- This is a Nice-to-Have / Enhancement
- This aligns with the current Roadmap
🔄 Alternatives Considered
- explicit
Assistant
Let me analyze this issue. The goal is to implement DeepSeek-specific thinking level mapping in PicoClaw. I need to:
- First, explore the repository structure to understand the codebase
- Look at PR #2898's patterns for provider-specific request shaping
- Find where the OpenAI-compatible provider path handles thinking
- Add DeepSeek-specific mapping for thinking levels
Let me start by exploring the repository structure.
Assistant
The current directory is
/picoclawand the repository is in/picoclaw/picoclaw. Let me explore more.Assistant
The path
/picoclaw/picoclaw/pkg/providers/httpapi/doesn't exist. Let me find the correct path.Assistant
Good, the httpapi directory is at
/picoclaw/pkg/providers/httpapi. Let me explore the repository structure and the relevant files.Assistant
Now let me explore the openai_compat package:
Assistant
Let me look at the openai_compat provider.go file to understand how it handles thinking and how other providers are mapped.
Assistant
Let me see the rest of the file:
Assistant
The file is 819 lines but I only got about 500 lines. Let me see the rest, particularly the
applyThinkingControlfunction and other related parts.I can see the
applyThinkingControlfunction which currently handles:thinking_level: "off"mapping- Two kinds of thinking control:
"thinking_type"and"enable_thinking"
The current implementation only maps these two kinds for specific providers (volcengine, zhipu, zai, qwen, etc.). DeepSeek is not in any of these mappings.
I need to:
- Add DeepSeek-specific thinking control kind (probably
"thinking_type"since DeepSeek usesthinking.type) - Implement the full mapping for thinking levels including reasoning_effort
Let me see more of the file to understand the complete picture.
Assistant
Let me look at the test file to understand the testing patterns:
Assistant
Now I understand the code structure. Let me look at more of the test file to understand testing patterns and then look at how other providers configure thinking.
Key observations:
- The
applyThinkingControlfunction only handlesthinking_level: "off"case currently - The
thinkingControlKindfunction returns the kind of thinking control for different providers - For DeepSeek, I need to:
- Add
"deepseek"to the thinkingControlKind switch case to return"thinking_type"(since DeepSeek usesthinking.type) - Add a new method or extend
applyThinkingControlto handle non-off levels for DeepSeek withreasoning_effort
- Add
Let me look at the DeepSeek API docs reference:
thinking.type- enabled/disabledreasoning_effort- high/max
So for DeepSeek:
thinking_level: "off"->thinking: { "type": "disabled" }thinking_level: "high"-> +
- The
Assistant
Let me look at the existing test file more and also understand the full provider.go structure to plan the implementation.
Assistant
Now I have a good understanding of the codebase. Let me plan the implementation:
- The current
applyThinkingControlfunction only handlesthinking_level: "off"case - I need to extend it to also handle non-off levels for DeepSeek (mapping to
thinking.type+reasoning_effort) - I need to add
"deepseek"to thethinkingControlKindmethod
The implementation plan:
- Add
"deepseek"to thethinkingControlKindswitch case to return"thinking_type" - Extend
applyThinkingControlto handle non-off levels for DeepSeek - Add tests for DeepSeek thinking mapping
Let me also check how the
applyThinkingControlis called and how the full implementation should look. I'll need to:- Add a
deepseekThinkingReasoningEfforthelper method - Extend
applyThinkingControlto call a new method for DeepSeek when level is not "off"
Let me look at the full
applyThinkingControlandthinkingControlKindmethods again to plan precisely.- The current
Assistant
Now I have a complete understanding. Let me implement the solution:
Plan:
- Add an
isDeepSeekHosthelper function to detect DeepSeek API endpoints - Add DeepSeek detection in
applyThinkingControl - Map thinking levels to DeepSeek's
thinking.typeandreasoning_effortfields - Add tests
Let me first check the existing tests to understand patterns:
- Add an
Assistant
Now I have a clear understanding of the codebase. Let me implement the DeepSeek thinking mapping.
Plan:
- Add
isDeepSeekHosthelper function - Modify
applyThinkingControlto handle DeepSeek's thinking levels (both "off" and non-off levels) - For DeepSeek:
thinking_level: "off"->thinking: { "type": "disabled" }thinking_level: "high"->thinking: { "type": "enabled" }+reasoning_effort: "high"thinking_level: "xhigh"->thinking: { "type": "enabled" }+reasoning_effort: "max"thinking_level: "low"or"medium"->thinking: { "type": "enabled" }+reasoning_effort: "high"
- Add
Assistant
Now I understand the full structure. Let me implement the DeepSeek thinking mapping. I'll modify the
applyThinkingControlfunction to handle DeepSeek-specific logic.Assistant
Assistant
Let me look for where providers are created and configured in the codebase.
Assistant
Let me look at how DeepSeek providers are configured:
Assistant
Good, I can see that "deepseek" is one of the HTTP-based protocols. Let me see how it's configured.
Assistant
Let me check what the default API base is for DeepSeek and how SetProviderName is called for it.
Assistant
Let me look at the getDefaultAPIBase function to understand how DeepSeek is configured.
Assistant
Let me continue exploring how DeepSeek is configured in the factory_provider.go file, particularly looking at the provider configuration and how SetProviderName is called for the deepseek protocol.
Assistant
Let me find where SetProviderName is called for the HTTP-based providers in factory_provider.go.
Assistant
Assistant
Let me first verify my changes by reviewing the current state of the file and running tests.
Assistant
Assistant
Let me search for the function definitions to get their line numbers.
Assistant
There's already an
isDeepSeekHostfunction at line 311. Let me check what it looks like and the surrounding context.Assistant
There's already an
isDeepSeekHostfunction at line 311. Let me check the fullrequiresToolRoundReasoningReplayfunction:Assistant
There's already an
isDeepSeekHostfunction at line 311. I can see there's alsorequiresToolRoundReasoningReplay()which checks for DeepSeek at line 304. Let me also check if there's a helper to detect DeepSeek provider that I can reuse or create.Assistant
Now I have a complete understanding. There's already an
isDeepSeekHostfunction at line 311. I need to:- Modify
applyThinkingControl(line 205) to handle DeepSeek separately with full thinking level mapping - Add
isDeepSeekhelper method - Add
applyDeepSeekThinkingControlmethod
Let me first create a test script to reproduce the expected behavior, then implement the fix.
- Modify
Assistant
Let me fix the environment issue first, then run the tests.
Assistant
Now I'll implement the DeepSeek thinking mapping. I need to modify the
applyThinkingControlfunction to handle DeepSeek separately with full thinking level mapping, and add helper methods.Assistant
Now I'll implement the DeepSeek thinking mapping. I need to modify
applyThinkingControlto handle DeepSeek separately with full thinking level mapping, and add the helper methods.Assistant
Now I need to replace the existing
applyThinkingControlfunction in the provider.go file with the new implementation. Let me first check the exact line range.Assistant
Now I'll replace the existing
applyThinkingControlfunction with the new implementation that includes DeepSeek handling.Assistant
Now let me replace the old
applyThinkingControlfunction with the new implementation:Assistant
Let me verify the changes were applied correctly:
Assistant
The changes look correct. Now let me verify the code compiles and the existing tests still pass:
Assistant
The code compiles successfully. Now let me run the existing tests to verify I haven't broken anything:
Assistant
All existing tests pass. Now I need to add tests for the new DeepSeek thinking mapping functionality. Let me add comprehensive tests to the existing test file.
Assistant
Let me look at the existing tests more closely to understand the test patterns and then add my new tests.
Assistant
Now I'll add comprehensive tests for the DeepSeek thinking mapping. Let me find the right location to add them after the existing thinking tests.
Assistant
Let me add comprehensive tests for the DeepSeek thinking mapping. I'll insert them after the existing thinking tests:
Assistant
Now let me find the right line to insert these tests - right before the
TestProviderChat_ParsesToolCallsfunction:Assistant
I need to insert the new DeepSeek thinking tests at line 128 (before the
TestProviderChat_ParsesToolCallsfunction). Let me do this properly.Assistant
Now let me verify the tests were added correctly and run them:
Assistant
All 8 new DeepSeek tests pass. Now let me run all existing tests to make sure nothing is broken:
Assistant
All tests pass. Let me also run the httpapi package tests since that's where the HTTPProvider wraps the openai_compat provider:
Assistant
Let me also run the full test suite to make sure nothing else is broken:
Assistant
The failing test
TestShellTool_TimeoutKillsChildProcessis unrelated to my changes - it's a flaky shell process timeout test. Let me verify that all tests related to the openai_compat package pass (which is what I modified):Assistant
All provider tests pass. The failing test in
pkg/toolsis unrelated to my changes (it's a flaky shell process timeout test). Let me verify my changes one more time:Assistant
All tests pass. Let me verify the final state of the changes and submit.
Assistant
The implementation is complete. All tests pass and the changes are ready. Here's a summary of what was implemented:
Changes Made
1.
pkg/providers/openai_compat/provider.go- Modified
applyThinkingControl: Now handles DeepSeek separately with full thinking level mapping, while other providers continue to only handle the "off" case - Added
isDeepSeek()helper method: Detects DeepSeek providers by checking either the provider name or the API host - Added
applyDeepSeekThinkingControl()method: Implements the complete thinking level mapping for DeepSeek:thinking_level: "off"→thinking: { "type": "disabled" }thinking_level: "high"→thinking: { "type": "enabled" }+
- Modified
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.