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