fix(gemini): preserve search tools when include_server_side_tool_invocations is set - #27600
Conversation
…cations is set Three independent code paths prevented the include_server_side_tool_invocations flag from reaching the search tool conflict resolver, causing googleSearch to be silently dropped when mixed with function tools: 1. Flag missing from DEFAULT_CHAT_COMPLETION_PARAM_VALUES -- get_non_default_params stripped it before any provider code ran. 2. GoogleAIStudioGeminiConfig.get_supported_openai_params did not list it -- with drop_params=True the flag was silently popped. 3. map_openai_params iterated tools before the flag handler, so _resolve_search_tool_conflict never saw the flag in optional_params. Fixes BerriAI#27479
|
@greptileai review |
Greptile SummaryThis PR fixes a silent tool-drop bug where
Confidence Score: 5/5Safe to merge — the changes are narrowly scoped to the flag propagation path and the pre-loop pre-set is a clean, non-breaking addition. All three root causes are correctly addressed, the fix is minimal and targeted, no existing test semantics were changed (only formatting), and the four new tests are pure unit tests that will catch regressions without any network dependency. No files require special attention; the pre-loop pre-set in vertex_and_google_ai_studio_gemini.py is the most behaviorally significant change and it reads cleanly.
|
| Filename | Overview |
|---|---|
| litellm/constants.py | Adds include_server_side_tool_invocations: None to DEFAULT_CHAT_COMPLETION_PARAM_VALUES so get_non_default_params no longer strips the flag before provider code runs. |
| litellm/llms/gemini/chat/transformation.py | Adds include_server_side_tool_invocations to GoogleAIStudioGeminiConfig.get_supported_openai_params so the flag survives _check_valid_arg when drop_params=True. |
| litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py | Pre-sets include_server_side_tool_invocations in optional_params before the iteration loop so _resolve_search_tool_conflict can read it when processing tools, fixing the ordering race; the loop also still writes it (harmless redundancy). |
| tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py | Adds four targeted regression tests for the three root causes; all are pure unit tests with no real network calls. Existing test changes are cosmetic formatting only. |
Reviews (1): Last reviewed commit: "fix(gemini): preserve search tools when ..." | Re-trigger Greptile
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Summary
Fixes #27479
When
include_server_side_tool_invocations=Trueis passed alongside mixed function + search tools (e.g.google_search+ a function tool), the search tool is silently dropped and the model answers from training data only. Three independent code paths compound to prevent the flag from reaching_resolve_search_tool_conflict:DEFAULT_CHAT_COMPLETION_PARAM_VALUES(constants.py) --include_server_side_tool_invocationswas not in the dict, soget_non_default_paramsstripped it before any provider code ran.GoogleAIStudioGeminiConfig.get_supported_openai_params-- the overridden method did not list the flag, so withdrop_params=Trueit was silently popped by_check_valid_arg.VertexGeminiConfig.map_openai_paramsiteration order -- thetoolsparam is iterated beforeinclude_server_side_tool_invocations, so_resolve_search_tool_conflictreads the flag fromoptional_paramsbefore the flag's handler has run.Changes
litellm/constants.py-- addinclude_server_side_tool_invocationstoDEFAULT_CHAT_COMPLETION_PARAM_VALUESlitellm/llms/gemini/chat/transformation.py-- addinclude_server_side_tool_invocationstoGoogleAIStudioGeminiConfig.get_supported_openai_paramslitellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py-- pre-set the flag inoptional_paramsbefore the iteration loop inmap_openai_paramsTest plan
test_search_tool_preserved_with_server_side_invocations-- verifies googleSearch is preserved when the flag is settest_search_tool_dropped_without_server_side_invocations-- confirms existing drop behavior without the flagtest_google_ai_studio_supports_server_side_invocations-- verifies the flag is in supported paramstest_flag_in_default_chat_completion_params-- verifies the flag survives get_non_default_params