adk-docs icon indicating copy to clipboard operation
adk-docs copied to clipboard

Persistent TypeError during FunctionTool initialization due to argument parsing inconsistencies

Open Hereforlolz opened this issue 5 months ago • 2 comments

Describe the bug

In the current Google ADK 1.2.1 Python codebase, FunctionTool initialization fails with a TypeError when wrapping Python functions that have mixed required and optional parameters. The root cause appears to be inconsistent argument parsing in the FunctionTool implementation, particularly around how function signatures are introspected and validated.

The relevant code resides in src/google/adk/tools/function_tool.py, where Python’s inspect module is used for signature parsing. This logic behaves inconsistently for certain function signatures, especially on Python 3.13, causing crashes.

Steps to reproduce:

  1. Define a Python function with required positional and optional keyword arguments, e.g.:
``python
def example_func(required_param, optional_param=None):
    pass
```
2. Wrap this function with FunctionTool:

```
from google.adk.tools import FunctionTool
tool = FunctionTool(example_func)

```

**Expected behavior**
FunctionTool should successfully wrap functions with mixed argument patterns without error.

**Actual behavior**

TypeError is raised, preventing agent orchestration.
Generic snippet but close to what this bug causes:
```
Traceback (most recent call last):
  File "agent_script.py", line 10, in <module>
    tool = FunctionTool(example_func)
  File ".../google/adk/tools/function_tool.py", line 45, in __init__
    # (some internal function signature parsing code)
TypeError: __init__() got an unexpected keyword argument 'some_arg'

```

**Desktop**
 - OS: [e.g. iOS] : Windows 11 Home 24H2
 - Python version(python -V): 3.13 (issue reproducible also on 3.11 but with fewer cases)
 - ADK version(pip show google-adk): 1.2.1

**Additional context**

- The bug hinders building multi-agent workflows using FunctionTool.
- A temporary workaround is to avoid complex signatures or use raw Gemini APIs.

**Suggested fix**

    Review and update the argument parsing logic in src/google/adk/tools/function_tool.py to handle all valid Python function signatures robustly, especially considering Python 3.13’s introspection changes.

Hereforlolz avatar Jun 23 '25 13:06 Hereforlolz

Hey team! 👋

I wanted to jump in here and say that the persistent TypeError bug in FunctionTool (covered in this issue google/adk-docs#826) is actually tied to the docs being a bit sketchy on how to handle functions with mixed required and optional parameters.

Right now, the docs don’t clearly show how to write functions that have:

  • Required positional params
  • Optional params with defaults
  • Or even *args and **kwargs

Here’s a quick example that tripped me up:

def greet(name, greeting="Hello", *args, **kwargs):
    print(f"{greeting}, {name}!")

If the docs had clearer examples like this and explained how FunctionTool expects to handle them, it would save folks a lot of guesswork and prevent runtime errors.

I don’t have a perfect fix or PR ready, but I’m happy to collaborate or help draft clearer examples if that would be useful.

Thanks for building such a cool tool -just want to help make it even smoother for everyone. 🚀

Hereforlolz avatar Jun 23 '25 14:06 Hereforlolz

@seanzhou1023 Could you work with @Hereforlolz to come up with the documentation?

hangfei avatar Jun 24 '25 20:06 hangfei