liveBook · Manning

Event

As explained in Build an AI Agent (From Scratch)

An event is a structured record that wraps an execution content item with metadata about its producer and occurrence time.

An event records one occurrence during agent execution. It wraps typed content—such as a message, tool call, or tool result—with an identifier, execution identifier, timestamp, and author. Grouping events by execution_id creates a complete audit trail for debugging and analysis. section 4.3.1

Use events to represent the main parts of an agent trace:

  • Store user and assistant exchanges as Message content with a role and text. section 4.3.1
  • Store model requests as ToolCall content, including the tool name, arguments, and tool_call_id. section 4.3.1
  • Store execution outcomes as ToolResult content with success or error status, output, and the originating call identifier. section 4.3.1
  • Add model responses and tool outcomes to the execution context as separate events during each think–act cycle. section 4.6.3

Tracing a tool call

For the question about Kipchoge running to the Moon, the agent records a user message, a search_web ToolCall, its ToolResult, further research and calculation calls, and the final assistant message. Each event identifies the producing actor and belongs to the same execution. section 4.3.1

Listing 4.3 Event class for execution tracking
class Event(BaseModel):
    """A recorded occurrence during agent execution."""
    id: str = Field(default_factory=lambda: str(uuid.uuid4()))
    execution_id: str
    timestamp: float = Field(default_factory=lambda: datetime.now().timestamp())
    author: str  # "user" or agent name
    content: List[ContentItem] = Field(default_factory=list)

The Event model shows the minimal Python representation: generated identity and timestamp, execution grouping, author, and a list of typed content items. section 4.3.1

How Build an AI Agent (From Scratch) covers it

How deep it goes
Defines a Pydantic record with identity, execution grouping, timestamps, authorship, typed content, and run-loop integration.
Examples
Uses a Kipchoge research trace, calculator and search tool calls, user input events, and final assistant responses.
What it assumes
Assumes typed content models and an agent execution loop, while defining event recording from the execution trace.
What you can do after
Build it from scratch by wrapping user input, model responses, and tool results in events and inspecting AgentResult.context.
How it connects
Connects messages, tool calls, tool results, execution context, agent steps, LLM requests, and observability traces.

Related concepts

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