google / google/adk-docs

int | None union syntax fails to parse in function parameters despite documented support

Open
#827 5 comments 2 reactions 0 assignees View on GitHub
Dominant language
Shell
Stars
1.5k
Forks
1.3k
Avg merge
7d 1h
Merged PRs (30d)
34

Description

Bug Description:

The Google ADK function parameter parser fails to handle modern Python union syntax (int | None) in function parameters, throwing a parsing error despite the codebase claiming to support union types. The error suggests using manual function declaration parsing as a workaround.

To Reproduce:

Create a function with int | None parameter annotation
Use the function as a tool in an ADK agent
Run the agent - automatic function calling fails with parsing error
Expected Behavior:
The int | None syntax should be parsed successfully, similar to how Optional[int] works, since both represent the same type annotation.

Actual Behavior:

Error: Failed to parse the parameter num_lines: int | None of function for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function .

Root Cause Analysis:
The issue appears to be in where the parser checks get_origin(param.annotation) is Union. The modern int | None syntax may not be detected by this condition, causing it to fall through to the error case at .

Environment:

Python version: 3.12.10
ADK version: 1.4.2
OS: Windows 11 Pro
Code Example:

```python
def example_function(file_path: str, num_lines: int | None = None) -> str:
# Function implementation
pass
```
Workaround:
Using Optional[int] instead of int | None works as expected:

from typing import Optional
```python
def example_function(file_path: str, num_lines: Optional[int] = None) -> str:
# Function implementation
pass
```
Additional Context:

The codebase requires from __future__ import annotations as shown in check-file-contents.yml:73-83
The parser has logic for handling union types with None as shown in
The codebase uses Optional[type] extensively in existing tools, suggesting this should work
This appears to be an inconsistency between the documented/intended support for modern Python syntax and the actual implementation in the parameter parser.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.