diff options
| author | dev <dev@local> | 2026-10-05 16:40:10 +0530 |
|---|---|---|
| committer | dev <dev@local> | 2026-10-05 16:40:10 +0530 |
| commit | ed4889134aa77d912d7e0fc0d69f7def0dd772fc (patch) | |
| tree | 4317f0b80491c02e37d1f752bce8462b5b4b24ff /src/agentux/tools/base.py | |
Working agent before enhancements: 205 tests passing
Diffstat (limited to 'src/agentux/tools/base.py')
| -rw-r--r-- | src/agentux/tools/base.py | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/agentux/tools/base.py b/src/agentux/tools/base.py new file mode 100644 index 0000000..5c13069 --- /dev/null +++ b/src/agentux/tools/base.py @@ -0,0 +1,51 @@ +"""Tool interface. + +A tool is anything the agent can run on the model's behalf. The model only +ever sees a tool's name, description, and JSON Schema -- it addresses tools by +name, and the registry decides what actually runs. +""" + +from __future__ import annotations + +from abc import ABC, abstractmethod +from typing import Any, Dict + +from ..models import ToolDefinition + + +class BaseTool(ABC): + """Abstract base class for all Agentux tools.""" + + @property + @abstractmethod + def name(self) -> str: + """The unique name the model uses to call this tool.""" + + @property + @abstractmethod + def description(self) -> str: + """A description of what the tool does, used for the LLM prompt.""" + + @property + @abstractmethod + def parameters(self) -> Dict[str, Any]: + """JSON Schema defining the tool's input parameters.""" + + @abstractmethod + async def execute(self, **kwargs: Any) -> str: + """Run the tool and return its result as text. + + Raise ``ToolError`` to report failure; the agent turns the message into + tool output so the model can recover instead of aborting the run. + """ + + def to_definition(self) -> ToolDefinition: + """Describe this tool in the shape providers expect.""" + return ToolDefinition( + name=self.name, + description=self.description, + parameters=self.parameters, + ) + + +__all__ = ["BaseTool"] |
