Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/google/adk/agents/llm_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,17 @@ async def _convert_tool_union_to_tools(
# other tools.
# TODO: Remove once the workaround is no longer needed.
if multiple_tools and isinstance(tool_union, VertexAiSearchTool):
from ..tools.discovery_engine_search_tool import DiscoveryEngineSearchTool

vais_tool = tool_union
if vais_tool.bypass_multi_tools_limit:
try:
from ..tools.discovery_engine_search_tool import DiscoveryEngineSearchTool
except ImportError as e:
raise ImportError(
'VertexAiSearchTool with bypass_multi_tools_limit=True requires'
' the google-cloud-discoveryengine package. Install it with'
' `pip install google-adk[gcp]`.'
) from e

return [
DiscoveryEngineSearchTool(
data_store_id=vais_tool.data_store_id,
Expand Down
22 changes: 22 additions & 0 deletions tests/unittests/agents/test_llm_agent_fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,6 +595,28 @@ async def test_handle_vais_with_other_tools(self):
assert tools[1].name == 'discovery_engine_search'
assert tools[1].__class__.__name__ == 'DiscoveryEngineSearchTool'

async def test_handle_vais_with_other_tools_missing_gcp_extra(self):
"""Missing google-cloud-discoveryengine raises an actionable error."""
agent = LlmAgent(
name='test_agent',
model='gemini-pro',
tools=[
self._my_tool,
VertexAiSearchTool(
data_store_id='test_data_store_id',
bypass_multi_tools_limit=True,
),
],
)
ctx = await _create_readonly_context(agent)

with mock.patch.dict(
'sys.modules',
{'google.adk.tools.discovery_engine_search_tool': None},
):
with pytest.raises(ImportError, match='google-adk\\[gcp\\]'):
await agent.canonical_tools(ctx)

async def test_handle_vais_with_other_tools_no_bypass(self):
"""Test that VertexAiSearchTool is not replaced."""
agent = LlmAgent(
Expand Down