Practical article
How to Test an AI Agent's Tool Calls
Code, failure boundaries, and a runnable exercise.
Python · Tool contracts · Failure recovery
Forthcoming book · Free lab available nowA Hands-On Python Guide to Testing, Evaluating, Debugging, and Recovering Production Agents
By Leandro Calado Ferreira
The tool commits an action. Its response disappears. Your agent retries.
Does the action happen twice?
Reproduce a duplicate synthetic credit after a lost tool response. Then use a stable operation identity and a local transaction to preserve one authorized effect.
| Controlled scenario | Broken retry | Corrected runner |
|---|---|---|
| Effects after a lost response | 2 | 1 |
| Total synthetic credit | 2,000 cents | 1,000 cents |
Results from a constructed deterministic incident, not a benchmark of model quality or production traffic.
Free · No account · No API key
Python 3.11+ with SQLite support. No pip packages or model calls. The archive includes source, MIT license, instructions, tests and the four articles.
cd agent-reliability-lab python -m unittest -v python lab.py demo python lab.py evaluate
Checked on Python 3.11, 3.12 and 3.13. Covers response loss, restart, concurrent delivery, changed payloads, authorization and attempt budgets.
Inspect the recorded test runThe synthetic effect and receipt share one SQLite transaction. Remote APIs still need their own idempotency and reconciliation strategy.
The book is being developed for readers who already know Python and APIs and need concrete ways to test what an agent is allowed to do, what actually happened, and how interrupted work resumes.
Tool schemas, trusted task facts, authorization, side effects and evaluation cases.
Traces, uncertain writes, operation identities, duplicate delivery and restart behavior.
The complete edition is in preparation. The opening chapters are a working sample. Real-model, multi-step, retrieval, MCP and cost/latency laboratories are still being completed.
The book is not yet available for purchase on Amazon. There is no preorder or payment required for these resources.
Learn by reproducing failures
Practical article
Code, failure boundaries, and a runnable exercise.
Practical article
Code, failure boundaries, and a runnable exercise.
Practical article
Code, failure boundaries, and a runnable exercise.
Practical article
Code, failure boundaries, and a runnable exercise.