fix(cli): filter non-agent directories from list_agents#4652
fix(cli): filter non-agent directories from list_agents#4652giulio-leone wants to merge 1 commit intogoogle:mainfrom
Conversation
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses an issue where the agent loader was incorrectly listing non-agent directories, causing them to appear in the UI and fail to load. By introducing a more robust validation mechanism, the change ensures that only directories containing actual agent definitions are recognized and presented, thereby improving the reliability and user experience of agent selection. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
|
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. |
There was a problem hiding this comment.
Code Review
This pull request correctly addresses the issue of non-agent directories appearing in the agent list by adding a validation step. The new _is_agent_dir method effectively checks for valid agent definitions before a directory is included. I've added a couple of suggestions to improve the implementation's conciseness and to promote consistent use of pathlib for path manipulations, which should enhance code maintainability.
| return ( | ||
| (path / 'root_agent.yaml').exists() | ||
| or (path / 'agent.py').exists() | ||
| or (path / '__init__.py').exists() | ||
| ) |
There was a problem hiding this comment.
For improved conciseness and maintainability, you can use any() with a generator expression here. This makes the code more compact and easier to extend if more agent definition filenames are added in the future.
Also, note that this logic is duplicated in _determine_agent_language (lines 392-405). While refactoring that method is likely out of scope for this PR, it would be good to extract the list of filenames into a module-level constant to be shared between both methods to avoid this duplication.
return any((path / f).exists() for f in ('root_agent.yaml', 'agent.py', '__init__.py'))79d4f1f to
b3a576a
Compare
list_agents() returns all non-hidden subdirectories, including those that contain no agent definition (e.g. utils/, data/, tmp/). This causes the web UI agent selector and /list-apps endpoint to show non-agent entries that fail to load when selected. Add _is_agent_dir() static method that checks for root_agent.yaml, agent.py, or __init__.py — the same files _determine_agent_language() already relies on — and filter list_agents() output accordingly. Fixes google#4647
b3a576a to
dbac382
Compare
|
Closing — CLA not yet signed. Will resubmit when ready. |
Problem
list_agents()returns all non-hidden subdirectories from the agents directory, including those that contain no agent definition (e.g.utils/,data/,tmp/). These appear in the web UI agent selector and/list-appsendpoint, and fail to load when selected.Root Cause
The directory filter only checks
isdir(),not startswith('.'), and!= '__pycache__'— it never validates that the directory actually contains an agent definition.Fix
Add a
_is_agent_dir()static method that checks for the presence ofroot_agent.yaml,agent.py, or__init__.py— the same files that_determine_agent_language()already relies on — and use it as an additional filter inlist_agents().Test
286 CLI tests pass, 2 consecutive clean runs.
Fixes #4647