Skip to content

Commit 98ccc29

Browse files
authored
Merge branch 'main' into feat/s3-artifact
2 parents 11275bf + 82e6623 commit 98ccc29

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

src/google/adk/tools/openapi_tool/openapi_spec_parser/openapi_toolset.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def __init__(
6969
auth_scheme: Optional[AuthScheme] = None,
7070
auth_credential: Optional[AuthCredential] = None,
7171
tool_filter: Optional[Union[ToolPredicate, List[str]]] = None,
72+
tool_name_prefix: Optional[str] = None,
7273
ssl_verify: Optional[Union[bool, str, ssl.SSLContext]] = None,
7374
):
7475
"""Initializes the OpenAPIToolset.
@@ -104,6 +105,9 @@ def __init__(
104105
``google.adk.tools.openapi_tool.auth.auth_helpers``
105106
tool_filter: The filter used to filter the tools in the toolset. It can be
106107
either a tool predicate or a list of tool names of the tools to expose.
108+
tool_name_prefix: The prefix to prepend to the names of the tools returned
109+
by the toolset. Useful when multiple OpenAPI specs have tools with
110+
similar names.
107111
ssl_verify: SSL certificate verification option for all tools. Can be:
108112
- None: Use default verification (True)
109113
- True: Verify SSL certificates using system CA
@@ -113,7 +117,7 @@ def __init__(
113117
This is useful for enterprise environments where requests go through
114118
a TLS-intercepting proxy with a custom CA certificate.
115119
"""
116-
super().__init__(tool_filter=tool_filter)
120+
super().__init__(tool_filter=tool_filter, tool_name_prefix=tool_name_prefix)
117121
if not spec_dict:
118122
spec_dict = self._load_spec(spec_str, spec_str_type)
119123
self._ssl_verify = ssl_verify

tests/unittests/tools/openapi_tool/openapi_spec_parser/test_openapi_toolset.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,3 +169,24 @@ def test_openapi_toolset_configure_verify_all(openapi_spec: Dict[str, Any]):
169169

170170
for tool in toolset._tools:
171171
assert tool._ssl_verify == ca_bundle_path
172+
173+
174+
async def test_openapi_toolset_tool_name_prefix(openapi_spec: Dict[str, Any]):
175+
"""Test tool_name_prefix parameter prefixes tool names."""
176+
prefix = "my_api"
177+
toolset = OpenAPIToolset(spec_dict=openapi_spec, tool_name_prefix=prefix)
178+
179+
# Verify the toolset has the prefix set
180+
assert toolset.tool_name_prefix == prefix
181+
182+
prefixed_tools = await toolset.get_tools_with_prefix()
183+
assert len(prefixed_tools) == 5
184+
185+
# Verify all tool names are prefixed
186+
for tool in prefixed_tools:
187+
assert tool.name.startswith(f"{prefix}_")
188+
189+
# Verify specific tool name is prefixed
190+
expected_prefixed_name = "my_api_calendar_calendars_insert"
191+
prefixed_tool_names = [t.name for t in prefixed_tools]
192+
assert expected_prefixed_name in prefixed_tool_names

0 commit comments

Comments
 (0)