Skip to content

fix(cli): use Optional[List[str]] in cleanup_unused_files to fix parser error#6190

Open
syzayd wants to merge 1 commit into
google:mainfrom
syzayd:fix/cleanup-unused-files-optional-type-hints
Open

fix(cli): use Optional[List[str]] in cleanup_unused_files to fix parser error#6190
syzayd wants to merge 1 commit into
google:mainfrom
syzayd:fix/cleanup-unused-files-optional-type-hints

Conversation

@syzayd

@syzayd syzayd commented Jun 22, 2026

Copy link
Copy Markdown

Problem

When the ADK web server runs and the LLM calls the cleanup_unused_files built-in tool, the automatic function calling system fails to parse its optional parameter type annotations:

Error in event_generator: Failed to parse the parameter
file_patterns: List[str] | None = None of function
cleanup_unused_files for automatic function calling

The root cause is that file_patterns and exclude_patterns use the PEP 604 union syntax (list[str] | None) which ADK's function schema builder cannot handle.

Fixes #3591

Fix

All sibling tools in src/google/adk/cli/built_in_agents/tools/ already use Optional[List[str]] from typing (see write_files.py, delete_files.py, read_files.py). This PR aligns cleanup_unused_files.py with that established pattern:

  • Add from typing import List and from typing import Optional
  • Replace list[str] | None with Optional[List[str]] on file_patterns and exclude_patterns
  • Change used_files: list[str] to used_files: List[str] for style consistency

Testing

The fix can be verified by running adk web, opening the agent editor, and confirming the cleanup_unused_files tool is invoked without the parser warning appearing in the console.

…er error

ADK's automatic function calling system cannot parse the PEP 604 union
syntax `list[str] | None` when building the tool schema for Gemini.
This causes the following error every time the ADK web server runs:

    Failed to parse the parameter file_patterns: List[str] | None = None
    of function cleanup_unused_files for automatic function calling

All sibling tools in this directory (delete_files.py, read_files.py,
write_files.py, etc.) already use `Optional[List[str]]` from `typing`.
This commit aligns cleanup_unused_files.py with that established pattern.

Changes:
- Add `from typing import List` and `from typing import Optional`
- Replace `list[str] | None` with `Optional[List[str]]` on both optional
  parameters (file_patterns, exclude_patterns)
- Change `used_files: list[str]` to `used_files: List[str]` for style
  consistency with sibling tools

Fixes google#3591
@google-cla

google-cla Bot commented Jun 22, 2026

Copy link
Copy Markdown

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant