liveBook · Manning

Test-driven agent development

As explained in AI Agents in Action, Second Edition

Test-driven agent development is an iterative methodology for building an agent by defining evaluation goals and incrementally adding the instructions and tools needed to satisfy them.

Test-driven agent development (TDAD) starts by deciding what a good agent run looks like, then building toward it. Like test-driven development, it puts expectations before implementation. For agents, those expectations may be benchmarks or rubrics rather than ordinary unit tests. section 7.2

Work in a small loop:

  • Set goals and input benchmarks. Record expected responses and known-bad responses. section 7.2
  • Run the smallest agent against them. Expect early failures; add only the instructions or tools needed to address them. section 7.2.2 section 7.6
  • Retest and refactor. Run passing benchmarks repeatedly: one successful LLM response does not establish consistent behavior. section 7.2.2 section 7.6

Start with a knowledge question

A simple RAG agent is asked, “Nebula Forge engine spins what?” Its benchmark expects “antimatter” and marks “fusion” as wrong. The agent searches a small knowledge base and answers from what it finds; an evaluator checks the answer. The first version has only a role instruction, so failures show what capability to add next. section 7.2.1 section 7.2.2

Figure 7.3 Architecture of a simple RAG knowledge agent. The goal of the agent is to answer questions from a benchmark by searching its knowledge base and returning answers. A simple evaluator LLM evaluates the answer based on the expected and incorrect answers from the benchmark test. The accuracy of the RAG agent can be determined by the percentage of benchmark questions it answers correctly.

The diagram traces one benchmark question through knowledge-base search, the agent’s answer, and evaluation against expected and incorrect answers. section 7.2.1

Test the run, not just its final wording. Tool choice, grounding, steps, latency, cost, and failure behavior can matter even when an answer looks correct. Simple string matching is a starting point; evaluation agents can assess complex answers against criteria and return feedback. If benchmarks conflict, choose a partial-pass target, split responsibilities, or rethink the instructions rather than endlessly adding prompt text. section 7.2 section 7.6

How AI Agents in Action, Second Edition covers it

How deep it goes
Works through benchmark-first iteration, repeated tests, and refactoring; starts with string matching before suggesting evaluators for complex outputs.
Examples
Uses a Python RAG agent, fictional knowledge-base questions, expected answers, and known-wrong answers.
What it assumes
Starts with a minimally instructed question-answering agent and separates ordinary software tests from agent benchmarks.
What you can do after
Build it from scratch by setting benchmarks, testing a minimal agent, adding necessary capabilities, and rerunning tests for consistency.
How it connects
Connects test-driven development, benchmark testing, rubrics, retrieval-augmented generation, grounding checks, and evaluator agents.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI Agents in Action, Second Edition. The section links point to the parts of the book it draws on.