Skip to the workspace
Pebellslearn by building
Agent Patterns, Testing and Guardrails  ›  Lesson

Testing Agents — Tools, Flows and Human Review

Unit Testing for Individual Tools 15 minAgents are tested in layers: unit tests for individual tools, integration tests that check outcomes and properties of whole flows, and human review for judgement that code cannot make.

ai agents / Testing Agents — Tools, Flows and Human Review

Explore each scene at your own pace.

01 · The rule

The rule

Testing Agents — Tools, Flows and Human Review

A small change to Tripmate's prompt makes it write dates as "16/10/2026". The prompt reads fine, the demo looks fine, and a week later bookings start failing because the railway tool expects "2026-10-16". An agent has many moving parts, and each kind of part needs its own kind of test.

The rule

Test tools like code, flows by outcome, and quality with people.

Three layers, from cheapest to most expensive:

  • Unit tests for individual tools — tools are ordinary functions, so test them without any model at all. Feed fixed inputs, check exact outputs and errors. Fast, repeatable, and they catch most plain bugs.
  • Integration tests for flows — run the whole agent on a scripted request, with outside services replaced by fakes that return known data. Because model wording varies from run to run, check outcomes and properties, not exact text: the right tool was called, with valid arguments, the booking stayed within budget, the agent asked before paying.
  • Human-in-the-loop evaluation — people review a sample of real or realistic conversations for things code cannot judge well: was the advice sensible, was the tone right, did it misunderstand the user? Their verdicts become new test cases.

Some teams add a self-critique step inside the agent — a second model call that checks a draft answer against the goal before it is sent. It helps, but it is not a replacement for tests, because the checker can share the same blind spots.

def test_search_trains_rejects_bad_date():
    result = search_trains(frm="PUNE", to="JP", date="16/10/2026")
    assert result["error"] == "date must be YYYY-MM-DD"

def test_booking_flow_stays_in_budget():
    run = run_agent("Cheapest train Pune to Jaipur on 16 Oct, max ₹2,500", fakes=TIMETABLE_FAKES)
    assert run.called("search_trains")
    assert run.booking_total() <= 2500
    assert run.asked_user_before("book_ticket")
Scene 1 of 5
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.