Skip to content

fix: filter non-agent directoris from list_agents()#4648

Open
markadelnawar wants to merge 3 commits intogoogle:mainfrom
markadelnawar:fix/list-agents-filter-non-agents-dirs
Open

fix: filter non-agent directoris from list_agents()#4648
markadelnawar wants to merge 3 commits intogoogle:mainfrom
markadelnawar:fix/list-agents-filter-non-agents-dirs

Conversation

@markadelnawar
Copy link

Please ensure you have read the contribution guide before creating a pull request.

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

2. Or, if no issue exists, describe the change:

Problem:
AgentLoader.list_agents() returns every non-hidden subdirectory in the agents directory, regardless of whether it contains a valid agent definition. This causes non-agent directories (e.g. tmp/, data/, utils/) to appear in the /list-apps API response. This affects both the ADK web UI agent selector and any production deployment depending on this API.

Solution:
Reuse the existing _determine_agent_language() method inside list_agents() to verify each candidate directory contains at least one recognized agent file (root_agent.yaml, agent.py, or __init__.py). Directories that fail this check are excluded from the result. This avoids introducing any new methods or abstractions and keeps the check lightweight (filesystem only, no agent imports).

Testing Plan

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

27 passed in 2.85s:
pytest tests/unittests/cli/utils/test_agent_loader.py -v
======================= 27 passed, 14 warnings in 2.85s ========================

Added test_list_agents_excludes_non_agent_directories which creates a temp directory with three valid agent types (package with __init__.py, module with agent.py, YAML with root_agent.yaml) and three non-agent directories, and asserts only the valid agents are listed.

Screenshots / Video:

Before (non-agent directories listed) After (only valid agents listed)
Image Image

Manual End-to-End (E2E) Tests:

  1. Create a project directory containing both valid agent subdirectories and non-agent subdirectories
  2. Run adk web .
  3. Open the web UI and verify only valid agents appear in the agent selector
  4. See screenshots below for before/after comparison

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

Additional context

@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 refines the agent discovery mechanism by ensuring that the list_agents function only returns directories that genuinely contain agent definitions. This change improves the accuracy of agent listings in the ADK web UI and API, preventing the display of irrelevant or invalid entries and enhancing the user experience.

Highlights

  • Problem Addressed: The AgentLoader.list_agents() method previously returned all non-hidden subdirectories, including those that did not contain valid agent definitions, leading to incorrect listings in the ADK web UI and API.
  • Solution Implemented: The list_agents() method now reuses the existing _determine_agent_language() method to verify if a directory contains a valid agent definition (e.g., root_agent.yaml, agent.py, or __init__.py). Directories failing this check are excluded.
  • Testing: A new unit test, test_list_agents_excludes_non_agent_directories, was added to confirm that list_agents correctly filters out non-agent directories while including valid ones. Manual end-to-end tests were also performed and screenshots provided.

🧠 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
    • Refactored list_agents method from a list comprehension to an explicit loop.
    • Integrated a try-except ValueError block to call _determine_agent_language for each directory, filtering out those that do not represent valid agents.
  • tests/unittests/cli/utils/test_agent_loader.py
    • Added a new unit test test_list_agents_excludes_non_agent_directories.
    • The test creates a temporary directory structure with various valid and invalid agent configurations.
    • Assertions confirm that list_agents correctly identifies and returns only the valid agent directories.
Activity
  • The author identified a problem where AgentLoader.list_agents() was returning non-agent directories.
  • A solution was proposed to reuse _determine_agent_language() for validation.
  • Unit tests were added and updated to cover the new filtering logic.
  • All unit tests passed locally.
  • Manual end-to-end tests were conducted, and screenshots were provided to demonstrate the fix.
  • The author performed a self-review and confirmed adherence to contribution guidelines.
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.

@adk-bot adk-bot added the core [Component] This issue is related to the core interface and implementation label Feb 28, 2026
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 filters out non-agent directories from list_agents() by checking for valid agent definition files. The implementation is sound and is accompanied by a good unit test. I have a couple of suggestions to improve maintainability and strengthen the test assertions.

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

Labels

core [Component] This issue is related to the core interface and implementation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants