40 lines
1.1 KiB
Python
40 lines
1.1 KiB
Python
import importlib
|
|
import logging
|
|
from pathlib import Path
|
|
|
|
def load_tools(tools_path: Path):
|
|
registry = {}
|
|
|
|
for file in tools_path.glob("*.py"):
|
|
if file.name.startswith("_"):
|
|
continue
|
|
|
|
module_name = f"tools.{file.stem}"
|
|
|
|
try:
|
|
module = importlib.import_module(module_name)
|
|
|
|
# Check if TOOL_DEFINITION exists
|
|
if not hasattr(module, "TOOL_DEFINITION"):
|
|
logging.warning(f"Tool {file.name} missing TOOL_DEFINITION, skipping")
|
|
continue
|
|
|
|
# Check if run function exists
|
|
if not hasattr(module, "run"):
|
|
logging.warning(f"Tool {file.name} missing 'run' function, skipping")
|
|
continue
|
|
|
|
name = module.TOOL_DEFINITION["name"]
|
|
func = getattr(module, "run")
|
|
|
|
registry[name] = {
|
|
"definition": module.TOOL_DEFINITION,
|
|
"function": func,
|
|
}
|
|
|
|
logging.info(f"Loaded tool: {name}")
|
|
|
|
except Exception as e:
|
|
logging.error(f"Failed to load tool {file.name}", exc_info=True)
|
|
|
|
return registry |