7 Reflection and evaluation: How your agent audits and learns from itself
The chapter presents reflection as the disciplined use of feedback that is allowed to change something, whether that means revising a current artifact, repairing a failed run, admitting a reusable capability, or storing a lesson for later use. Its central warning is that local fixes can look successful while quietly accumulating cost, complexity, or conflicting rules across many runs. To avoid that trap, the text emphasizes that reflection must be paired with explicit evidence, clear authority, and a stop policy that prevents endless iteration or overcorrection.
One major theme is separating production from review. For the current task, Generator-Critic improves an artifact by using a review path with independent criteria and evidence, while Self-Heal Loop repairs bounded execution only inside a protected recovery envelope. In both cases, the reviewer or verifier must see something the producer did not, and the system must preserve the best known version, support rollback, and stop when progress stalls. The chapter also shows that better evaluation is not just another pass: it requires grounded checks, calibrated rubrics, protected tests, and measurements like confirmed-issue precision, regression rate, latency, and cost.
The other major theme is cross-task learning. Skill Package turns a successful procedure into a versioned capability that can be routed later only after isolated, coexistence, and trial evidence support it, while Experience Replay stores traces and distills scoped lessons that may be recalled only when task, version, and trigger conditions match. Both patterns insist on provenance, conflict tracking, and reversible retirement so that admitted knowledge remains useful without becoming unsafe or stale. Taken together, the chapter shows how an agent can audit itself, recover from failure, and learn from experience without granting itself unlimited authority over its own evidence or behavior.
The Generator-Critic chain. The Critic receives one artifact version, explicit criteria, and evidence; a bounded return permits another review.
The Self-Heal Loop. The agent captures a baseline, diagnoses a failure, checks repair authority, applies a change atomically, verifies it, and either recovers, retries, rolls back, or hands off.
Skill admission and maintenance. A trace proposes a candidate; isolated, coexistence, and trial gates control activation; operating evidence supports refinement, merging, demotion, deprecation, retirement, and rollback.
The Experience Replay hierarchy and recall path. Raw traces support candidate lessons; evidence admits scoped heuristics; task and trigger filters decide whether a replayable lesson enters live context.
Reflection patterns compose through traces and separate gates. Current-task review and recovery produce evidence; capability admission and replay admission control what later tasks may use.
The evaluation evidence stack. Structural checks, deterministic verifiers, traces, invariants, semantic review, human evidence, and real outcomes cover progressively different questions and feedback latencies.
Summary
- Reflection connects feedback to a permitted change. The design specifies what the feedback can see, when the result arrives, what the loop may change, and what evidence is required to retain that change.
- Generator-Critic improves a current artifact. Independence comes from a different review frame, criteria, context, or evidence, rather than agent count alone.
- Self-Heal Loop has greater recovery authority. It verifies each repair, preserves a rollback path, stops at a bounded limit, and hands control to a person when the recovery boundary is reached.
- Skill Package admits executable capability. Promotion requires isolated, coexistence, and trial evidence; routing first filters by permission, risk, dependency, and applicability.
- Low use sends a Skill to review. Retirement requires stronger evidence and a reversible path, and consequential scope changes require human approval.
- Experience Replay separates raw traces, candidate lessons, and replayable heuristics. Recording, replay admission, and runtime recall are separate decisions.
- Experience remains advisory. Recall occurs before planning for selected high-risk or repeated tasks and during recovery after a relevant trigger.
- Evaluation is part of each pattern's change path. Deterministic checks, traces, semantic review, invariants, human evidence, and real outcomes cover different scopes and feedback latencies.
- A hard regression cannot be hidden by an aggregate score. Cost, latency, state change, and human effort belong alongside task success.
- Each safeguard in the opening case passed its local check while the complete system became slower and more conflicted. Cross-run review and explicit retirement authority turn local reflection into system learning.
Designing AI Agents ebook for free