mirror of
https://github.com/encounter/adk-python.git
synced 2026-07-09 18:19:28 -07:00
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:
committed by
Copybara-Service
parent
143ad44f8c
commit
82e6623fa9
@@ -69,6 +69,7 @@ class OpenAPIToolset(BaseToolset):
|
||||
auth_scheme: Optional[AuthScheme] = None,
|
||||
auth_credential: Optional[AuthCredential] = None,
|
||||
tool_filter: Optional[Union[ToolPredicate, List[str]]] = None,
|
||||
tool_name_prefix: Optional[str] = None,
|
||||
ssl_verify: Optional[Union[bool, str, ssl.SSLContext]] = None,
|
||||
):
|
||||
"""Initializes the OpenAPIToolset.
|
||||
@@ -104,6 +105,9 @@ class OpenAPIToolset(BaseToolset):
|
||||
``google.adk.tools.openapi_tool.auth.auth_helpers``
|
||||
tool_filter: The filter used to filter the tools in the toolset. It can be
|
||||
either a tool predicate or a list of tool names of the tools to expose.
|
||||
tool_name_prefix: The prefix to prepend to the names of the tools returned
|
||||
by the toolset. Useful when multiple OpenAPI specs have tools with
|
||||
similar names.
|
||||
ssl_verify: SSL certificate verification option for all tools. Can be:
|
||||
- None: Use default verification (True)
|
||||
- True: Verify SSL certificates using system CA
|
||||
@@ -113,7 +117,7 @@ class OpenAPIToolset(BaseToolset):
|
||||
This is useful for enterprise environments where requests go through
|
||||
a TLS-intercepting proxy with a custom CA certificate.
|
||||
"""
|
||||
super().__init__(tool_filter=tool_filter)
|
||||
super().__init__(tool_filter=tool_filter, tool_name_prefix=tool_name_prefix)
|
||||
if not spec_dict:
|
||||
spec_dict = self._load_spec(spec_str, spec_str_type)
|
||||
self._ssl_verify = ssl_verify
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user