summaryrefslogtreecommitdiff
path: root/src/agentux/tools/base.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/agentux/tools/base.py')
-rw-r--r--src/agentux/tools/base.py51
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"]