Skip to content

fix: resolve #746#748

Merged
bSi (brunusansi) merged 2 commits intodevfrom
agent-fix/issue-746
Feb 26, 2026
Merged

fix: resolve #746#748
bSi (brunusansi) merged 2 commits intodevfrom
agent-fix/issue-746

Conversation

@lightweight-agent
Copy link

Issue for this PR

Closes #746

Type of change

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

What does this PR do?

Fix tool_choice: 'required' incompatibility with thinking-enabled Anthropic models when using structured output.

When structured output (json_schema format) is requested, the system sets toolChoice: 'required', which the AI SDK maps to tool_choice: { type: 'any' } in Anthropic's API. Anthropic prohibits this when extended thinking is enabled, only allowing 'auto' or a specific tool by name. The fix intercepts toolChoice in llm.ts before sending to streamText() and rewrites 'required' to { type: 'tool', toolName: 'StructuredOutput' } for Anthropic-backed providers with thinking enabled, preserving the structured output guarantee while satisfying the API constraint.

How did you verify your code works?

  • ✅ Research analyzed (Gemini 3.1 Pro)
  • ✅ Plan generated (Sonnet 4.6)
  • ✅ Fix implemented (Opus 4.6)
  • ✅ TypeScript type-checking passed (post-patch)
  • ✅ Quick validation passed (GPT-5.3 Codex)
  • ✅ Changes are minimal and focused
  • ✅ Self-review passed (Opus 4.6 Fast)

Changed files

packages/opencode/src/session/llm.ts | 52 +++++++++++++++++++++++++++++++++++-
 1 file changed, 51 insertions(+), 1 deletion(-)

Checklist

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

Generated by Lightweight Agent — 5-model team: Gemini 3.1 Pro → Sonnet 4.6 → Opus 4.6 → GPT-5.3 Codex → Opus 4.6 Fast

@lightweight-agent lightweight-agent bot added the automated Created by automation label Feb 26, 2026
@github-actions
Copy link

The following comment was made by an LLM, it may be inaccurate:

Copy link
Member

@brunusansi bSi (brunusansi) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved: bot PR passed all checks.

@brunusansi bSi (brunusansi) merged commit f457791 into dev Feb 26, 2026
11 of 12 checks passed
@brunusansi bSi (brunusansi) deleted the agent-fix/issue-746 branch February 26, 2026 15:31
Copy link
Member

@brunusansi bSi (brunusansi) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Auto-approved: bot PR passed all checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automated Created by automation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Upstream #15226] tool_choice: 'required' incompatible with thinking-enabled models when using structured output

1 participant