summaryrefslogtreecommitdiff
path: root/src/agentux/tools/base.py
blob: 5c13069cb210d087965e644fd7ed6fda4a90fc74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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"]