fix(session): don't force tool_choice required for reasoning models - #2069
Open
anandlo wants to merge 1 commit into
Open
fix(session): don't force tool_choice required for reasoning models#2069anandlo wants to merge 1 commit into
anandlo wants to merge 1 commit into
Conversation
Structured-output steps (json_schema format) forced toolChoice: "required",
which DeepSeek and other thinking-mode providers reject with HTTP 400
("Thinking mode does not support this tool_choice"). Reasoning-capable
models now use the provider default tool choice; the StructuredOutput tool
plus autoRetry still drive extraction. Non-reasoning models keep the forced
"required" behavior.
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
Closes #2068
Type of change
What does this PR do?
When a prompt runs with
format: {type: "json_schema", ...}(used by workflowagent(prompt, {schema})),session/prompt.tsforcedtoolChoice: "required". Providers running the model in thinking mode (DeepSeek withreasoning: true) rejecttool_choice: "required"with HTTP 400Thinking mode does not support this tool_choice, which fails schema'd workflow steps (reproduced live: deep-research Plan and Review steps).The fix guards the forced
"required"with!model.capabilities.reasoningat both toolChoice sites (fork path and main loop). Reasoning models get the provider default tool choice; structured extraction still works because the StructuredOutput tool remains registered, the system prompt still directs the model to use it, and the existing structured-output autoRetry path covers cases where the model returns prose. Non-reasoning models keep the deterministic forced behavior.How did you verify your code works?
test/session/tool-choice-thinking.test.ts(scripted LLM server, wire-leveltool_choicecapture): thinking model must NOT receivetool_choice: "required", plain model must keep it. Confirmed RED before the fix, GREEN after.structured-output-retry,structured-output,structured-output-integration).bun typecheckclean frompackages/opencode.deepseek-v4-flash, thinking enabled,json_schemaformat): without the change the call fails with HTTP 400Thinking mode does not support this tool_choice; with the change it returns structured output.Screenshots / recordings
If this is a UI change, please include a screenshot or recording. (Not a UI change.)
Checklist