From dbac3829a1845d975b2a04d2ba4ba461baad22e4 Mon Sep 17 00:00:00 2001 From: g97iulio1609 Date: Sat, 28 Feb 2026 11:47:52 +0100 Subject: [PATCH] fix(cli): filter non-agent directories from list_agents MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 #4647 --- src/google/adk/cli/utils/agent_loader.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/google/adk/cli/utils/agent_loader.py b/src/google/adk/cli/utils/agent_loader.py index 8b5805c5a9..8e7dc131a1 100644 --- a/src/google/adk/cli/utils/agent_loader.py +++ b/src/google/adk/cli/utils/agent_loader.py @@ -332,6 +332,15 @@ def load_agent(self, agent_name: str) -> Union[BaseAgent, App]: return agent_or_app @override + @staticmethod + def _is_agent_dir(path: Path) -> bool: + """Check if a directory contains a valid agent definition.""" + return ( + (path / 'root_agent.yaml').exists() + or (path / 'agent.py').exists() + or (path / '__init__.py').exists() + ) + def list_agents(self) -> list[str]: """Lists all agents available in the agent loader (sorted alphabetically).""" base_path = Path.cwd() / self.agents_dir @@ -341,6 +350,7 @@ def list_agents(self) -> list[str]: if os.path.isdir(os.path.join(base_path, x)) and not x.startswith(".") and x != "__pycache__" + and self._is_agent_dir(base_path / x) ] agent_names.sort() return agent_names