liveBook · Manning

Asyncbasetool

As explained in Build a Multi-Agent System (from Scratch)

AsyncBaseTool is a framework base class for tools whose operations execute asynchronously and can avoid blocking while awaiting external results.

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

How Build a Multi-Agent System (from Scratch) covers it

How deep it goes
Defines tool metadata and an asynchronous call interface, then explains coroutine invocation without detailing event-loop internals.
Examples
Uses external weather-data lookup and an awaited Hailstone tool call as examples.
What it assumes
Introduces async functions, coroutines, and await while relying on the surrounding tool-call abstraction.
What you can do after
Build it from scratch by implementing asynchronous tool metadata and execution, then await calls from async code.
How it connects
Connects tool calls with ToolCall, ToolCallResult, JSON Schema, BaseTool, and asyncio.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build a Multi-Agent System (from Scratch). The section links point to the parts of the book it draws on.