Base class for all tools.
| 14 | |
| 15 | |
| 16 | class Tool: |
| 17 | """Base class for all tools.""" |
| 18 | |
| 19 | @property |
| 20 | def name(self) -> str: |
| 21 | """Tool name.""" |
| 22 | raise NotImplementedError |
| 23 | |
| 24 | @property |
| 25 | def description(self) -> str: |
| 26 | """Tool description.""" |
| 27 | raise NotImplementedError |
| 28 | |
| 29 | @property |
| 30 | def parameters(self) -> dict[str, Any]: |
| 31 | """Tool parameters schema (JSON Schema format).""" |
| 32 | raise NotImplementedError |
| 33 | |
| 34 | async def execute(self, *args, **kwargs) -> ToolResult: # type: ignore |
| 35 | """Execute the tool with arbitrary arguments.""" |
| 36 | raise NotImplementedError |
| 37 | |
| 38 | def to_schema(self) -> dict[str, Any]: |
| 39 | """Convert tool to Anthropic tool schema.""" |
| 40 | return { |
| 41 | "name": self.name, |
| 42 | "description": self.description, |
| 43 | "input_schema": self.parameters, |
| 44 | } |
| 45 | |
| 46 | def to_openai_schema(self) -> dict[str, Any]: |
| 47 | """Convert tool to OpenAI tool schema.""" |
| 48 | return { |
| 49 | "type": "function", |
| 50 | "function": { |
| 51 | "name": self.name, |
| 52 | "description": self.description, |
| 53 | "parameters": self.parameters, |
| 54 | }, |
| 55 | } |
nothing calls this directly
no outgoing calls
no test coverage detected