Skip to content

fix(opencode): honor agent tool_choice config#32521

Open
ozpool wants to merge 1 commit into
anomalyco:devfrom
ozpool:agent-tool-choice
Open

fix(opencode): honor agent tool_choice config#32521
ozpool wants to merge 1 commit into
anomalyco:devfrom
ozpool:agent-tool-choice

Conversation

@ozpool

@ozpool ozpool commented Jun 16, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #32465

Type of change

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

What does this PR do?

Setting tool_choice on an agent in opencode.json had no effect — the key was accepted without error and silently dropped, so the provider always received tool_choice: "auto". For models that don't reliably emit tool calls under auto, that makes agentic runs impossible (the model never gets asked to commit to a tool call).

The llm layer already plumbs toolChoice end to end (session/llm.ts → native request/runtime → per-provider lowering); the only missing link was config → request. The prompt builder hard-coded toolChoice to undefined for normal turns (it was only ever set to "required" for json_schema output).

This wires the existing capability up:

  • adds tool_choice ("auto" | "required" | "none") to the agent config schema and registers it as a known key so it stays a top-level field instead of being swept into options,
  • adds the matching toolChoice field to the loaded agent info and maps tool_choicetoolChoice during agent loading (next to temperature / top_p),
  • uses the agent's configured toolChoice when building the request.

json_schema output still forces "required". When tool_choice is unset, toolChoice stays undefined and behavior is unchanged.

How did you verify your code works?

Added a schema test asserting tool_choice is preserved as a top-level field (not moved into options) and that an unknown value is rejected. Existing agent-loading suite still passes.

bun test packages/core/test/config/agent-v1.test.ts   # 2 pass
bun test packages/opencode/test/agent/agent.test.ts    # 43 pass
bun run typecheck                                      # clean (core + opencode)

Screenshots / recordings

Not a UI change.

Checklist

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

An agent's tool_choice in opencode.json was accepted but silently
dropped: the prompt builder always passed toolChoice undefined (except
for json_schema output), so the provider always received the default
auto. The llm layer already supports toolChoice end to end; only the
config-to-request link was missing.

Add tool_choice to the agent config schema and the loaded agent info,
map it through agent loading, and use it when building the request.
json_schema output still forces required.

Closes anomalyco#32465
@github-actions

Copy link
Copy Markdown
Contributor

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

Potential Duplicate Found:

Why it's related: PR #32518 addresses the exact same issue—applying configured tool_choice to model requests. Both PRs appear to solve the problem of honoring tool_choice settings from agent config in opencode.json. This is likely a duplicate or overlapping fix for issue #32465.

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.

opencode Agent config is silently ignored — opencode always sends (1.17.7)

1 participant