From 95f0fcd2048eec3fee6acce3da7eb518be94ab51 Mon Sep 17 00:00:00 2001 From: LeVDuan Date: Thu, 9 Apr 2026 17:24:53 +0900 Subject: [PATCH] fix: skip dropping search tools when server-side tool invocations enabled (Gemini 3+) --- .../vertex_and_google_ai_studio_gemini.py | 7 ++++- ...test_vertex_and_google_ai_studio_gemini.py | 29 +++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py index d4d8124af40..6cd3aceb079 100644 --- a/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py +++ b/litellm/llms/vertex_ai/gemini/vertex_and_google_ai_studio_gemini.py @@ -650,7 +650,12 @@ class VertexGeminiConfig(VertexAIBaseConfig, BaseConfig): urlContext, ] ) - if gtool_func_declarations and has_search_tools: + # Skip this check when include_server_side_tool_invocations is enabled + # (Gemini 3+ supports tool combination natively via PR #24073). + server_side_tool_invocations = optional_params.get( + "include_server_side_tool_invocations", False + ) + if gtool_func_declarations and has_search_tools and not server_side_tool_invocations: verbose_logger.warning( "Vertex AI does not support mixing function declarations with " "search tools (googleSearch, enterpriseWebSearch, urlContext, " diff --git a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py index 873f99d031a..2e719b212f7 100644 --- a/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py +++ b/tests/test_litellm/llms/vertex_ai/gemini/test_vertex_and_google_ai_studio_gemini.py @@ -2867,6 +2867,35 @@ def test_vertex_ai_function_tools_with_code_execution_preserved(): assert "code_execution" in tool_keys +def test_vertex_ai_gemini3_tool_combination_no_drop(): + """ + Test that search tools are NOT dropped when include_server_side_tool_invocations + is enabled (Gemini 3+ tool combination). + """ + v = VertexGeminiConfig() + optional_params = {"include_server_side_tool_invocations": True} + + tools = v._map_function( + value=[ + {"enterpriseWebSearch": {}}, + {"urlContext": {}}, + { + "type": "function", + "function": {"name": "my_func", "description": "A function"}, + }, + ], + optional_params=optional_params, + ) + + tool_keys = set() + for t in tools: + tool_keys.update(t.keys()) + assert "function_declarations" in tool_keys + assert "enterpriseWebSearch" in tool_keys + assert "url_context" in tool_keys + assert len(tools) == 3 + + def test_vertex_ai_openai_web_search_tool_transformation(): """ Test that OpenAI-style web_search and web_search_preview tools are transformed to googleSearch.