Download mini_agent/tools/base.py from AbdulElahGwaith/Mini-Agent: direct link, hf CLI and curl.
- Browser
- Download file 1.38 kB
-
https://huggingface.co/AbdulElahGwaith/Mini-Agent/resolve/main/mini_agent/tools/base.py
- Command line
-
hf download hf://AbdulElahGwaith/Mini-Agent/mini_agent/tools/base.py
-
curl -L -o base.py https://huggingface.co/AbdulElahGwaith/Mini-Agent/resolve/main/mini_agent/tools/base.py
1.38 kB
| """Base tool classes.""" | |
| from typing import Any | |
| from pydantic import BaseModel | |
| class ToolResult(BaseModel): | |
| """Tool execution result.""" | |
| success: bool | |
| content: str = "" | |
| error: str | None = None | |
| class Tool: | |
| """Base class for all tools.""" | |
| def name(self) -> str: | |
| """Tool name.""" | |
| raise NotImplementedError | |
| def description(self) -> str: | |
| """Tool description.""" | |
| raise NotImplementedError | |
| def parameters(self) -> dict[str, Any]: | |
| """Tool parameters schema (JSON Schema format).""" | |
| raise NotImplementedError | |
| async def execute(self, *args, **kwargs) -> ToolResult: # type: ignore | |
| """Execute the tool with arbitrary arguments.""" | |
| raise NotImplementedError | |
| def to_schema(self) -> dict[str, Any]: | |
| """Convert tool to Anthropic tool schema.""" | |
| return { | |
| "name": self.name, | |
| "description": self.description, | |
| "input_schema": self.parameters, | |
| } | |
| def to_openai_schema(self) -> dict[str, Any]: | |
| """Convert tool to OpenAI tool schema.""" | |
| return { | |
| "type": "function", | |
| "function": { | |
| "name": self.name, | |
| "description": self.description, | |
| "parameters": self.parameters, | |
| }, | |
| } | |