Skip to content

Tool

Base Tool.

BaseTool

Bases: ABC

Base Tool Class.

Source code in src/llm_agents_from_scratch/base/tool.py
class BaseTool(ABC):
    """Base Tool Class."""

    @property
    @abstractmethod
    def name(self) -> str:
        """Name of tool."""

    @property
    @abstractmethod
    def description(self) -> str:
        """Description of what this tool does."""

    @property
    @abstractmethod
    def parameters_json_schema(self) -> dict[str, Any]:
        """JSON schema for tool parameters."""

    @abstractmethod
    def __call__(
        self,
        tool_call: ToolCall,
        *args: Any,
        **kwargs: Any,
    ) -> ToolCallResult:
        """Execute the tool call.

        Args:
            tool_call (ToolCall): The tool call to execute.
            *args (Any): Additional positional arguments.
            **kwargs (Any): Additional keyword arguments.


        Returns:
            ToolCallResult: The result of the tool call execution.
        """

name abstractmethod property

name

Name of tool.

description abstractmethod property

description

Description of what this tool does.

parameters_json_schema abstractmethod property

parameters_json_schema

JSON schema for tool parameters.

__call__ abstractmethod

__call__(tool_call, *args, **kwargs)

Execute the tool call.

Parameters:

Name Type Description Default
tool_call ToolCall

The tool call to execute.

required
*args Any

Additional positional arguments.

()
**kwargs Any

Additional keyword arguments.

{}

Returns:

Name Type Description
ToolCallResult ToolCallResult

The result of the tool call execution.

Source code in src/llm_agents_from_scratch/base/tool.py
@abstractmethod
def __call__(
    self,
    tool_call: ToolCall,
    *args: Any,
    **kwargs: Any,
) -> ToolCallResult:
    """Execute the tool call.

    Args:
        tool_call (ToolCall): The tool call to execute.
        *args (Any): Additional positional arguments.
        **kwargs (Any): Additional keyword arguments.


    Returns:
        ToolCallResult: The result of the tool call execution.
    """

AsyncBaseTool

Bases: ABC

Async Base Tool Class.

Source code in src/llm_agents_from_scratch/base/tool.py
class AsyncBaseTool(ABC):
    """Async Base Tool Class."""

    @property
    @abstractmethod
    def name(self) -> str:
        """Name of tool."""

    @property
    @abstractmethod
    def description(self) -> str:
        """Description of what this tool does."""

    @property
    @abstractmethod
    def parameters_json_schema(self) -> dict[str, Any]:
        """JSON schema for tool parameters."""

    @abstractmethod
    async def __call__(
        self,
        tool_call: ToolCall,
        *args: Any,
        **kwargs: Any,
    ) -> ToolCallResult:
        """Asynchronously execute the tool call.

        Args:
            tool_call (ToolCall): The tool call to execute.
            *args (Any): Additional positional arguments.
            **kwargs (Any): Additional keyword arguments.


        Returns:
            ToolCallResult: The result of the tool call execution.
        """

name abstractmethod property

name

Name of tool.

description abstractmethod property

description

Description of what this tool does.

parameters_json_schema abstractmethod property

parameters_json_schema

JSON schema for tool parameters.

__call__ abstractmethod async

__call__(tool_call, *args, **kwargs)

Asynchronously execute the tool call.

Parameters:

Name Type Description Default
tool_call ToolCall

The tool call to execute.

required
*args Any

Additional positional arguments.

()
**kwargs Any

Additional keyword arguments.

{}

Returns:

Name Type Description
ToolCallResult ToolCallResult

The result of the tool call execution.

Source code in src/llm_agents_from_scratch/base/tool.py
@abstractmethod
async def __call__(
    self,
    tool_call: ToolCall,
    *args: Any,
    **kwargs: Any,
) -> ToolCallResult:
    """Asynchronously execute the tool call.

    Args:
        tool_call (ToolCall): The tool call to execute.
        *args (Any): Additional positional arguments.
        **kwargs (Any): Additional keyword arguments.


    Returns:
        ToolCallResult: The result of the tool call execution.
    """