Agents and AutomationLesson 36 of 72

Module 4 · Surviving real data

Testing something that is not deterministic

In this lesson

  • 9 min read
  • 4 reading sections
  • Knowledge check
  • Lesson 8 of 9 in this chapter

This chapter’s goalDiagnose a failing agent run from its trace and apply the specific fix it needs: a retry policy, a validator, a shorter chain, or no loop at all.

This chapter’s media

The film explains chapter ideas. The audiobook narrates the complete teaching text.

FormatEnglishहिंदी
Chapter filmNot availableNot available
Full audiobookNot availableNot available

A little at a time

Explore an idea, try it, then check what stays.

Step 1 of 5Free · no account needed
Lesson steps

The objection, and the answer

“You cannot unit-test an agent, the model is non-deterministic.”

You cannot unit-test the model. You can absolutely unit-test the harness, and the harness is where nearly all of your bugs are. The trick is to hold the other variable still.

Record and replay

Run the agent once, for real, with recording on. Every tool call and its result is written to a file keyed by tool name and canonical arguments.

Text
tests/fixtures/refund_happy_path.jsonl
  {"tool":"get_order","args":{"order_id":"ORD-48213"},"result":"{\"status\":\"shipped\"...}"}
  {"tool":"refund_order","args":{"order_id":"ORD-48213","amount":2499},"result":"{\"ok\":true...}"}

On replay, the harness serves results from the file and never touches the network. Now the run is fast, free, offline, and repeatable: this is the same technique HTTP-testing libraries have called cassettes for years, applied one level up.

Two things to get right: redact secrets and personal data at record time, and record the failures too. A fixture directory of only happy paths tests the least interesting third of your code.

Your place and first choices stay on this browser. Classroom credit is recorded separately.

Every lesson here is open. Your progress is recorded once you pass the Context Engineering exam.

Stuck on something?Ask Mai, your AI tutor

How to cite: Addaly (2026) ‘Testing something that is not deterministic’, in Agents and Automation. Edited by M. Mun. Addaly. Available at: https://addaly.com/learn/agents-and-automation/testing-with-replay (Accessed: 29 November 2026).