Download src/tools/base_tool.py from lekmikdok/hyp: direct link, hf CLI and curl.
- Browser
- Download file 1.69 kB
-
https://huggingface.co/spaces/lekmikdok/hyp/resolve/main/src/tools/base_tool.py
- Command line
-
hf download hf://spaces/lekmikdok/hyp/src/tools/base_tool.py
-
curl -L -o base_tool.py https://huggingface.co/spaces/lekmikdok/hyp/resolve/main/src/tools/base_tool.py
1.69 kB
| # Base class for all tools | |
| from abc import ABC, abstractmethod | |
| import logging | |
| from typing import Any, Dict, Optional, List | |
| class BaseTool(ABC): | |
| """Base abstract class for all tools used by agents. | |
| All specific tool implementations should inherit from this class | |
| and implement the required methods. | |
| """ | |
| def __init__(self, name: str, description: str): | |
| """Initialize the base tool. | |
| Args: | |
| name: The name of the tool | |
| description: A description of what the tool does | |
| """ | |
| self.name = name | |
| self.description = description | |
| self.logger = logging.getLogger(f"tool.{name}") | |
| def execute(self, **kwargs) -> Any: | |
| """Execute the tool with the given parameters. | |
| Args: | |
| **kwargs: Tool-specific parameters | |
| Returns: | |
| The result of the tool execution | |
| """ | |
| pass | |
| def get_tool_spec(self) -> Dict[str, Any]: | |
| """Get the tool specification for agent function calling. | |
| Returns: | |
| A dictionary containing the tool's specification. | |
| """ | |
| return { | |
| "type": "function", | |
| "function": { | |
| "name": self.name, | |
| "description": self.description, | |
| "parameters": self.get_parameters_schema() | |
| } | |
| } | |
| def get_parameters_schema(self) -> Dict[str, Any]: | |
| """Get the JSON schema for the tool's parameters. | |
| Returns: | |
| A dictionary containing the JSON schema for the tool's parameters. | |
| """ | |
| pass | |