fix: Parallelize tool resolution in LlmAgent.canonical_tools()

Previously we resolved tools sequentially by awaiting _convert_tool_union_to_tools() in a loop -- reduce the latency by resolving tools concurrently.

Co-authored-by: Kathy Wu <wukathy@google.com>
PiperOrigin-RevId: 872979105
This commit is contained in:
Kathy Wu
2026-02-20 10:45:18 -08:00
committed by Copybara-Service
parent bef3f117b4
commit 7478bdaa98
2 changed files with 33 additions and 8 deletions
@@ -451,6 +451,27 @@ class TestCanonicalTools:
assert tools[0].name == 'vertex_ai_search'
assert tools[0].__class__.__name__ == 'VertexAiSearchTool'
async def test_multiple_tools_resolution(self):
"""Test that multiple tools are resolved correctly."""
def _tool_1():
pass
def _tool_2():
pass
agent = LlmAgent(
name='test_agent',
model='gemini-pro',
tools=[_tool_1, _tool_2],
)
ctx = await _create_readonly_context(agent)
tools = await agent.canonical_tools(ctx)
assert len(tools) == 2
assert tools[0].name == '_tool_1'
assert tools[1].name == '_tool_2'
# Tests for multi-provider model support via string model names
@pytest.mark.parametrize(