|
17 | 17 | from google.adk.features import FeatureName |
18 | 18 | from google.adk.features._feature_registry import temporary_feature_override |
19 | 19 | from google.adk.tools import _automatic_function_calling_util |
| 20 | +from google.adk.tools import _function_parameter_parse_util |
20 | 21 | from google.adk.tools.tool_context import ToolContext |
21 | 22 | from google.adk.utils.variant_utils import GoogleLLMVariant |
22 | 23 | from google.genai import types |
@@ -198,6 +199,44 @@ def simple_function(input_str: str, tool_context: ToolContext) -> str: |
198 | 199 | assert function_decl.parameters.properties['input_str'].type == 'STRING' |
199 | 200 | assert 'tool_context' not in function_decl.parameters.properties |
200 | 201 |
|
| 202 | + def test_get_required_fields_no_properties_returns_empty_list(self): |
| 203 | + # A schema without properties must yield [] rather than None for any |
| 204 | + # caller that relies on the declared list[str] return. |
| 205 | + assert ( |
| 206 | + _function_parameter_parse_util._get_required_fields( |
| 207 | + types.Schema(type='OBJECT') |
| 208 | + ) |
| 209 | + == [] |
| 210 | + ) |
| 211 | + assert ( |
| 212 | + _function_parameter_parse_util._get_required_fields( |
| 213 | + types.Schema(type='OBJECT', properties={}) |
| 214 | + ) |
| 215 | + == [] |
| 216 | + ) |
| 217 | + |
| 218 | + def test_build_declaration_includes_required_parameters(self): |
| 219 | + def simple_function(input_str: str) -> str: |
| 220 | + return {'result': input_str} |
| 221 | + |
| 222 | + function_decl = _automatic_function_calling_util.build_function_declaration( |
| 223 | + func=simple_function |
| 224 | + ) |
| 225 | + |
| 226 | + assert function_decl.parameters.required == ['input_str'] |
| 227 | + |
| 228 | + def test_all_parameters_ignored_results_in_no_parameters_schema(self): |
| 229 | + def only_context(tool_context: ToolContext) -> str: |
| 230 | + return '' |
| 231 | + |
| 232 | + function_decl = _automatic_function_calling_util.build_function_declaration( |
| 233 | + func=only_context, ignore_params=['tool_context'] |
| 234 | + ) |
| 235 | + |
| 236 | + # No parameters remain after ignoring tool_context, so the declaration |
| 237 | + # carries no parameter schema instead of one with required=None. |
| 238 | + assert function_decl.parameters is None |
| 239 | + |
201 | 240 | def test_basemodel(self): |
202 | 241 | class SimpleFunction(BaseModel): |
203 | 242 | input_str: str |
|
0 commit comments