feat: Add bypass_multi_tools_limit option to GoogleSearchTool and VertexAiSearchTool

PiperOrigin-RevId: 817493869
This commit is contained in:
Xuan Yang
2025-10-09 23:05:02 -07:00
committed by Copybara-Service
parent 64646e0002
commit 9a6b8507f0
4 changed files with 74 additions and 15 deletions
@@ -26,6 +26,7 @@ from google.adk.models.llm_request import LlmRequest
from google.adk.models.registry import LLMRegistry
from google.adk.sessions.in_memory_session_service import InMemorySessionService
from google.adk.tools.google_search_tool import google_search
from google.adk.tools.google_search_tool import GoogleSearchTool
from google.adk.tools.vertex_ai_search_tool import VertexAiSearchTool
from google.genai import types
from pydantic import BaseModel
@@ -310,6 +311,25 @@ class TestCanonicalTools:
assert tools[1].name == 'google_search_agent'
assert tools[1].__class__.__name__ == 'GoogleSearchAgentTool'
async def test_handle_google_search_with_other_tools_no_bypass(self):
"""Test that google_search is not wrapped into an agent."""
agent = LlmAgent(
name='test_agent',
model='gemini-pro',
tools=[
self._my_tool,
GoogleSearchTool(bypass_multi_tools_limit=False),
],
)
ctx = await _create_readonly_context(agent)
tools = await agent.canonical_tools(ctx)
assert len(tools) == 2
assert tools[0].name == '_my_tool'
assert tools[0].__class__.__name__ == 'FunctionTool'
assert tools[1].name == 'google_search'
assert tools[1].__class__.__name__ == 'GoogleSearchTool'
async def test_handle_google_search_only(self):
"""Test that google_search is not wrapped into an agent."""
agent = LlmAgent(
@@ -346,8 +366,8 @@ class TestCanonicalTools:
'google.auth.default',
mock.MagicMock(return_value=('credentials', 'project')),
)
async def test_handle_google_vais_with_other_tools(self):
"""Test that VertexAiSearchTool is wrapped into an agent."""
async def test_handle_vais_with_other_tools(self):
"""Test that VertexAiSearchTool is replaced with Discovery Engine Search."""
agent = LlmAgent(
name='test_agent',
model='gemini-pro',
@@ -365,6 +385,28 @@ class TestCanonicalTools:
assert tools[1].name == 'discovery_engine_search'
assert tools[1].__class__.__name__ == 'DiscoveryEngineSearchTool'
async def test_handle_vais_with_other_tools_no_bypass(self):
"""Test that VertexAiSearchTool is not replaced."""
agent = LlmAgent(
name='test_agent',
model='gemini-pro',
tools=[
self._my_tool,
VertexAiSearchTool(
data_store_id='test_data_store_id',
bypass_multi_tools_limit=False,
),
],
)
ctx = await _create_readonly_context(agent)
tools = await agent.canonical_tools(ctx)
assert len(tools) == 2
assert tools[0].name == '_my_tool'
assert tools[0].__class__.__name__ == 'FunctionTool'
assert tools[1].name == 'vertex_ai_search'
assert tools[1].__class__.__name__ == 'VertexAiSearchTool'
async def test_handle_vais_only(self):
"""Test that VertexAiSearchTool is not wrapped into an agent."""
agent = LlmAgent(