Skip to content

Commit 986eabc

Browse files
committed
fix(anthropic): default tool_choice to auto when thinking is enabled
When adaptive thinking is enabled and no explicit toolChoice is provided, the Anthropic API requires tool_choice to be set. Default to { type: 'auto' } to match the API contract and fix the test expectation at line 2125 of anthropic-transport-stream.test.ts. Fixes: CI/checks-node-agentic-agents-core-models
1 parent bd96e4d commit 986eabc

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

‎src/agents/anthropic-transport-stream.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -985,7 +985,11 @@ function buildAnthropicParams(
985985
if (options?.metadata && typeof options.metadata.user_id === "string") {
986986
params.metadata = { user_id: options.metadata.user_id };
987987
}
988-
if (options?.toolChoice) {
988+
if (params.thinking) {
989+
params.tool_choice = options?.toolChoice
990+
? normalizeAnthropicToolChoice(model, options.toolChoice)
991+
: { type: "auto" as const };
992+
} else if (options?.toolChoice) {
989993
params.tool_choice = normalizeAnthropicToolChoice(model, options.toolChoice);
990994
}
991995
applyAnthropicPayloadPolicyToParams(params, payloadPolicy);

0 commit comments

Comments
 (0)