fix(cli): use Optional[List[str]] in cleanup_unused_files to fix parser error#6190
Open
syzayd wants to merge 1 commit into
Open
fix(cli): use Optional[List[str]] in cleanup_unused_files to fix parser error#6190syzayd wants to merge 1 commit into
syzayd wants to merge 1 commit into
Conversation
…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
|
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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When the ADK web server runs and the LLM calls the
cleanup_unused_filesbuilt-in tool, the automatic function calling system fails to parse its optional parameter type annotations:The root cause is that
file_patternsandexclude_patternsuse 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 useOptional[List[str]]fromtyping(seewrite_files.py,delete_files.py,read_files.py). This PR alignscleanup_unused_files.pywith that established pattern:from typing import Listandfrom typing import Optionallist[str] | NonewithOptional[List[str]]onfile_patternsandexclude_patternsused_files: list[str]toused_files: List[str]for style consistencyTesting
The fix can be verified by running
adk web, opening the agent editor, and confirming thecleanup_unused_filestool is invoked without the parser warning appearing in the console.