fix(opencode): honor agent tool_choice config - #32521
Conversation
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
|
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 |
|
Flagging that this overlaps with #32518 — both apply the configured agent 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. |
|
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:
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. |
Issue for this PR
Closes #32465
Type of change
What does this PR do?
Setting
tool_choiceon an agent inopencode.jsonhad no effect — the key was accepted without error and silently dropped, so the provider always receivedtool_choice: "auto". For models that don't reliably emit tool calls underauto, that makes agentic runs impossible (the model never gets asked to commit to a tool call).The
llmlayer already plumbstoolChoiceend to end (session/llm.ts→ native request/runtime → per-provider lowering); the only missing link was config → request. The prompt builder hard-codedtoolChoicetoundefinedfor normal turns (it was only ever set to"required"forjson_schemaoutput).This wires the existing capability up:
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 intooptions,toolChoicefield to the loaded agent info and mapstool_choice→toolChoiceduring agent loading (next totemperature/top_p),toolChoicewhen building the request.json_schemaoutput still forces"required". Whentool_choiceis unset,toolChoicestaysundefinedand behavior is unchanged.How did you verify your code works?
Added a schema test asserting
tool_choiceis preserved as a top-level field (not moved intooptions) and that an unknown value is rejected. Existing agent-loading suite still passes.Screenshots / recordings
Not a UI change.
Checklist