AsyncBaseTool is an abstract base class for tools whose operations execute asynchronously. It suits work such as external API calls: while a tool waits for a result, other application code can continue running. section 2.1.3
Its interface standardizes tool metadata and execution:
- Provide a name, description, and JSON Schema for the tool’s input parameters. section 2.1.3
- Implement async __call__ to accept a ToolCall and return a ToolCallResult. section 2.1.3
- Call the tool with await from asynchronous code. A coroutine called from synchronous code can be run with asyncio.run(). section 2.1.3
Listing 2.4 Implementing AsyncBaseTool
# llm_agents_from_scratch/base/tool.py
from abc import ABC, abstractmethod
from llm_agents_from_scratch.data_structures.tool import (
ToolCall,
ToolCallResult,
)
class BaseTool(ABC):
"""Base Tool Class."""
… #A
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__( #B
self,
tool_call: ToolCall,
*args: Any,
**kwargs: Any,
) -> ToolCallResult:
"""Asynchronously execute the tool call."""Inspect the abstract class declaration, including its metadata properties and asynchronous call signature. section 2.1.3
Awaiting a tool call
A Hailstone tool implemented with AsyncBaseTool can be invoked as `await hailstone_tool(tool_call)`. section 2.1.3
