Conversation
…ionTool When building Tool Declarations, FunctionTool explicitly includes inspect.Parameter.POSITIONAL_ONLY parameters in the JSON schema. However, during invocation, FunctionTool passes arguments as keyword arguments (**args_to_call), which causes Python to raise a TypeError when invoking functions or builtins that have positional-only arguments (e.g., 'def add(x, /, y)' or 'math.pow'). This change introduces _make_keyword_compatible to adapt callables with positional-only parameters so that matching keyword arguments from model tool calls are bound to positional arguments at invocation time, while preserving async execution, thread pool runners, and default arguments.
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Please ensure you have read the contribution guide before creating a pull request.
Link to Issue or Description of Change
1. Link to an existing issue (if applicable):
Problem:
FunctionToolcurrently supports positional-only parameters in its generated tool declaration schema (_function_tool_declarations.py), but runtime invocation inFunctionTool.run_asyncforwards model-generated arguments exclusively via keyword unpacking:In Python, positional-only parameters cannot be supplied as keyword arguments. This causes valid callables such as:
and standard library built-ins such as:
to raise
TypeErrorduring tool execution (TypeError: add() got some positional-only arguments passed as keyword arguments: 'x'orTypeError: math.pow() takes no keyword arguments). Because_invoke_callableonly catches invocationTypeErrorwhennot self._spec.has_signature, this unhandled exception terminates the entire agent run.Root Cause:
There is a mismatch between declaration/schema generation, which explicitly recognizes
inspect.Parameter.POSITIONAL_ONLYparameters and exposes them by name in the LLM tool declaration schema, and runtime invocation, which treats every model argument as a keyword argument.Solution:
Added
_make_keyword_compatible(target, signature)insrc/google/adk/tools/function_tool.pyto adapt callables with positional-only parameters:__call__), parameter injection (e.g.tool_context), confirmation predicates (require_confirmation), and thread-pool execution (_use_sync_callable_runner).Testing Plan
Unit Tests:
Summary of passed test results:
FunctionToolunit tests passed intests/unittests/tools/test_function_tool.py(including 8 new regression tests covering sync, async, built-ins, defaults, thread-pool runner, callable objects, context injection, and confirmation predicates).tests/unittests/tools/test_function_tool*.pyandtests/unittests/flows/llm_flows/tools/test_functions_thread_pool.py.tests/unittests/tools/suite.tox) across Python 3.10, 3.11, 3.12, 3.13, and 3.14:FunctionTooltests and all tool-related tests passed with 100% success on all 5 Python versions.test_interactions_utils.pyandtest_import_loading.py) were verified to reproduce identically on clean upstreamorigin/mainas pre-existing baseline/environmental issues.pre-commit run --all-files(pyink, isort, ruff, addlicense, compliance-checks, check-docs, etc.).Manual End-to-End (E2E) Tests:
Built wheel with
uv buildand verified execution in an isolated virtual environment outside the repository:Scope
Changes are strictly confined to:
src/google/adk/tools/function_tool.pytests/unittests/tools/test_function_tool.pyChecklist