multiple-changes-made
This commit is contained in:
40
tool_loader.py
Normal file
40
tool_loader.py
Normal file
@@ -0,0 +1,40 @@
|
||||
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
|
||||
Reference in New Issue
Block a user