Skip to content

Allow modern Union type for FunctionTool #2925

@ptrxwsmitt

Description

@ptrxwsmitt

** Please make sure you read the contribution guide and file the issues in the right place. **
Contribution guide.

Describe the bug
Version 1.13.0, 1.14.0

The documentation describes that FunctionTool is capable of using parameters with the modern python Union type i.e. | None (see https://google.github.io/adk-docs/tools/function-tools/#required-parameters).

Yet it doesn't seem to work:

ValueError: Failed to parse the parameter name: str | None = None of function say_hello for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function say_hello.

To Reproduce
Use the following tool with an LLMAgent

from google.adk.tools import FunctionTool

def say_hello(name:str|None=None):
    if name:
        return f"Hello {name}!"
    else:
        return "Hello!"
    
def say_hello_tool():
    return FunctionTool(say_hello)

Expected behavior
No ValueError and correct type identification

Metadata

Metadata

Labels

tools[Component] This issue is related to tools

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions