- Home
- Skills
- Agents & Orchestration
- Agent Resilience: crash-safe, idempotent AI agents
Works with the AI Agents you already use
Agent Resilience: crash-safe, idempotent AI agents
Audits your AI agent for 8 production failure modes, then adds checkpoints, safe retries, an outbox, human approval, token budgets and cancel, and proves each fix with failure tests.
$12
Agent Resilience: crash-safe, idempotent AI agents
Example session with this skill installed
Audit the agent in this repo for production reliability. It's a Celery task that reads support tickets and can refund via Stripe and email the customer. Don't change code yet.
- Read your context and instructions
- Compiled the agent resilience
Agent reliability audit: naive-agent
Scope: agent.py, which is the whole project at 35 lines.
Stack: Python, Celery on Redis, the Anthropic SDK, Stripe and SMTP. There is no database.
Verdict
Score: 0/16. It is not ready for production. Under the audit rubric, a repeated side effect that costs money is a blocker on its own (F3 = 0). There are also two problems outside the rubric that matter more. Anyone who writes a ticket can choose which charge gets refunded and for how much. And the agent probably can't complete a refund conversation at all, because the request it builds is likely to be rejected by the API.
I only read the code. I didn't run it.
Problems outside the rubric (fix these first)
| # | Problem | Evidence |
|---|---|---|
| A | A ticket can trigger refunds and emails it shouldn't. The ticket text goes straight to the model as the only prompt. The model then picks charge_id, amount and to, and those go to Stripe and SMTP without any check. Nothing checks that the charge belongs to the person who wrote the ticket, nothing caps the amount, and nothing requires a human to approve. | agent.py:25, :13-14, :17-19, :32 |
| B | Tool definitions are probably invalid. "input_schema": {} has no "type": "object", no properties and no descriptions. | agent.py:10 |
| C | Responses with more than one tool call break the conversation. If the model asks for refund and email_customer in one response, the next API call fails, so the refund has gone through, but the customer never gets an email and the task errors out. | agent.py:31-34 |
| D | Ordinary errors crash the task. An unknown tool name raises KeyError, Stripe errors are never caught, and stop_reason values such as max_tokens aren't handled. | agent.py:30, :32 |
Scores
| # | Failure mode | Score | Evidence |
|---|---|---|---|
| F1 | Progress is lost on crash | 0 | The conversation is a local list (agent.py:25, :33-34) and is never saved. |
| F2 | The model re-decides a step after a crash | 0 | The decision isn't saved before the tool runs. After a redelivery the model starts again and may choose differently. |
| F3 | Side effects repeat on retry or resume | 0 (blocker) | stripe.Refund.create (:14) has no idempotency_key, and sendmail (:19) has no outbox. With acks_late=True (:23), a worker that dies after the refund gets the task redelivered: a second refund and a second email. |
| F4 | Two workers run the same run | 0 | No claim or lock. If a task runs past Redis's 1-hour visibility_timeout, a second worker gets the same ticket and both refund. |
| F5 | A worker writes after losing ownership | 0 | Ownership is never tracked. A stalled worker that wakes up still refunds and sends email. |
| F6 | Runs get stuck or lost | 0 | No run record outside the queue message. Without task_reject_on_worker_lost, an OOM-killed task disappears without a trace. |
| F7 | Failures unbounded or mis-handled | 0 | No timeouts (smtplib.SMTP at :18 can block forever), no retries or backoff. The run "finishes" as soon as the model replies with text. |
| F8 | Runaway runs and missing controls | 0 | while True (:26) has no step limit, token budget or loop detection. No approval before a refund, no cancel. |
Side effects inventory
| Tool / call | Location | What it does outside the process | Protected by |
|---|---|---|---|
refund → stripe.Refund.create | agent.py:14 | Moves money to the customer | Nothing |
email_customer → smtplib.sendmail | agent.py:18-19 | Sends email to any address the model chooses | Nothing |
Fixes, in order
Authorize refunds outside the model (A, F8). Accept a charge_id only if it belongs to the ticket's customer, cap the amount, and require human approval above a limit, releasing the worker while it waits. Email only the customer on file.
2.
Make refunds and emails safe to repeat (F3). Pass idempotency_key=f"{run_id}:{step_no}" to Refund.create. Write emails to an outbox table in the same transaction that marks the step complete.
3.
Fix the agent loop (B, C, D). Proper JSON schemas, one assistant message per response with all tool results in one user message, tool errors returned as is_error, handle stop_reason.
4.
Keep run state in a database (F1, F2, F4, F5, F6). runs and steps tables with a unique key per ticket, atomic UPDATE … RETURNING claim plus heartbeat, every write inside an ownership check, a reaper, and task_reject_on_worker_lost=True.
5.
Bound failures (F7). Timeouts on every tool and LLM call, limited retries for transient errors only, and a finish tool as the only way a run completes.
6. Add guards (F8). Step limit, per-run token budget, repeated-call detection and cancel.
Decisions for you
- Fixes 2, 4 and 5 need a database. Postgres or SQLite?
- Your refund policy: up to what amount can the agent refund on its own, and who approves above that?
- Do tickets have a stable ID I can use as the idempotency key?
I haven't changed any code. Answer the questions above and I'll make the fixes, including failure tests against a real database.
(Follow-up in the same project: after answering "SQLite, 50 USD, ticket_id", the skill retrofitted the agent and wrote 47 failure tests, including a real worker kill right after a refund that ends with exactly one refund.)
Connects securely to your tools. The creator never sees your data.
About this skill
Your agent works in the demo. Then a worker restarts mid-run and the customer gets refunded twice. Or a queue redelivers a job, two workers both send the email, and nobody can stop a run that's burning tokens.
This skill teaches your coding agent (Claude Code, Cursor, Codex, Copilot and others) to find and fix those failures in your own agent code:
- Audit: scores your agent loop on 8 failure modes (lost progress, re-decided steps, repeated side effects, double execution, zombie writers, stuck runs, unbounded failures, runaway runs), with
file:lineevidence and fixes in priority order. It includes an offline scanner that locates LLM calls, side effects and existing safeguards. - Retrofit: adds the patterns in the right order. That means a durable checkpoint before every tool call, an atomic lease with heartbeat and fencing, side-effect-free tools with an idempotent outbox, bounded retries and timeouts, a reaper, an explicit
finishtool, and human approval that doesn't block a worker. - Guards: per-run token budgets, no-progress loop detection, and a cancel that stops a worker mid-step before anything commits.
- Proof: chaos test recipes (simulated crash, 8 workers racing, stale worker waking up, hung tool, concurrent approve/cancel) that your agent writes against a real database.
Complete reference implementations for Python + Postgres, Node/TypeScript + Postgres and Python + SQLite (no Postgres needed). Each passes its own chaos test suite. It also covers how this maps onto Temporal, LangGraph and Celery: what they already guarantee, and what they don't.
Built from resilient-agent-runner, an open backend where every guarantee is tested, including a real SIGKILL demo.
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Agents & Orchestration.
Not for single-shot LLM calls or stateless chat with no tools. The retrofit needs a database you control (Postgres or SQLite); reference code is Python and Node/TypeScript, so other languages get the patterns but not ready-made code. The token budget counts planning calls only. Provider idempotency keys (for example Stripe's) expire after a while, so very late retries still rely on your own outbox.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed 18 days ago
- Software
Python 3.8+ (for the offline scanner)
PostgreSQLorSQLite (in your own project)Git
Permissions
The skill reads your agent's source files to audit it, edits them when you ask for a retrofit, and runs your test suite in the terminal. Its one script (scripts/scan_agent.py) uses the Python standard library only: it reads files and prints JSON, with no network access, no environment or credential reads, and it never writes or executes anything.