feat: OPENCODE_TOOL_CHOICE=required for agent tool binding - #14
Conversation
Local models often answer with prose/JSON instead of MCP tool invocations. When OPENCODE_TOOL_CHOICE=required (or VERDICT_FORCE_TOOL_CHOICE=1), non-final session runner steps send tool_choice: required. Final max-steps exit still uses none.
|
This PR doesn't fully meet our contributing guidelines and PR template. What needs to be fixed:
Please edit this PR description to address the above within 2 hours, or it will be automatically closed. If you believe this was flagged incorrectly, please let a maintainer know. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9380c82dda
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| : Flag.OPENCODE_TOOL_CHOICE === "required" | ||
| ? "required" |
There was a problem hiding this comment.
Preserve a final turn when forcing tool choice
When OPENCODE_TOOL_CHOICE=required or VERDICT_FORCE_TOOL_CHOICE=1 is set for an agent without a configured steps limit (the built-in build agent leaves steps unset), isLastStep never becomes true, so every provider turn is sent with toolChoice: "required". Any local tool call then sets needsContinuation and the runner starts another turn that again cannot produce a final text answer, causing default sessions to keep issuing tools until an error/context limit instead of settling. Only force required when there is a finite final step or otherwise disable it after tool settlement.
Useful? React with 👍 / 👎.
Summary
OPENCODE_TOOL_CHOICE=required/VERDICT_FORCE_TOOL_CHOICE=1forces OpenAI-compatibletool_choice: requiredon non-final agent steps.Evidence (operator host)
Test plan
bun test packages/core/test/tool-choice-flag.test.ts