Repository navigation
Conversation
|
Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). View this failed invocation of the CLA check for more information. For the most up to date status, view the checks section at the bottom of the pull request. |
5bc5bf7 to
2e357f4
Compare
mangeshraut712
left a comment
There was a problem hiding this comment.
The identity check in _get_mandatory_args is the right fix for elementwise-equality defaults.
Same hazard remains in src/google/adk/tools/_automatic_function_calling_util.py (~line 84) when building the pydantic field default: param.default != inspect.Parameter.empty still calls the default's __eq__/__ne__. For an elementwise numpy/pandas-style default that returns a non-bool, that ternary can raise the same ambiguous-truth error during schema generation. Please switch it to is / is not, matching this change and the other identity checks in _function_parameter_parse_util.py.
| # when tested for truth or marks an optional parameter as mandatory. | ||
| if ( | ||
| param.default == inspect.Parameter.empty | ||
| param.default is inspect.Parameter.empty |
There was a problem hiding this comment.
Using is here is correct: with a stand-in default whose __eq__ returns a non-bool (as in the new test), == inspect.Parameter.empty raises on truth-testing, while is keeps the parameter optional.
Please apply the same identity check in _automatic_function_calling_util.py where param.default != inspect.Parameter.empty is still used for the pydantic Field default.
…entity param.default == inspect.Parameter.empty runs the default's __eq__, so a numpy/pandas default made an optional parameter mandatory or raised on ambiguous truth values. Use 'is'.
2e357f4 to
b454400
Compare
Problem
FunctionTool._get_mandatory_args()decides whether a parameter has a default with==:==runs the default's own__eq__. A default with elementwise equality - anumpy.ndarray, apandas.Series, the natural default of a numeric tool parameter - returns a non-boolean:run_async()answers every call that omits it with "mandatory input parameters are not present" and the default is never used;_get_mandatory_args()raiseValueError: The truth value of an array with more than one element is ambiguouson every call._get_mandatory_args()runs on everyFunctionTool.run_async()path. The comment directly above the code already states the test in identity form.Fix
Tests
tests/unittests/tools/test_function_tool.py::test_optional_param_with_elementwise_equality_default_is_optionaluses a dependency-free stand-in whose__eq__returns an object with ambiguous truthiness.Related suites (
test_function_tool*.py,test_authenticated_function_tool.py,utils/test_callable_utils.py): 232 passed, 1 skipped.Note: the look-alike
param.default != inspect.Parameter.emptyintools/_automatic_function_calling_util.pyis intentionally not touched here - that path is the legacy function-declaration builder, while_get_mandatory_args()runs on every tool call.