Repository navigation
fix(models): honor a single allowed_function_names entry in LiteLlm tool_choice - #8445
Open
abhishekacharya200 wants to merge 1 commit into
Open
abhishekacharya200 wants to merge 1 commit into
abhishekacharya200 wants to merge 1 commit into
Conversation
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.
Please ensure you have read the contribution guide before creating a pull request.
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:
Describe the bug
With
FunctionCallingConfig(mode=ANY, allowed_function_names=["some_tool"]),LiteLlmalways sendstool_choice="required"and drops the allowed name. The model is then free to call any declared tool instead of the one requested.AnthropicLlmalready maps a single allowed name to a forced tool, andForceEscalationPluginrelies on this behavior to force one specific tool.To Reproduce
LlmRequestwith two declared functions andtool_configset toFunctionCallingConfig(mode=ANY, allowed_function_names=["my_func"])._get_completion_inputs(llm_request, model="openai/gpt-4o").tool_choiceis"required".Expected behavior
tool_choiceshould be{"type": "function", "function": {"name": "my_func"}}so the provider is forced to call that tool.Solution:
In the ANY branch of
_get_completion_inputs, when exactly one allowed name is given and it matches a declared tool, send the function styletool_choicefor that name. With several names, an unknown name, or no names, it still sends"required". The no tools handling is unchanged.Testing Plan
Unit Tests:
Added two tests in
tests/unittests/models/test_litellm.py: a single allowed name gives the forced functiontool_choice, and two allowed names give"required". The single name test fails on main (assert 'required' == {'type': 'function', ...}) and passes with the fix.The 2 failures are
test_get_completion_inputs_ignores_unsupported_reasoning_params(minimax and bedrock cases), which fail the same way on main with my installed litellm version and are unrelated.Manual End-to-End (E2E) Tests:
I did not run it against a live model. I called
_get_completion_inputswith the request from the steps above: before the change it returned"required", after it returns{"type": "function", "function": {"name": "my_func"}}.Checklist