Skip to content

tool_action

ToolAction

Bases: BaseAction

Represents an instance of an LLM using a Tool.

Attributes:

Name Type Description
tag str

The tag (unique identifier) of the action.

name str

The name (Tool name) of the action.

path Optional[str]

The path (Tool activity name) of the action.

input dict

The input (Tool params) of the action.

tool Optional[BaseTool]

The matched Tool of the action.

output Optional[BaseArtifact]

The output (Tool result) of the action.

Source code in griptape/common/actions/tool_action.py
@define(kw_only=True)
class ToolAction(BaseAction):
    """Represents an instance of an LLM using a Tool.

    Attributes:
        tag: The tag (unique identifier) of the action.
        name: The name (Tool name) of the action.
        path: The path (Tool activity name) of the action.
        input: The input (Tool params) of the action.
        tool: The matched Tool of the action.
        output: The output (Tool result) of the action.
    """

    tag: str = field(metadata={"serializable": True})
    name: str = field(metadata={"serializable": True})
    path: Optional[str] = field(default=None, metadata={"serializable": True})
    input: dict = field(factory=dict, metadata={"serializable": True})
    tool: Optional[BaseTool] = field(default=None)
    output: Optional[BaseArtifact] = field(default=None)

    def __str__(self) -> str:
        return json.dumps(self.to_dict())

    def to_native_tool_name(self) -> str:
        parts = [self.name]

        if self.path is not None:
            parts.append(self.path)

        return "_".join(parts)

    @classmethod
    def from_native_tool_name(cls, native_tool_name: str) -> tuple[str, Optional[str]]:
        parts = native_tool_name.split("_", 1)

        if len(parts) == 1:
            name, path = parts[0], None
        else:
            name, path = parts

        return name, path

input: dict = field(factory=dict, metadata={'serializable': True}) class-attribute instance-attribute

name: str = field(metadata={'serializable': True}) class-attribute instance-attribute

output: Optional[BaseArtifact] = field(default=None) class-attribute instance-attribute

path: Optional[str] = field(default=None, metadata={'serializable': True}) class-attribute instance-attribute

tag: str = field(metadata={'serializable': True}) class-attribute instance-attribute

tool: Optional[BaseTool] = field(default=None) class-attribute instance-attribute

__str__()

Source code in griptape/common/actions/tool_action.py
def __str__(self) -> str:
    return json.dumps(self.to_dict())

from_native_tool_name(native_tool_name) classmethod

Source code in griptape/common/actions/tool_action.py
@classmethod
def from_native_tool_name(cls, native_tool_name: str) -> tuple[str, Optional[str]]:
    parts = native_tool_name.split("_", 1)

    if len(parts) == 1:
        name, path = parts[0], None
    else:
        name, path = parts

    return name, path

to_native_tool_name()

Source code in griptape/common/actions/tool_action.py
def to_native_tool_name(self) -> str:
    parts = [self.name]

    if self.path is not None:
        parts.append(self.path)

    return "_".join(parts)