Dynamically import tool classes defined in toolregistry.json
(self)
| 15 | self.tools: Dict[str, Any] = {} |
| 16 | |
| 17 | def load_tools(self): |
| 18 | """Dynamically import tool classes defined in toolregistry.json""" |
| 19 | for tool in TOOL_REGISTRY: |
| 20 | fn = tool["function"] |
| 21 | module_name = fn.get("module") |
| 22 | class_name = fn.get("class") |
| 23 | |
| 24 | try: |
| 25 | module = importlib.import_module(f"termnet.tools.{module_name}") |
| 26 | cls = getattr(module, class_name) |
| 27 | instance = cls() |
| 28 | self.tools[fn["name"]] = instance |
| 29 | #print(f"✅ Loaded tool: {fn['name']} ({module_name}.{class_name})") |
| 30 | except Exception as e: |
| 31 | print(f"❌ Failed to load tool {fn['name']}: {e}") |
| 32 | |
| 33 | def get_tool_definitions(self) -> List[Dict[str, Any]]: |
| 34 | """Return JSON schema tool definitions (for LLM)""" |