Skip to content

fix(opencode): honor agent tool_choice config - #32521

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

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.

@ozpool

ozpool commented Jun 24, 2026

Copy link
Copy Markdown
Author

Flagging that this overlaps with #32518 — both apply the configured agent tool_choice to model requests, opened the same day (the bot flagged them as duplicates).

Mine is the smaller diff (+24/-1: the v1 config + agent + prompt path, with a config-level test); #32518 is broader (+48/-1) and also updates the agents docs. Happy to defer to whichever you'd prefer — if you'd rather take #32518 I'll close this out, or I can fold the docs update into this one if you'd prefer the smaller change. Whatever's easiest on your side.

@github-actions

Copy link
Copy Markdown
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:

  • The PR was created more than 1 month ago
  • The PR had fewer than 2 positive reactions
  • Positive reactions are counted as thumbs-up, heart, celebration, or rocket reactions on the PR

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.

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

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