Skip to content

fix(gemini): preserve search tools when include_server_side_tool_invocations is set - #27600

Closed
Jwrede wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/gemini-grounding-search-tool-drop
Closed

fix(gemini): preserve search tools when include_server_side_tool_invocations is set#27600
Jwrede wants to merge 1 commit into
BerriAI:litellm_internal_stagingfrom
Jwrede:fix/gemini-grounding-search-tool-drop

Conversation

@Jwrede

@Jwrede Jwrede commented May 10, 2026

Copy link
Copy Markdown

Summary

Fixes #27479

When include_server_side_tool_invocations=True is 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:

  1. DEFAULT_CHAT_COMPLETION_PARAM_VALUES (constants.py) -- include_server_side_tool_invocations was not in the dict, so get_non_default_params stripped it before any provider code ran.

  2. GoogleAIStudioGeminiConfig.get_supported_openai_params -- the overridden method did not list the flag, so with drop_params=True it was silently popped by _check_valid_arg.

  3. VertexGeminiConfig.map_openai_params iteration order -- the tools param is iterated before include_server_side_tool_invocations, so _resolve_search_tool_conflict reads the flag from optional_params before the flag's handler has run.

Changes

  • litellm/constants.py -- add include_server_side_tool_invocations to DEFAULT_CHAT_COMPLETION_PARAM_VALUES
  • litellm/llms/gemini/chat/transformation.py -- add include_server_side_tool_invocations to GoogleAIStudioGeminiConfig.get_supported_openai_params
  • litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py -- pre-set the flag in optional_params before the iteration loop in map_openai_params

Test plan

  • test_search_tool_preserved_with_server_side_invocations -- verifies googleSearch is preserved when the flag is set
  • test_search_tool_dropped_without_server_side_invocations -- confirms existing drop behavior without the flag
  • test_google_ai_studio_supports_server_side_invocations -- verifies the flag is in supported params
  • test_flag_in_default_chat_completion_params -- verifies the flag survives get_non_default_params

…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
@Jwrede

Jwrede commented May 10, 2026

Copy link
Copy Markdown
Author

@greptileai review

@greptile-apps

greptile-apps Bot commented May 10, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a silent tool-drop bug where include_server_side_tool_invocations=True had no effect when mixed function + search tools were passed to Gemini, because three independent code paths each stripped or ignored the flag before it could reach _resolve_search_tool_conflict.

  • constants.py: Registers the flag in DEFAULT_CHAT_COMPLETION_PARAM_VALUES (default None) so get_non_default_params stops treating a user-supplied True as the default and dropping it.
  • transformation.py: Adds the flag to GoogleAIStudioGeminiConfig.get_supported_openai_params so it is not silently popped by _check_valid_arg when drop_params=True.
  • vertex_and_google_ai_studio_gemini.py: Pre-sets the flag into optional_params before the map_openai_params iteration loop begins, ensuring _resolve_search_tool_conflict sees the flag when the tools key is processed earlier in the loop; four regression tests are added covering each root cause.

Confidence Score: 5/5

Safe 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.

Important Files Changed

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

codecov Bot commented May 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Gemini grounding silently disabled when web_grounding tools are mixed with function tools (3 compounding failures)

3 participants