Skip to content

fix(session): don't force tool_choice required for reasoning models - #2069

Open
anandlo wants to merge 1 commit into
XiaomiMiMo:mainfrom
anandlo:fix/tool-choice-thinking-mode
Open

fix(session): don't force tool_choice required for reasoning models#2069
anandlo wants to merge 1 commit into
XiaomiMiMo:mainfrom
anandlo:fix/tool-choice-thinking-mode

Conversation

@anandlo

@anandlo anandlo commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Issue for this PR

Closes #2068

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

When a prompt runs with format: {type: "json_schema", ...} (used by workflow agent(prompt, {schema})), session/prompt.ts forced toolChoice: "required". Providers running the model in thinking mode (DeepSeek with reasoning: true) reject tool_choice: "required" with HTTP 400 Thinking 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.reasoning at 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?

  • New integration test test/session/tool-choice-thinking.test.ts (scripted LLM server, wire-level tool_choice capture): thinking model must NOT receive tool_choice: "required", plain model must keep it. Confirmed RED before the fix, GREEN after.
  • Existing structured-output suites still pass (structured-output-retry, structured-output, structured-output-integration).
  • bun typecheck clean from packages/opencode.
  • Live A/B against DeepSeek API (deepseek-v4-flash, thinking enabled, json_schema format): without the change the call fails with HTTP 400 Thinking 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

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

structured output tool_choice "required" breaks thinking-mode models (DeepSeek 400)

1 participant