Skip to content

Commit 5020954

Browse files
GWealecopybara-github
authored andcommitted
fix: Update list_agents to only list directories, not validate agent definitions
The list_agents method in AgentLoader no longer attempts to determine the agent language for each directory Co-authored-by: George Weale <gweale@google.com> PiperOrigin-RevId: 890078066
1 parent f7359e3 commit 5020954

File tree

2 files changed

+7
-57
lines changed

2 files changed

+7
-57
lines changed

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

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -364,18 +364,13 @@ def load_agent(self, agent_name: str) -> Union[BaseAgent, App]:
364364
def list_agents(self) -> list[str]:
365365
"""Lists all agents available in the agent loader (sorted alphabetically)."""
366366
base_path = Path.cwd() / self.agents_dir
367-
agent_names = []
368-
for x in os.listdir(base_path):
369-
if (
370-
os.path.isdir(os.path.join(base_path, x))
371-
and not x.startswith(".")
372-
and x != "__pycache__"
373-
):
374-
try:
375-
self._determine_agent_language(x)
376-
agent_names.append(x)
377-
except ValueError:
378-
continue
367+
agent_names = [
368+
x
369+
for x in os.listdir(base_path)
370+
if os.path.isdir(os.path.join(base_path, x))
371+
and not x.startswith(".")
372+
and x != "__pycache__"
373+
]
379374
agent_names.sort()
380375
return agent_names
381376

tests/unittests/cli/utils/test_agent_loader.py

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -960,51 +960,6 @@ def __init__(self):
960960
assert detailed_list[0]["name"] == agent_name
961961
assert not detailed_list[0]["is_computer_use"]
962962

963-
def test_list_agents_excludes_non_agent_directories(self):
964-
"""Test that list_agents filters out directories without agent definitions."""
965-
with tempfile.TemporaryDirectory() as temp_dir:
966-
temp_path = Path(temp_dir)
967-
968-
valid_package = temp_path / "valid_agent"
969-
valid_package.mkdir()
970-
(valid_package / "__init__.py").write_text(dedent("""
971-
from google.adk.agents.base_agent import BaseAgent
972-
973-
class ValidAgent(BaseAgent):
974-
def __init__(self):
975-
super().__init__(name="valid_agent")
976-
977-
root_agent = ValidAgent()
978-
"""))
979-
980-
valid_module = temp_path / "module_agent"
981-
valid_module.mkdir()
982-
(valid_module / "agent.py").write_text(dedent("""
983-
from google.adk.agents.base_agent import BaseAgent
984-
985-
class ModuleAgent(BaseAgent):
986-
def __init__(self):
987-
super().__init__(name="module_agent")
988-
989-
root_agent = ModuleAgent()
990-
"""))
991-
992-
valid_yaml = temp_path / "yaml_agent"
993-
valid_yaml.mkdir()
994-
(valid_yaml / "root_agent.yaml").write_text("name: yaml_agent\n")
995-
996-
(temp_path / "random_folder").mkdir()
997-
(temp_path / "data").mkdir()
998-
(temp_path / "tmp").mkdir()
999-
1000-
loader = AgentLoader(str(temp_path))
1001-
agents = loader.list_agents()
1002-
1003-
assert agents == ["module_agent", "valid_agent", "yaml_agent"]
1004-
assert "random_folder" not in agents
1005-
assert "data" not in agents
1006-
assert "tmp" not in agents
1007-
1008963
def test_validate_agent_name_rejects_dotted_paths(self):
1009964
"""Agent names with dots are rejected to prevent arbitrary module imports."""
1010965
with tempfile.TemporaryDirectory() as temp_dir:

0 commit comments

Comments
 (0)