liveBook · Manning

Error analysis

As explained in Build an AI Agent (From Scratch)

Error analysis is a record field explaining why a problem-solving attempt failed.

Error analysis records why a problem-solving attempt failed and identifies an alternative action. In an agent, it turns a failed tool call into guidance for the next decision instead of another repetition. section 7.3.3 section 7.4

Use error analysis in two connected roles:

  • During execution, record the failure cause and a replacement strategy in context so the agent can choose another tool or approach. section 7.4
  • After execution, store the failure explanation with the task, approach, answer, and correctness result as structured memory. section 6.4.2
  • Across deployments, funnel recurring failures through taxonomy, rubrics, and metrics to improve the evaluation dataset. section 10.4.2

Recovering from a failed research tool

A Wikipedia tool raises “Wikipedia service is temporarily unavailable.” Reflection records: “Cause: service unavailable. Alternative: use web search.” The agent then calls search_web rather than retrying Wikipedia until max_steps. section 7.3.3

Listing 6.27 TaskMemory schema definition
class TaskMemory(BaseModel):
    """Structured memory for GAIA problem-solving records"""

    task_summary: str = Field(description="What the problem asked")
    approach: str = Field(description="Methods and tools used to solve it")
    final_answer: str = Field(description="The agent's submitted answer")
    is_correct: bool = Field(description="Whether the answer was correct")
    error_analysis: str | None = Field(
        default=None, 
        description="Why the attempt failed, if it did"
    )

    def to_embedding_text(self) -> str:
        """Generate text for vector search"""
        return f"Task: {self.task_summary}"

Inspect the TaskMemory schema to see error_analysis implemented as an optional field alongside the task summary, approach, final answer, and correctness flag. section 6.4.2

How Build an AI Agent (From Scratch) covers it

How deep it goes
Defines the field, demonstrates recovery behavior, and places it in an evaluation loop without specifying a complete taxonomy.
Examples
Uses a failing Wikipedia tool, a search alternative, a TaskMemory schema, and recurring operational failure patterns.
What it assumes
Assumes agent execution traces, tool calls, reflection, and structured output while treating failure recovery as the practical focus.
What you can do after
Diagnose/debug with recorded causes and alternatives, redirect failed agent actions, and preserve failures for later evaluation improvement.
How it connects
Connects reflection, tool calls, structured memory, vector search, taxonomy, rubrics, metrics, and evaluation datasets.

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.