Papa Programmer
Lesson 18 of 20

Testing an agent

8 min read

Optional

Why one run proves nothing

A normal function returns the same output for the same input. An agent does not. The model can pick a different step from one run to the next, so a task that passed today may fail tomorrow with no change in the code.

That means a single passing run tells you very little. What you need is a rate: out of ten runs, how many reached the right result? Measure that rate before and after each change to see whether the change helped.

Build an evaluation set

An Evaluation setA list of tasks, each with a way to check the result, that you run again after every change to an agent. You measure how often the agent gets each task right. is a list of tasks, each paired with a way to check the result. Begin small. Twenty tasks that reflect real use are worth more than two hundred invented ones.

Include three kinds of case.

  • Typical tasks. The everyday requests the agent will see most.
  • Hard tasks. Cases where the agent failed before. Add every real failure to the set, so that it cannot come back without notice.
  • Tasks it should refuse. Requests the agent must decline or hand to a person.

Check the outcome, then the path

Prefer checks on the outcome, because many paths can be right. Did the agent produce the correct order number? Is the file changed in the right way? Does the test suite pass?

Also check the path where it matters. Did the agent stay under ten steps? Did it avoid the forbidden tool? Did it ask for approval before the refund?

python
def run_agent(task):
	return {"answer": "1042", "steps": 4, "tools_used": ["search_orders"]}

cases = [
	{"task": "Find the order for Mia", "expect": "1042", "max_steps": 6, "forbidden": ["refund_order"]},
]

def passes(case, result):
	return (
		result["answer"] == case["expect"]
		and result["steps"] <= case["max_steps"]
		and not set(result["tools_used"]) & set(case["forbidden"])
	)

runs = 10
results = [passes(cases[0], run_agent(cases[0]["task"])) for _ in range(runs)]
print(f"{sum(results)}/{runs} passed")

Here run_agent is a stand-in that always succeeds, so the output is 10/10 passed. With a real agent the rate will be lower, and that number is what you watch.

Run it on every change

Treat the evaluation set like a test suite. Run it after you change the instructions, a tool, the model or the history logic. Compare the pass rate with the last run. If it fell, the change hurt, even if the one example you tried by hand looked better.

When the rate is high but users still complain, the set is missing their cases. Add them. An evaluation set is never finished, because real use keeps finding new ways to fail.

Repeat each caseRun every task several times and report a pass rate, not one result.
Small, real, growingStart with twenty real tasks and add each new failure to the set.
Outcome firstCheck the result, and check the path only where the path matters.

Your reading position is saved

0%

0 of 20 complete

Contents

Learning tools