Repository navigation
Conversation
3 tasks done
Contributor
|
Automated PR Cleanup Thank you for contributing to opencode. Due to the high volume of PRs from users and AI agents, we periodically close older PRs using automated criteria so maintainers can focus review time on the most active and community-supported contributions. This PR was closed because it matched the following cleanup criteria:
PRs created within the last month are not affected by this cleanup. If you believe this PR was closed incorrectly, or if you are still actively working on it, please leave a comment explaining why it should be reopened. A maintainer can review and reopen it if appropriate. Thanks again for taking the time to contribute. |
3 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Issue for this PR
None
What does this PR do?
This fixes SDK structured response support for DeepSeek v4 reasoning models. Those models do not support forcing tool calls with
tool_choice: "required".Previously, OpenCode always used forced tool calling for JSON schema output. That worked for many models, but DeepSeek reasoning models reject this parameter with an error like:
deepseek-reasoner does not support this tool_choiceType of change
Open Question
Since we changed the semantics from
requiredtoauto,should we detect and return an error when a structured response wasn't generated?UPDATE: We already do
opencode/packages/opencode/src/session/prompt.ts
Line 1451 in 7d5e91b
Naming
tool_choice_requiredmight be a bit confusing, however, if you read it as "capability" liketool_call,it could be fine.What Changed
Why
Some models have this capability shape:
That means:
Structured output uses a StructuredOutput tool. For these models, we now send the tool but use tool_choice: "auto" instead of tool_choice: "required".
Example
This SDK script proves the fix by using DeepSeek V4 Flash Free / Pro with JSON schema output:
Before this fix, the request could fail because OpenCode forced:
tool_choice: "required"After this fix, the request uses:
tool_choice: "auto"while still sending the StructuredOutput tool.
Before release
The models.dev metadata must be updated for affected DeepSeek reasoning models:
{ "tool_call": true, "tool_choice_required": false }Checklist
If you do not follow this template your PR will be automatically rejected.