Every module so far has been tested by hand: run it, type a message, eyeball the reply. That doesn’t scale, and it silently breaks when you tweak a prompt or swap a model. This module builds a small eval harness with two kinds of checks.
calculate for math, not for pet names).def run_agent(goal: str) -> dict:
...
return {"text": final_reply, "tools_called": [...]}
Returning both the final text and which tools were called (not just the text) is what makes the deterministic checks possible — you’re testing behavior, not just output. “Did it get the right answer” and “did it get there the right way” are different questions, and an eval suite that only checks final text misses agents that get lucky via the wrong path.
The judge is deliberately forced to answer through a tool call instead of free text:
response = client.messages.create(
tools=[JUDGE_TOOL],
tool_choice={"type": "tool", "name": "submit_verdict"},
...
)
tool_choice forcing a specific tool guarantees a structured {"passed": bool, "reason": str} back — no parsing a judge’s prose to guess whether it meant “pass” or “passed, but…”. This is the same structured-output trick usable anywhere you’d otherwise regex a model’s free-text reply.
exercise.py — fill in check_tool_was_called, check_output_contains, and judge_response.solution.py — the completed reference implementation.pip install -r requirements.txt
export ANTHROPIC_API_KEY=your_key_here
python exercise.py # after filling in the TODOs — exits 1 if any test fails
python solution.py # to compare against a working version
You’ve gone from a single stateless API call, through tools, memory, specialization, and safety guardrails, to orchestrating multiple agents, streaming output, grounding answers in retrieved data, and testing that all of it actually works. That’s the full loop a working agent goes through — the remaining modules cover what changes once that agent needs to run efficiently, connect to more tools, and stay up for a long time.
Module 10 — Prompt Caching & Cost Optimization — cutting the cost of resending the same large context on every call.