Skip to content

Commit 539d856

Browse files
google-genai-botShaharKatz
authored andcommitted
feat: Allow overriding connection template
PiperOrigin-RevId: 841984336
1 parent 7eb9c06 commit 539d856

File tree

3 files changed

+59
-7
lines changed

3 files changed

+59
-7
lines changed

src/google/adk/tools/application_integration_tool/application_integration_toolset.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(
8383
self,
8484
project: str,
8585
location: str,
86+
connection_template_override: Optional[str] = None,
8687
integration: Optional[str] = None,
8788
triggers: Optional[List[str]] = None,
8889
connection: Optional[str] = None,
@@ -104,6 +105,8 @@ def __init__(
104105
Args:
105106
project: The GCP project ID.
106107
location: The GCP location.
108+
connection_template_override: Overrides `ExecuteConnection` default
109+
integration name.
107110
integration: The integration name.
108111
triggers: The list of trigger names in the integration.
109112
connection: The connection name.
@@ -129,6 +132,7 @@ def __init__(
129132
super().__init__(tool_filter=tool_filter)
130133
self.project = project
131134
self.location = location
135+
self._connection_template_override = connection_template_override
132136
self._integration = integration
133137
self._triggers = triggers
134138
self._connection = connection
@@ -142,6 +146,7 @@ def __init__(
142146
integration_client = IntegrationClient(
143147
project,
144148
location,
149+
connection_template_override,
145150
integration,
146151
triggers,
147152
connection,

src/google/adk/tools/application_integration_tool/clients/integration_client.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ def __init__(
3838
self,
3939
project: str,
4040
location: str,
41+
connection_template_override: Optional[str] = None,
4142
integration: Optional[str] = None,
4243
triggers: Optional[List[str]] = None,
4344
connection: Optional[str] = None,
@@ -50,6 +51,8 @@ def __init__(
5051
Args:
5152
project: The Google Cloud project ID.
5253
location: The Google Cloud location (e.g., us-central1).
54+
connection_template_override: Overrides `ExecuteConnection` default
55+
integration name.
5356
integration: The integration name.
5457
triggers: The list of trigger IDs for the integration.
5558
connection: The connection name.
@@ -62,6 +65,7 @@ def __init__(
6265
"""
6366
self.project = project
6467
self.location = location
68+
self.connection_template_override = connection_template_override
6569
self.integration = integration
6670
self.triggers = triggers
6771
self.connection = connection
@@ -130,7 +134,7 @@ def get_openapi_spec_for_connection(self, tool_name="", tool_instructions=""):
130134
Exception: For any other unexpected errors.
131135
"""
132136
# Application Integration needs to be provisioned in the same region as connection and an integration with name "ExecuteConnection" and trigger "api_trigger/ExecuteConnection" should be created as per the documentation.
133-
integration_name = "ExecuteConnection"
137+
integration_name = self.connection_template_override or "ExecuteConnection"
134138
connections_client = ConnectionsClient(
135139
self.project,
136140
self.location,

tests/unittests/tools/application_integration_tool/test_application_integration_toolset.py

Lines changed: 49 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,15 @@ async def test_initialization_with_integration_and_trigger(
192192
project, location, integration=integration_name, triggers=triggers
193193
)
194194
mock_integration_client.assert_called_once_with(
195-
project, location, integration_name, triggers, None, None, None, None
195+
project,
196+
location,
197+
None,
198+
integration_name,
199+
triggers,
200+
None,
201+
None,
202+
None,
203+
None,
196204
)
197205
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
198206
mock_connections_client.assert_not_called()
@@ -218,6 +226,7 @@ async def test_initialization_with_integration_and_list_of_triggers(
218226
mock_integration_client.assert_called_once_with(
219227
project,
220228
location,
229+
None,
221230
integration_name,
222231
triggers,
223232
None,
@@ -247,7 +256,7 @@ async def test_initialization_with_integration_and_empty_trigger_list(
247256
project, location, integration=integration_name
248257
)
249258
mock_integration_client.assert_called_once_with(
250-
project, location, integration_name, None, None, None, None, None
259+
project, location, None, integration_name, None, None, None, None, None
251260
)
252261
mock_integration_client.return_value.get_openapi_spec_for_integration.assert_called_once()
253262
mock_connections_client.assert_not_called()
@@ -287,6 +296,7 @@ async def test_initialization_with_connection_and_entity_operations(
287296
location,
288297
None,
289298
None,
299+
None,
290300
connection_name,
291301
entity_operations_list,
292302
None,
@@ -335,7 +345,15 @@ async def test_initialization_with_connection_and_actions(
335345
tool_instructions=tool_instructions,
336346
)
337347
mock_integration_client.assert_called_once_with(
338-
project, location, None, None, connection_name, None, actions_list, None
348+
project,
349+
location,
350+
None,
351+
None,
352+
None,
353+
connection_name,
354+
None,
355+
actions_list,
356+
None,
339357
)
340358
mock_connections_client.assert_called_once_with(
341359
project, location, connection_name, None
@@ -414,6 +432,7 @@ def test_initialization_with_service_account_credentials(
414432
mock_integration_client.assert_called_once_with(
415433
project,
416434
location,
435+
None,
417436
integration_name,
418437
triggers,
419438
None,
@@ -441,7 +460,15 @@ def test_initialization_without_explicit_service_account_credentials(
441460
project, location, integration=integration_name, triggers=triggers
442461
)
443462
mock_integration_client.assert_called_once_with(
444-
project, location, integration_name, triggers, None, None, None, None
463+
project,
464+
location,
465+
None,
466+
integration_name,
467+
triggers,
468+
None,
469+
None,
470+
None,
471+
None,
445472
)
446473
mock_openapi_toolset.assert_called_once()
447474
_, kwargs = mock_openapi_toolset.call_args
@@ -542,7 +569,15 @@ async def test_init_with_connection_and_custom_auth(
542569
auth_credential=auth_credential,
543570
)
544571
mock_integration_client.assert_called_once_with(
545-
project, location, None, None, connection_name, None, actions_list, None
572+
project,
573+
location,
574+
None,
575+
None,
576+
None,
577+
connection_name,
578+
None,
579+
actions_list,
580+
None,
546581
)
547582
mock_connections_client.assert_called_once_with(
548583
project, location, connection_name, None
@@ -611,7 +646,15 @@ async def test_init_with_connection_with_auth_override_disabled_and_custom_auth(
611646
auth_credential=auth_credential,
612647
)
613648
mock_integration_client.assert_called_once_with(
614-
project, location, None, None, connection_name, None, actions_list, None
649+
project,
650+
location,
651+
None,
652+
None,
653+
None,
654+
connection_name,
655+
None,
656+
actions_list,
657+
None,
615658
)
616659
mock_connections_client.assert_called_once_with(
617660
project, location, connection_name, None

0 commit comments

Comments
 (0)