From ed4889134aa77d912d7e0fc0d69f7def0dd772fc Mon Sep 17 00:00:00 2001 From: dev Date: Mon, 5 Oct 2026 16:40:10 +0530 Subject: Working agent before enhancements: 205 tests passing --- src/agentux/tools/base.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 src/agentux/tools/base.py (limited to 'src/agentux/tools/base.py') 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"] -- cgit v1.2.3