Skip to content
Open
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
34 changes: 14 additions & 20 deletions backend/python/app/agents/tools/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,8 @@ def import_modules(self, module_paths: List[str]) -> Dict[str, Any]:
"imported": self.imported_modules,
"failed": self.failed_imports,
"success_rate": (
len(self.imported_modules) / len(module_paths)
if module_paths else 0
)
len(self.imported_modules) / len(module_paths) if module_paths else 0
),
}


Expand Down Expand Up @@ -125,15 +124,12 @@ def discover(self, base_dir: Path, importer: ModuleImporter) -> List[str]:
if not app_dir.exists():
return []

modules = []
for subdir in self.subdirs:
subdir_path = app_dir / subdir
if subdir_path.exists():
main_file = subdir_path / f"{subdir}.py"
if main_file.exists():
modules.append(
f"app.agents.actions.{self.app_name}.{subdir}.{subdir}"
)
# Use list comprehension for faster and more memory-efficient collection.
modules = [
f"app.agents.actions.{self.app_name}.{subdir}.{subdir}"
for subdir in self.subdirs
if (app_dir / subdir / f"{subdir}.py").exists()
]

return modules

Expand Down Expand Up @@ -204,18 +200,15 @@ def _log_results(self) -> None:
self.logger.info(f"Modules imported: {len(self.importer.imported_modules)}")

if self.importer.failed_imports:
self.logger.warning(
f"Failed imports: {len(self.importer.failed_imports)}"
)
self.logger.warning(f"Failed imports: {len(self.importer.failed_imports)}")
for failure in self.importer.failed_imports[:5]: # Show first 5
self.logger.warning(f" - {failure}")

def _get_discovery_results(self) -> Dict[str, Any]:
"""Get discovery results"""
registered_tools = _global_tools_registry.list_tools()
total_attempts = (
len(self.importer.imported_modules) +
len(self.importer.failed_imports)
total_attempts = len(self.importer.imported_modules) + len(
self.importer.failed_imports
)

return {
Expand All @@ -225,8 +218,9 @@ def _get_discovery_results(self) -> Dict[str, Any]:
"total_tools": len(registered_tools),
"success_rate": (
len(self.importer.imported_modules) / total_attempts
if total_attempts > 0 else 0
)
if total_attempts > 0
else 0
),
}


Expand Down