Repository navigation
fix(models): honor tool_config function calling mode in AnthropicLlm - #7634
Open
Somay-kousis wants to merge 1 commit into
Open
Somay-kousis wants to merge 1 commit into
Somay-kousis wants to merge 1 commit into
Conversation
AnthropicLlm always sent tool_choice auto, so a FunctionCallingConfig mode of NONE or ANY (or ANY with one allowed function name) set in generate_content_config.tool_config never reached Claude. Map the mode to Claude's none, any and tool choices. A forced choice falls back to auto while extended thinking is on, since Claude rejects forced tool use there.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
2. Or, if no issue exists, describe the change:
Problem:
AnthropicLlmalways senttool_choiceauto, so the function calling mode ingenerate_content_config.tool_confignever reached Claude.NONEdid not stop tool calls,ANYdid not force one, and themodel_consultforce plugin (ANYwith one allowed name) had no effect on Claude.Solution:
AnthropicLlmnow mapsconfig.tool_config.function_calling_configto Claude'stool_choice:NONE{"type": "none"}ANYwith oneallowed_function_namesentry{"type": "tool", "name": ...}ANYotherwise{"type": "any"}AUTO,VALIDATED, unset, no config{"type": "auto"}(unchanged)Two limits come from the Anthropic API:
anyortool) while extended thinking is on. In that caseANYfalls back toautowith a warning, the same way the existing output-schema tool falls back.NONEis kept, since Claude accepts it with thinking.any.integrations/openai/_openai_common.pyhandles the same case this way.Requests with no tools still send no
tool_choice. The output-schema path, which sets its own choice, is unchanged.Testing Plan
Unit Tests:
New tests in
tests/unittests/models/test_anthropic_llm.py:test_tool_config_mode_reaches_claude_tool_choice: every mode, streaming and non-streaming.test_forced_tool_choice_with_thinking_falls_back_to_auto:ANYandANYwith one name, with a manual budget and with adaptive thinking.test_tool_config_none_mode_is_kept_with_thinking.The 10 new cases that pass on main are the ones where
autois correct. Three mutations of the fix (NONEback toauto, single-name branch disabled, thinking fallback removed) each make at least 3 tests fail.tests/unittests/modelsandtests/unittests/flowspass (2814 tests). isort, pyink and mypy are clean on the changed file.Manual End-to-End (E2E) Tests:
The repro in the issue (
Agent+InMemoryRunner,AsyncMessages.createfaked to record the request):No live Claude call; the thinking limits come from Anthropic's tool use docs and the fallback this file already has.
Checklist
Additional context
LiteLlmalso ignores a single allowed function name (ANYalways becomes"required",lite_llm.py:3645-3654). Not changed here.