Skip to content

Commit dbac382

Browse files
committed
fix(cli): filter non-agent directories from list_agents
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
1 parent 8ddddc0 commit dbac382

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/google/adk/cli/utils/agent_loader.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,15 @@ def load_agent(self, agent_name: str) -> Union[BaseAgent, App]:
332332
return agent_or_app
333333

334334
@override
335+
@staticmethod
336+
def _is_agent_dir(path: Path) -> bool:
337+
"""Check if a directory contains a valid agent definition."""
338+
return (
339+
(path / 'root_agent.yaml').exists()
340+
or (path / 'agent.py').exists()
341+
or (path / '__init__.py').exists()
342+
)
343+
335344
def list_agents(self) -> list[str]:
336345
"""Lists all agents available in the agent loader (sorted alphabetically)."""
337346
base_path = Path.cwd() / self.agents_dir
@@ -341,6 +350,7 @@ def list_agents(self) -> list[str]:
341350
if os.path.isdir(os.path.join(base_path, x))
342351
and not x.startswith(".")
343352
and x != "__pycache__"
353+
and self._is_agent_dir(base_path / x)
344354
]
345355
agent_names.sort()
346356
return agent_names

0 commit comments

Comments
 (0)