Package: workers-ai-provider v3.1.1
Bug
getArgs() correctly computes tool_choice via prepareToolsAndToolChoice(), but buildRunInputs() only forwards specific fields - silently dropping tool_choice:
// buildRunInputs returns:
{
max_tokens: args.max_tokens,
messages: finalMessages,
temperature: args.temperature,
tools: args.tools, // included
top_p: args.top_p,
// tool_choice: args.tool_choice <- MISSING
}
Impact
Models that require explicit tool_choice: "auto" to call tools (e.g. @cf/mistralai/mistral-small-3.1-24b-instruct) silently skip tool calls - the model acknowledges it should use tools in its text response but never calls them. @cf/zai-org/glm-4.7-flash was unaffected because it defaults to using tools when provided.
Workaround
Shim the binding to inject tool_choice: "auto" when tools are present:
const shimmedBinding = {
run: (model, inputs, options) =>
env.AI.run(model, inputs?.tools ? { ...inputs, tool_choice: "auto" } : inputs, options)
};
const provider = createWorkersAI({ binding: shimmedBinding });
Fix
One line in buildRunInputs in workersai-chat-language-model.ts:
tools: args.tools,
tool_choice: args.tool_choice, // add this