fix(opencode): honor agent tool_choice config#32521
Open
ozpool wants to merge 1 commit into
Open
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
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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