fix: filter non-agent directoris from list_agents()#4648
fix: filter non-agent directoris from list_agents()#4648markadelnawar wants to merge 3 commits 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 refines the agent discovery mechanism by ensuring that the 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
Activity
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
|
There was a problem hiding this comment.
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.
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-appsAPI 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 insidelist_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:
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_directorieswhich creates a temp directory with three valid agent types (package with__init__.py, module withagent.py, YAML withroot_agent.yaml) and three non-agent directories, and asserts only the valid agents are listed.Screenshots / Video:
Manual End-to-End (E2E) Tests:
adk web .Checklist
Additional context