liveBook · Manning

Trajectory

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

A trajectory, or rollout, is a record of an agent's task execution, including its actions and their results.

A trajectory, or rollout, records an agent’s task execution across its processing-loop steps. It can include the agent’s plans, tool calls, tool results, and conclusions. Unlike the final result returned to a user, the trajectory shows how the agent reached it, making it useful for debugging, evaluation, and improvement. section 1.3 section 4.5

In an LLMAgent implementation, TaskHandler maintains the rollout as a string. It starts empty; after each sub-step, _format_step_for_rollout() formats that step’s chat history and appends it. Step boundaries make the execution history easier to inspect. The formatter skips system messages, so the rollout is a formatted record rather than an unfiltered chat transcript. section 4.2.3

The rollout also provides context for subsequent steps: get_next_step() uses it when deciding what to do next, and run_step() can include it in the system message. Execution continues until the task completes or a stopping condition, such as a maximum step count, is reached. section 4.2.3 section 1.3

Inspecting a Hailstone rollout

For a task starting at 4, the agent calls next_number on 4 and then 2, stopping when the tool returns 1. The final TaskResult contains 4 → 2 → 1; printing handler.rollout exposes the marked sub-steps and tool interactions used to produce it. section 4.3

=== Task Step Start ===
 
💬 assistant: My current instruction is 'CALL `next_number` on the current number x=2'
 
💬 assistant: I need to make the following tool call(s):
 
{
    "id_": "7d529c53-2da2-49c7-a538-abfa8217cd62",
    "tool_name": "next_number",
    "arguments": {
        "x": 2
    }
}.
 
🔧 tool: {
    "tool_call_id": "7d529c53-2da2-49c7-a538-abfa8217cd62",
    "content": "1",
    "error": false
}
 
💬 assistant: The `next_number` function returned the number 1 when called with x=2. 
 
Now, I will provide the complete sequence observed from start to finish: Starting at x = 4 and ending with x = 1.
 
Here is the sequence:
```
4 -> 2 -> 1
```
 
Since we received the final number 1 as requested by the instruction, no further calls are needed. The task can now be considered complete.
 
=== Task Step End ===

Inspect the second sub-step’s instruction, tool-call arguments, result, and completion message. section 4.3

Long rollouts consume context-window space. A subagent can execute a subtask with its own isolated rollout and return only the result to the delegating agent. Rollouts can also expose interactions absent from the final answer, such as a remote agent requesting additional input and a subsequent call to resume its task. section 9.1.1 section 10.2.3

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

How deep it goes
Defines trajectories and implements per-step accumulation and formatting, while leaving some rollout implementation detail unexplored.
Examples
Illustrates rollouts with croissant searches, Hailstone tool calls, and a remote agent’s request for additional input.
What you can do after
Diagnose/debug agent executions by inspecting step boundaries, tool calls, results, and remote-agent interactions in the rollout.
How it connects
Connects trajectories to processing loops, tool calling, context management, subagents, and agent-to-agent interoperability.

Also explained in

Compare how 25 books explain trajectory →

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.