liveBook · Manning

Chapter 7: Building robust agents with evaluation and feedback

What you will learn in chapter 7 of AI Agents in Action, Second Edition

The introduction explains why evaluation and feedback matter for robust agents, what kinds of signals they provide, and why they should be considered throughout development.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction explains why evaluation and feedback matter for robust agents, what kinds of signals they provide, and why they should be considered throughout development.

Key terms: evaluation, feedback, robustness, benchmark, red team testing, grounding checks, evaluator agents, human reviewers, test outputs, evaluation and feedback

7.1 Introducing agent evaluation and feedback

This section maps how agents receive evaluation and feedback, matches evaluation methods to different kinds of correctness, and explains why multi-agent evaluation needs governance.

Key terms: Learn step, in-loop evaluators, evaluation database, deterministic test cases, LLM and agent evaluators, human evaluators, red team testing, benchmark testing, human feedback, statistical aggregation

7.2 Implementing test-driven agent development

This section explains how to define benchmarks before building an agent, test both its answers and behavior, and iteratively improve it without losing earlier successes.

Key terms: test-driven agent development, TDAD, rubrics, input benchmarks, expected responses, known-bad responses, intermediate behavior, tool calls, grounded, latency

7.2.1 Exploring TDAD in practice

The section illustrates test-driven agent development with a RAG agent that answers benchmark questions and has its answers evaluated.

Key terms: RAG agent, searchable words and phrases, knowledge base, context, benchmarks, evaluator, expected and incorrect answer candidates, passed or failed

7.2.2 Coding and testing the RAG agent

This section establishes a minimal benchmark-tested RAG agent and explains why apparent passes must be repeated to check consistency.

Key terms: benchmarks table, string matching, role/persona, TDAD, benchmarks, TDD, LLMs, variability, consistency

7.2.3 Refactoring the agent

This section uses benchmark results and traces to refactor a RAG agent, then shows how an overly strict evaluator can make correct answers appear wrong.

Key terms: tool metadata, output type, structured output, instruction prompt, benchmarks, baseline, agent’s instructions, trace output, retrieval, query-refinement step

7.2.4 Extending evaluation with an agent evaluator

This section replaces a word-matching benchmark evaluator with an agent evaluator that scores natural-language RAG answers, then notes a limitation of that score.

Key terms: agent evaluator, strongly typed pass/fail result, key term, benchmark, evaluation loop, dictionary, expected key term, wrong answer example, benchmark score, database

7.3 Employing grounding, critic, and evaluation agents

This section distinguishes grounding, critic, and rubric-based evaluation of agent output and explains why failed evaluations need context-appropriate handling.

Key terms: grounding agent, RAG, retrieval agent, context, critics, criteria, rubric, regeneration, retry ceiling, static fallback response

7.3.1 Reviewing the grounding agent

This section reviews how a grounding agent checks a RAG answer against shared context and how its results can be handled.

Key terms: grounding, retrieved knowledge context, RAG agent, grounding guardrail agent, grounding results, feedback, critic, approve or block, static answer

7.3.2 Grounding the RAG agent

This section shows how a reusable grounding agent uses the context behind a RAG answer to provide feedback, then checks that feedback against benchmark outputs.

Key terms: grounding agent, last context, knowledge agents, agent benchmarks, grounding output, final output, provided context

7.3.3 Implementing grounding agents as guardrails

This section shows how to use a grounding agent as an output guardrail for a RAG agent and handle answers that fail the grounding check.

Key terms: grounding agent, output guardrail, tripwire-triggered property, context, try/except block, static response, feedback, RAG agent

7.3.4 Understanding the role of rubrics in evaluation

This section explains how to choose evaluation methods for different agent outputs, build and validate rubrics, and retain the evidence needed to improve evaluations.

Key terms: structured outputs, known target, accuracy, precision, recall, F1 score, rubric, objectives, criteria, rating scale

7.3.5 Building a rubric critic agent

This section uses an image-generation example to show how a rubric critic evaluates outputs, controls retries, and uses a calibrated passing threshold.

Key terms: ImageGenerationTool, critic agent, style guidelines rubric, describe_image, rubric, criteria, pass/fail evaluation, hallucination rate, tool usage correctness, style guidelines

7.4 Phoenix for evaluation and feedback

This section introduces Phoenix as a way to observe and evaluate agents, explains why trace-level visibility matters, and places it among other observability options.

Key terms: trace-level observability, Arize Phoenix, token usage, tool usage, latency, experiments, evaluators, metadata, annotations, Phoenix

7.4.1 Connecting to Phoenix

Shows how to connect OpenAI Agents tracing to Phoenix and inspect agent activity in its dashboard.

Key terms: Phoenix, OpenTelemetry, set_trace_processors, Phoenix trace provider, trace function, Agents project, Traces page, agent workflow, latency, token usage

7.4.2 Adding metadata and session tracking

Shows how to attach session and metadata context to agent traces, then use Phoenix to find traces relevant to an evaluation.

Key terms: using_session, using_metadata, agent trace, LLM traces, Phoenix, Agents project, Metadata column, Columns selector

7.4.3 Experimenting with evaluators

This section shows how to turn Phoenix traces into a dataset and run a basic evaluation experiment as part of TDAD’s feedback loop.

Key terms: Phoenix, outer loop, TDAD, traces, datasets, evaluators, spans, Add to Dataset, Create Dataset, Run Experiment

7.4.4 Providing feedback with annotations

This section shows how Phoenix annotations turn feedback on agent traces into structured signals for analysis and regression testing.

Key terms: annotations, Traces page, span, LLM responses, structured labels, queryable signals, trace data, latency, cost, token usage

7.5 Exercises

This section gives five hands-on exercises that take a RAG agent from baseline benchmarking through refactoring, evaluation, grounding checks, and Phoenix tracing.

7.6 Summary

The chapter summary brings together testing, automated evaluation, grounding, and observability as an ongoing feedback loop for building robust agents.

Where this is used later

Concepts explained in this chapter

← Chapter 6: Working with memory and knowledge RAG for agents Chapter 8: Deploying agents and agentic systems →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.