|
20 | 20 | import os |
21 | 21 | from pathlib import Path |
22 | 22 | import sys |
| 23 | +from typing import Any |
| 24 | +from typing import Literal |
23 | 25 | from typing import Optional |
24 | 26 | from typing import Union |
25 | 27 |
|
@@ -341,6 +343,50 @@ def list_agents(self) -> list[str]: |
341 | 343 | agent_names.sort() |
342 | 344 | return agent_names |
343 | 345 |
|
| 346 | + def list_agents_detailed(self) -> list[dict[str, Any]]: |
| 347 | + """Lists all agents with detailed metadata (name, description, type).""" |
| 348 | + agent_names = self.list_agents() |
| 349 | + apps_info = [] |
| 350 | + |
| 351 | + for agent_name in agent_names: |
| 352 | + try: |
| 353 | + loaded = self.load_agent(agent_name) |
| 354 | + if isinstance(loaded, App): |
| 355 | + agent = loaded.root_agent |
| 356 | + else: |
| 357 | + agent = loaded |
| 358 | + |
| 359 | + language = self._determine_agent_language(agent_name) |
| 360 | + |
| 361 | + app_info = { |
| 362 | + "name": agent_name, |
| 363 | + "root_agent_name": agent.name, |
| 364 | + "description": agent.description, |
| 365 | + "language": language, |
| 366 | + } |
| 367 | + apps_info.append(app_info) |
| 368 | + |
| 369 | + except Exception as e: |
| 370 | + logger.error("Failed to load agent '%s': %s", agent_name, e) |
| 371 | + continue |
| 372 | + |
| 373 | + return apps_info |
| 374 | + |
| 375 | + def _determine_agent_language( |
| 376 | + self, agent_name: str |
| 377 | + ) -> Literal["yaml", "python"]: |
| 378 | + """Determine the type of agent based on file structure.""" |
| 379 | + base_path = Path.cwd() / self.agents_dir / agent_name |
| 380 | + |
| 381 | + if (base_path / "root_agent.yaml").exists(): |
| 382 | + return "yaml" |
| 383 | + elif (base_path / "agent.py").exists(): |
| 384 | + return "python" |
| 385 | + elif (base_path / "__init__.py").exists(): |
| 386 | + return "python" |
| 387 | + |
| 388 | + raise ValueError(f"Could not determine agent type for '{agent_name}'.") |
| 389 | + |
344 | 390 | def remove_agent_from_cache(self, agent_name: str): |
345 | 391 | # Clear module cache for the agent and its submodules |
346 | 392 | keys_to_delete = [ |
|
0 commit comments