Skip to content

Commit 2ed6865

Browse files
xuanyang15copybara-github
authored andcommitted
feat: Use json schema for IntegrationConnectorTool declaration when feature enabled
Co-authored-by: Xuan Yang <xygoogle@google.com> PiperOrigin-RevId: 856508415
1 parent ec6abf4 commit 2ed6865

2 files changed

Lines changed: 35 additions & 4 deletions

File tree

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
from ...auth.auth_credential import AuthCredential
2727
from ...auth.auth_schemes import AuthScheme
28+
from ...features import FeatureName
29+
from ...features import is_feature_enabled
2830
from .._gemini_schema_util import _to_gemini_schema
2931
from ..base_tool import BaseTool
3032
from ..openapi_tool.openapi_spec_parser.rest_api_tool import RestApiTool
@@ -125,10 +127,17 @@ def _get_declaration(self) -> FunctionDeclaration:
125127
if field in schema_dict['required']:
126128
schema_dict['required'].remove(field)
127129

128-
parameters = _to_gemini_schema(schema_dict)
129-
function_decl = FunctionDeclaration(
130-
name=self.name, description=self.description, parameters=parameters
131-
)
130+
if is_feature_enabled(FeatureName.JSON_SCHEMA_FOR_FUNC_DECL):
131+
function_decl = FunctionDeclaration(
132+
name=self.name,
133+
description=self.description,
134+
parameters_json_schema=schema_dict,
135+
)
136+
else:
137+
parameters = _to_gemini_schema(schema_dict)
138+
function_decl = FunctionDeclaration(
139+
name=self.name, description=self.description, parameters=parameters
140+
)
132141
return function_decl
133142

134143
def _prepare_dynamic_euc(self, auth_credential: AuthCredential) -> str:

tests/unittests/tools/application_integration_tool/test_integration_connector_tool.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818
from google.adk.auth.auth_credential import AuthCredentialTypes
1919
from google.adk.auth.auth_credential import HttpAuth
2020
from google.adk.auth.auth_credential import HttpCredentials
21+
from google.adk.features import FeatureName
22+
from google.adk.features._feature_registry import temporary_feature_override
2123
from google.adk.tools.application_integration_tool.integration_connector_tool import IntegrationConnectorTool
2224
from google.adk.tools.openapi_tool.openapi_spec_parser.rest_api_tool import RestApiTool
2325
from google.adk.tools.openapi_tool.openapi_spec_parser.tool_auth_handler import AuthPreparationResult
@@ -254,3 +256,23 @@ async def test_run_with_auth_async(
254256
args=expected_call_args, tool_context={}
255257
)
256258
assert result == {"status": "success", "data": "mock_data"}
259+
260+
261+
def test_get_declaration_with_json_schema_feature_enabled(integration_tool):
262+
"""Tests the generation of the function declaration with JSON schema feature enabled."""
263+
with temporary_feature_override(FeatureName.JSON_SCHEMA_FOR_FUNC_DECL, True):
264+
declaration = integration_tool._get_declaration()
265+
266+
assert isinstance(declaration, FunctionDeclaration)
267+
assert declaration.name == "test_integration_tool"
268+
assert declaration.description == "Test integration tool description."
269+
assert declaration.parameters is None
270+
assert declaration.parameters_json_schema == {
271+
"type": "object",
272+
"properties": {
273+
"user_id": {"type": "string", "description": "User ID"},
274+
"page_size": {"type": "integer"},
275+
"filter": {"type": "string"},
276+
},
277+
"required": ["user_id"],
278+
}

0 commit comments

Comments
 (0)