Skip to content

Tool ABC

pycodeloop.abc.tool.Tool

Bases: ABC

Action the agent can take. Set dangerous = True on subclasses that change state (filesystem, shell, remote calls) so Agent asks for confirmation before running them.

Source code in pycodeloop/abc/tool.py
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
class Tool(ABC):
    """Action the agent can take. Set `dangerous = True` on subclasses that
    change state (filesystem, shell, remote calls) so Agent asks for
    confirmation before running them."""

    name: str
    description: str
    parameters: dict[str, Any] = {"type": "object", "properties": {}}
    dangerous: bool = False

    def schema(self) -> dict:
        return {
            "name": self.name,
            "description": self.description,
            "parameters": self.parameters,
        }

    def preview(self, **kwargs) -> str:
        """Human-readable summary of what `run(**kwargs)` would do.

        Shown to the user in a confirmation prompt before a dangerous tool
        actually runs. Override for a diff, a shell command line, etc.
        """
        return ", ".join(f"{key}={value!r}" for key, value in kwargs.items())

    @abstractmethod
    def run(self, **kwargs) -> ToolResult:
        raise NotImplementedError

dangerous = False class-attribute instance-attribute

description instance-attribute

name instance-attribute

parameters = {'type': 'object', 'properties': {}} class-attribute instance-attribute

preview(**kwargs)

Human-readable summary of what run(**kwargs) would do.

Shown to the user in a confirmation prompt before a dangerous tool actually runs. Override for a diff, a shell command line, etc.

Source code in pycodeloop/abc/tool.py
33
34
35
36
37
38
39
def preview(self, **kwargs) -> str:
    """Human-readable summary of what `run(**kwargs)` would do.

    Shown to the user in a confirmation prompt before a dangerous tool
    actually runs. Override for a diff, a shell command line, etc.
    """
    return ", ".join(f"{key}={value!r}" for key, value in kwargs.items())

run(**kwargs) abstractmethod

Source code in pycodeloop/abc/tool.py
41
42
43
@abstractmethod
def run(self, **kwargs) -> ToolResult:
    raise NotImplementedError

schema()

Source code in pycodeloop/abc/tool.py
26
27
28
29
30
31
def schema(self) -> dict:
    return {
        "name": self.name,
        "description": self.description,
        "parameters": self.parameters,
    }

pycodeloop.abc.tool.ToolResult dataclass

Source code in pycodeloop/abc/tool.py
10
11
12
13
@dataclass
class ToolResult:
    output: str
    is_error: bool = False

is_error = False class-attribute instance-attribute

output instance-attribute

__init__(output, is_error=False)