fix(anthropic): send tool_choice none instead of stripping tools #12379
+17
−5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
toolChoiceis'none', sendtool_choice: { type: "none" }with the tools array preserved instead of stripping bothtoolsandtool_choicefrom the API request{ type: 'none' }to theAnthropicToolChoicetype unionProblem
When
toolChoiceis'none', the provider strips bothtoolsandtool_choicefrom the request:This causes the Anthropic API to return
content: [](empty response) when the conversation history containstool_use/tool_resultblocks, because it sees tool blocks in history but notoolsparameter.This is a common issue in agentic loops where the last step needs to force a text-only response — the model produces zero text instead of a summary.
Anthropic API support
The comment "Anthropic does not support 'none' tool choice" is outdated. The Anthropic API officially supports
tool_choice: { type: "none" }— it's listed in the tool use pricing table for every model from Claude 3 through Claude Opus 4.6:The docs also note: "If no tools are provided, then a tool choice of none uses 0 additional system prompt tokens."
Fixes #12378
Test plan
should handle tool choice "none"test to verify tools and toolChoice are preservedprepareToolstests pass