Patch Changes
-
#454
29087adThanks @mchenco! - Fix three tool calling bugs that caused multi-turn agentic loops to fail1. Tool result output not unwrapped
convert-to-workersai-chat-messages.tswas callingJSON.stringify(toolResponse.output)on the entireLanguageModelV3ToolResultOutputwrapper object ({ type: 'text', value: '...' }), sending the wrapper as the tool message content instead of just the value. Models received garbled tool results and stopped after the first tool call instead of continuing.Fix: extract
output.valueand serialize only that.2.
toolChoice: "required"mapped to"any"instead of"required"utils.tsmappedtoolChoice: "required"totool_choice: "any". All vLLM-backed models (@cf/moonshotai/kimi-k2.5,@cf/meta/llama-4-scout-17b-16e-instruct,@cf/zai-org/glm-4.7-flash) return8001: Invalid inputfortool_choice: "any". The same incorrect mapping applied totoolChoice: { type: "tool" }.Fix: map both to
"required".3.
description: falsein tool definitionsutils.tsused&&short-circuit for tool description and parameters, which evaluates tofalse(notundefined) whentool.type !== "function". Sendingdescription: falseto the binding causes8001: Invalid input.Fix: use ternary to produce
undefinedwhen not applicable.Tested against
@cf/moonshotai/kimi-k2.5,@cf/meta/llama-4-scout-17b-16e-instruct, and@cf/zai-org/glm-4.7-flashvia the Workers AI binding.