Agents, Tool Use & MCP·Question 34 of 90Intermediate

How do you test an agent in CI? Not evals - CI, on every pull request, in under five minutes.

Type it the way you would explain it to an interviewer. A few sentences is enough; you can't break anything.

Model answer: the part to lead with

Evals and tests are different jobs, and conflating them is why teams end up with neither. Evals measure quality on a distribution: slow, expensive, noisy. CI tests catch regressions deterministically and must be fast. You need both, in different pipelines.

Full worked answer

Evals and tests are different jobs, and conflating them is why teams end up with neither. Evals measure quality on a distribution: slow, expensive, noisy. CI tests catch regressions deterministically and must be fast. You need both, in different pipelines.

My layering:

Layer 1: everything that is not the model. Tool implementations are ordinary functions. Unit test them with no LLM anywhere near: schema validation, argument coercion, error formatting, pagination, truncation. This is most of your agent's surface area and it costs zero tokens.

Layer 2: the loop with a scripted model. Replace the LLM with a stub returning a fixed sequence of tool calls. Now you deterministically test the machinery: does max-iterations fire, does the budget guard trip, does a tool exception become a tool result rather than a crash, does a duplicate call get caught, does the approval gate block the write.

def test_budget_stops_loop():
    model = ScriptedModel([
        tool_call("search", {"q": "x"}),
        tool_call("search", {"q": "y"}),
    ])
    result = run_agent("...", model=model, max_cost_usd=0.01)
    assert result.stopped_reason == "budget_exceeded"

Layer 3: recorded trajectories (cassettes). Capture real LLM and tool responses once, replay on every PR. Catches prompt-template breakage, serialization changes, parsing bugs, at zero cost. Known weakness: cassettes go stale and stop reflecting real model behaviour, so they verify plumbing, not prompt quality. Re-record on a schedule.

Layer 4: a small live smoke set. Ten to twenty tasks against the real model, on merge to main rather than every PR, with loose assertions on final state rather than exact strings.

The full eval suite (trajectory judging, pass^k over a real task set) runs nightly or pre-release, because it takes minutes to hours and its variance makes a per-PR gate flaky enough that people start ignoring it. The rule I would state: CI gates on determinism, evals gate on releases.

What a good answer covers

  • Evals and tests are different jobs, and conflating them is why teams end up with neither
  • Evals measure quality on a distribution: slow, expensive, noisy
  • CI tests catch regressions deterministically and must be fast
  • You need both, in different pipelines
  • Layer 1: everything that is not the model

Key terms: Layer 3: recorded trajectories (cassettes)

Interviewer follow-ups to expect

  1. Your cassettes drift from real model behaviour and CI passes while prod breaks. How do you detect that?

  2. How do you write assertions for an agent whose output is legitimately different every run?

Worked answer from AI-Engineer-Interview-Questions by Om (MIT), reformatted for LLM Prep · answer text last updated 6 November 2026 · scoring and review schedule by LLM Prep