fix(litellm): collect all tools so native tools aren't dropped#6416
Closed
vup903 wants to merge 2 commits into
Closed
fix(litellm): collect all tools so native tools aren't dropped#6416vup903 wants to merge 2 commits into
vup903 wants to merge 2 commits into
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
_get_completion_inputs only converted tools[0].function_declarations, so Tools carrying only native/built-in tools (e.g. google_search) produced tools=None and any Tool past index 0 was ignored entirely. Loop over all config.tools instead: convert function declarations as before and serialize native tools via model_dump(by_alias=True, exclude_none=True) into the same list. Apply the same fix to the tools[0]-only slice in _build_request_log. Fixes google#6091
Collaborator
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):
Problem:
When ADK's
LiteLlmintegration is used through a proxy gateway, native/built-in tools (tools withoutfunction_declarations, e.g.google_search) are silently dropped and never reach the gateway._get_completion_inputsgated all tool conversion onllm_request.config.tools[0].function_declarations, so:Toolcarrying only native tools producedtools=None(the reported bug), andToolpast index 0 was ignored entirely — the list comprehension only ever touchedtools[0], which is the underlying root cause; native-tool dropping is the most common way people hit it.Solution:
Loop over all
llm_request.config.toolsinstead of only index 0: convertfunction_declarationsthrough the existing_function_declaration_to_tool_parampath, and serialize native tools viamodel_dump(by_alias=True, exclude_none=True)into the same combined list. Function and native tools are always sent together; ADK does not pre-emptively guess provider support, so an unsupported schema is rejected by the provider/proxy like any other unsupported parameter (per maintainer guidance on the issue).The identical
tools[0]-only slice in_build_request_logis fixed the same way for consistency (debug-log only; does not change what is sent).Testing Plan
Unit Tests:
Added to
tests/unittests/models/test_litellm.py:test_get_completion_inputs_serializes_native_only_tool— a native-onlyToolis serialized instead of dropped.test_get_completion_inputs_mixed_native_and_function_tools— both a native tool and a function tool reach the request.test_get_completion_inputs_collects_tools_beyond_index_zero— function tools onconfig.tools[1:]are no longer ignored.test_get_completion_inputs_no_tools_returns_none— regression: no tools still yieldstools=None.Manual End-to-End (E2E) Tests:
For the OpenAI path I ran ADK's
LiteLlmagainst a locallitellm proxyand confirmed native tools now appear in the outgoing request body (before this change the body carried no tools). I don't have a Vertex AI environment, so the Vertex-via-proxy path is covered here by wire-shape assertions against a mocked OpenAI-compatible backend — a check on a real Vertex proxy during review would be appreciated (@surajksharma07 offered a second pair of eyes on the Vertex-side wire shape).Checklist