from typing import Any, Dict from tools.utils import ToolExecutionError, logger class Tool: def openai_spec(self, legacy=False): """ Return the OpenAI function calling spec for this tool. Subclasses should override this if they support function calling. """ return { "name": self.name, "description": self.description, "parameters": self.args_schema } """ Base class for all tools in the agent framework. Attributes: name (str): The unique name of the tool. description (str): A short description of the tool's purpose. args_schema (dict): The schema describing the tool's input arguments. """ name: str description: str args_schema: Dict[str, Any] def __init__(self) -> None: """ Initialize the base Tool with default values. Subclasses should override these attributes as needed. """ self.name = "tool" self.description = "" self.args_schema = {} async def run(self, **kwargs: Any) -> Any: """ Run the tool with the provided arguments. Subclasses must implement this method. Args: **kwargs: Arbitrary keyword arguments for the tool. Returns: Any: The result of the tool's execution. Raises: ToolExecutionError: If the method is not implemented by a subclass. """ logger.error(f"Tool '{self.name}' does not implement the run method.") raise ToolExecutionError( message=f"Tool '{self.name}' does not implement the run method.", code="TOOL_NOT_IMPLEMENTED", user_message="This tool is not available. Please contact support.", )