Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/google/adk/cli/utils/agent_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Comment on lines +338 to +342
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For improved conciseness and maintainability, you can use any() with a generator expression here. This makes the code more compact and easier to extend if more agent definition filenames are added in the future.

Also, note that this logic is duplicated in _determine_agent_language (lines 392-405). While refactoring that method is likely out of scope for this PR, it would be good to extract the list of filenames into a module-level constant to be shared between both methods to avoid this duplication.

    return any((path / f).exists() for f in ('root_agent.yaml', 'agent.py', '__init__.py'))


def list_agents(self) -> list[str]:
"""Lists all agents available in the agent loader (sorted alphabetically)."""
base_path = Path.cwd() / self.agents_dir
Expand All @@ -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
Expand Down