Fix: Handle unexpected 'parameters' argument in FunctionTool.run_async

The LLM occasionally includes an unexpected 'parameters' argument when calling tools, specifically observed with 'transfer_to_agent'. This change makes FunctionTool.run_async more robust by filtering arguments against the function signature before invocation.

This resolves issue #1637.

Update test_function_tool.py

fix typing

fix: add `from __future__ import annotations`
This commit is contained in:
google-labs-jules[bot]
2025-07-02 00:22:09 +00:00
committed by Hangfei Lin
parent 9af2394e0a
commit 0959b06dbd
2 changed files with 58 additions and 1 deletions
+7 -1
View File
@@ -12,6 +12,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
from __future__ import annotations
import inspect
from typing import Any
from typing import Callable
@@ -79,9 +81,13 @@ class FunctionTool(BaseTool):
) -> Any:
args_to_call = args.copy()
signature = inspect.signature(self.func)
if 'tool_context' in signature.parameters:
valid_params = {param for param in signature.parameters}
if 'tool_context' in valid_params:
args_to_call['tool_context'] = tool_context
# Filter args_to_call to only include valid parameters for the function
args_to_call = {k: v for k, v in args_to_call.items() if k in valid_params}
# Before invoking the function, we check for if the list of args passed in
# has all the mandatory arguments or not.
# If the check fails, then we don't invoke the tool and let the Agent know