Register a tool class synchronously. Args: tool_cls: Tool class to register
(tool_cls: Type[Tool])
| 167 | tool_configs: Dict[str, ToolConfig] = {} |
| 168 | |
| 169 | async def register_tool_class(tool_cls: Type[Tool]): |
| 170 | """Register a tool class synchronously. |
| 171 | |
| 172 | Args: |
| 173 | tool_cls: Tool class to register |
| 174 | """ |
| 175 | try: |
| 176 | # Get tool config from global config |
| 177 | tool_config_key = inflection.underscore(tool_cls.__name__) |
| 178 | tool_config_dict = config.get(tool_config_key, {}) |
| 179 | tool_require_grad = tool_config_dict.get("require_grad", False) if tool_config_dict and "require_grad" in tool_config_dict else False |
| 180 | |
| 181 | # Get tool properties from tool class |
| 182 | tool_name = tool_cls.model_fields['name'].default |
| 183 | tool_description = tool_cls.model_fields['description'].default |
| 184 | tool_metadata = tool_cls.model_fields['metadata'].default |
| 185 | |
| 186 | # Get or generate version from version_manager |
| 187 | tool_version = await version_manager.get_version("tool", tool_name) |
| 188 | |
| 189 | # Get full module source code |
| 190 | tool_code = dynamic_manager.get_full_module_source(tool_cls) |
| 191 | |
| 192 | tool_parameters = dynamic_manager.get_parameters(tool_cls) |
| 193 | tool_function_calling = dynamic_manager.build_function_calling(tool_name, tool_description, tool_parameters) |
| 194 | tool_text = dynamic_manager.build_text_representation(tool_name, tool_description, tool_parameters) |
| 195 | tool_args_schema = dynamic_manager.build_args_schema(tool_name, tool_parameters) |
| 196 | |
| 197 | # Create tool config (ToolConfig.id is auto-incremented internally if needed) |
| 198 | tool_config = ToolConfig( |
| 199 | name=tool_name, |
| 200 | description=tool_description, |
| 201 | version=tool_version, |
| 202 | cls=tool_cls, |
| 203 | config=tool_config_dict, |
| 204 | instance=None, |
| 205 | function_calling=tool_function_calling, |
| 206 | text=tool_text, |
| 207 | args_schema=tool_args_schema, |
| 208 | metadata=tool_metadata, |
| 209 | require_grad=tool_require_grad, |
| 210 | code=tool_code, |
| 211 | ) |
| 212 | |
| 213 | # Store tool config |
| 214 | tool_configs[tool_name] = tool_config |
| 215 | |
| 216 | # Store in version history (by version string) |
| 217 | if tool_name not in self._tool_history_versions: |
| 218 | self._tool_history_versions[tool_name] = {} |
| 219 | self._tool_history_versions[tool_name][tool_version] = tool_config |
| 220 | |
| 221 | # Register version to version manager |
| 222 | await version_manager.register_version("tool", tool_name, tool_version) |
| 223 | |
| 224 | logger.info(f"| 📝 Registered tool: {tool_name} ({tool_cls.__name__})") |
| 225 | |
| 226 | except Exception as e: |
nothing calls this directly
no test coverage detected