Skip to content

fix: pass tool_choice through to binding.run()#429

Merged
threepointone merged 2 commits intocloudflare:mainfrom
michaeldwan:md/fix-tool-choice
Mar 9, 2026
Merged

fix: pass tool_choice through to binding.run()#429
threepointone merged 2 commits intocloudflare:mainfrom
michaeldwan:md/fix-tool-choice

Conversation

@michaeldwan
Copy link
Contributor

Summary

Closes #404

tool_choice was computed by prepareToolsAndToolChoice() but never included in the inputs passed to binding.run(), silently dropping it. Models that require an explicit tool_choice to call tools (e.g. mistral, granite, deepseek) would acknowledge tools in their text response but never actually invoke them.

Changes

  • Conditionally spread tool_choice into binding inputs when present
  • Set tool_choice: undefined in the JSON response format path where tools are suppressed
  • Added tests for "auto" and "required""any" mapping

tool_choice was computed by prepareToolsAndToolChoice() but never
included in the object returned by buildRunInputs(), silently dropping
it before reaching the model. This caused toolChoice options like
"required" to be ignored.
@changeset-bot
Copy link

changeset-bot bot commented Mar 2, 2026

🦋 Changeset detected

Latest commit: ae24f06

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
workers-ai-provider Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@michaeldwan michaeldwan marked this pull request as ready for review March 2, 2026 20:37
@pkg-pr-new
Copy link

pkg-pr-new bot commented Mar 9, 2026

Open in StackBlitz

npx https://pkg.pr.new/cloudflare/ai/ai-gateway-provider@429
npx https://pkg.pr.new/cloudflare/ai/@cloudflare/tanstack-ai@429
npx https://pkg.pr.new/cloudflare/ai/workers-ai-provider@429

commit: 9cb6269

@threepointone threepointone merged commit 48d8df8 into cloudflare:main Mar 9, 2026
2 checks passed
@github-actions github-actions bot mentioned this pull request Mar 9, 2026
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.

workers-ai-provider: tool_choice not forwarded to binding.run() inputs

2 participants