import os import importlib from typing import List, Dict from .base_tool import BaseTool def discover_tools() -> Dict[str, BaseTool]: """Auto-discover and load all tools""" tools = {} tools_dir = os.path.dirname(__file__) for item in os.listdir(tools_dir): tool_path = os.path.join(tools_dir, item) if os.path.isdir(tool_path) and not item.startswith('_'): try: # Import the tool module module = importlib.import_module(f'tools.{item}.tool') # Find Tool class (should be named like CensorTool, etc.) for attr_name in dir(module): attr = getattr(module, attr_name) if (isinstance(attr, type) and issubclass(attr, BaseTool) and attr != BaseTool): tool_instance = attr() # Only register enabled tools if tool_instance.enabled: tools[tool_instance.baseroute] = tool_instance break except ImportError as e: print(f"Failed to load tool {item}: {e}") return tools TOOLS = discover_tools()