fix: Add tool_name_prefix support to OpenAPIToolset

Fixes: https://github.com/google/adk-python/issues/3779

Co-authored-by: Xuan Yang <xygoogle@google.com>
PiperOrigin-RevId: 841850614
This commit is contained in:
Xuan Yang
2025-12-08 11:35:08 -08:00
committed by Copybara-Service
parent 143ad44f8c
commit 82e6623fa9
2 changed files with 26 additions and 1 deletions
@@ -169,3 +169,24 @@ def test_openapi_toolset_configure_verify_all(openapi_spec: Dict[str, Any]):
for tool in toolset._tools:
assert tool._ssl_verify == ca_bundle_path
async def test_openapi_toolset_tool_name_prefix(openapi_spec: Dict[str, Any]):
"""Test tool_name_prefix parameter prefixes tool names."""
prefix = "my_api"
toolset = OpenAPIToolset(spec_dict=openapi_spec, tool_name_prefix=prefix)
# Verify the toolset has the prefix set
assert toolset.tool_name_prefix == prefix
prefixed_tools = await toolset.get_tools_with_prefix()
assert len(prefixed_tools) == 5
# Verify all tool names are prefixed
for tool in prefixed_tools:
assert tool.name.startswith(f"{prefix}_")
# Verify specific tool name is prefixed
expected_prefixed_name = "my_api_calendar_calendars_insert"
prefixed_tool_names = [t.name for t in prefixed_tools]
assert expected_prefixed_name in prefixed_tool_names