Skip to content

fix(cli): filter non-agent directories from list_agents#4652

Closed
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/list-agents-filter-valid
Closed

fix(cli): filter non-agent directories from list_agents#4652
giulio-leone wants to merge 1 commit intogoogle:mainfrom
giulio-leone:fix/list-agents-filter-valid

Conversation

@giulio-leone
Copy link

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-apps endpoint, 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 of root_agent.yaml, agent.py, or __init__.py — the same files that _determine_agent_language() already relies on — and use it as an additional filter in list_agents().

Test

286 CLI tests pass, 2 consecutive clean runs.

Fixes #4647

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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

  • Problem Identification: The list_agents() function was returning non-agent directories (e.g., utils/, data/, tmp/), which appeared in the web UI agent selector and /list-apps endpoint, leading to loading failures when selected.
  • Root Cause Analysis: The existing directory filter only checked for isdir(), not startswith('.'), and != '__pycache__', lacking validation for actual agent definitions within the directories.
  • Solution Implemented: A new static method, _is_agent_dir(), was added to check for the presence of root_agent.yaml, agent.py, or __init__.py files. This method is now used as an additional filter within list_agents() to ensure only valid agent directories are returned.

🧠 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
  • src/google/adk/cli/utils/agent_loader.py
    • Added a new static method _is_agent_dir to verify if a given path contains a valid agent definition.
    • Modified the list_agents method to incorporate the _is_agent_dir check, filtering out directories that do not contain agent definitions.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@google-cla
Copy link

google-cla bot commented Feb 28, 2026

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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +338 to +342
return (
(path / 'root_agent.yaml').exists()
or (path / 'agent.py').exists()
or (path / '__init__.py').exists()
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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'))

@giulio-leone giulio-leone force-pushed the fix/list-agents-filter-valid branch from 79d4f1f to b3a576a Compare February 28, 2026 14:38
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
@giulio-leone giulio-leone force-pushed the fix/list-agents-filter-valid branch from b3a576a to dbac382 Compare February 28, 2026 14:39
@giulio-leone
Copy link
Author

Closing — CLA not yet signed. Will resubmit when ready.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

list_agents() returns non-agent directories in /list-apps endpoint

1 participant