liveBook · Manning

ToolCallResult

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

ToolCallResult is a framework data structure that records a tool-call identifier, its execution result, and whether an error occurred.

ToolCallResult records the output of a tool call so an agent can match it to the request and return it to the LLM. A BaseTool accepts a ToolCall through __call__() and returns one ToolCallResult. section 2.1 section 2.5

The Python implementation extends pydantic.BaseModel and defines three fields:

Listing 2.2 Implementing ToolCallResult
# llm_agents_from_scratch/data_structures/tool.py
import uuid
from typing import Any
 
from pydantic import BaseModel, Field
 
 
…  #A
 
class ToolCallResult(BaseModel):
    """Result of a tool call execution.
 
    Attributes:
        tool_call_id: The id of the associated tool call.
        content: The content of tool call.
        error: Whether or not the tool call yielded an error.
    """
 
    tool_call_id: str  #B
    content: Any | None  #C
    error: bool = False  #D

The implementation defines the field types and the default error flag. section 2.1.1

A successful execution puts its output in content and sets error to False. A basic failure representation uses content=None and error=True. Individual tools can provide more detail: SimpleFunctionTool returns a JSON-serialized error description in content when argument validation or function execution fails. section 2.1.1 section 2.2.1

Return a hailstone step

For a ToolCall with arguments {"x": 3}, the hailstone tool computes 10 and returns ToolCallResult(tool_call_id=tool_call.id_, content=10, error=False). The identifier links the result to the original request. section 2.1.2

To continue a chat, pass one or more results and the chat history to continue_chat_with_tool_results(). It creates TOOL-role ChatMessage objects from the results and returns them alongside the LLM’s response; append both to the running history. section 3.1.2 section 3.2.2

The same result interface can carry remote-agent responses. An A2A tool converts a remote response into ToolCallResult; its content can also indicate that the remote agent needs further input. section 10.2.2 section 10.2.3

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

How deep it goes
Defines the Pydantic fields and traces success, validation failure, execution failure, and chat continuation.
Examples
Uses a web-search result and a hailstone tool call to demonstrate result construction and return.
What you can do after
Build it from scratch as a Pydantic model and use it to return tool results to an LLM.
How it connects
Connects tool calling with BaseTool, ToolCall, chat messages, and A2A.

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.