Guide

AI Agent Works in the Demo, Fails in Production? A Reliability Checklist

Why AI agents that pass demos break with real users, and a 10-step checklist: step caps, safe retries, structured outputs, saved state, traces, and evals.

· 9 min read

It’s the most common complaint in the builder conversations we track. “AI agent works perfectly in the demo… then falls apart in production?” (post). Or the worse version: “Your AI agent works in the demo. Then a client uses it and it silently fails” (post).

One builder summed up the cause in two lines: “Not because the model is dumb. Because nothing around it is reliable” (post). That’s good news, because the parts around the model are the parts you control. This guide walks through ten fixes in the order we’d apply them, with a checklist at the end.

Why demos lie

Small error rates compound

An agent that takes ten steps has ten chances to go wrong. The same post did the math: “10 steps at 99% each = 90.4% success. 20 steps = 81.8%.” At 95% per step, ten steps comes out to about 60%. Anthropic’s own guidance on agents warns about the same thing: autonomy means “higher costs, and the potential for compounding errors” (Building effective agents).

Demos are usually short, so they hide this. Real tasks are longer.

Demo inputs are clean

You test with the inputs you thought of. Users send empty fields, pasted spreadsheets, three requests in one message, and the occasional prompt injection. One post put it bluntly: generic outputs “break when connected to real B2B workflows” (post).

The agent says “done” when it isn’t

Agents report success in text, and text is cheap. Anthropic’s eval guide gives the example of a flight-booking agent that says “Your flight has been booked,” while the real test is “whether a reservation exists in the environment’s SQL database” (Demystifying evals for AI agents). If nothing checks the outcome, failures stay silent until a customer notices.

Real APIs time out

In a demo, every tool call works. In production, third-party APIs are slow, rate-limited, or down. One list of production problems includes “Stopping infinite retry loops on third-party API timeouts” (post). A loop like that burns tokens and can repeat side effects, like sending the same email twice.

Step 1: Make the agent part as small as possible

Anthropic separates workflows, where “LLMs and tools are orchestrated through predefined code paths,” from agents, where the model directs its own steps. Their advice is to find “the simplest solution possible, and only increasing complexity when needed.”

In practice, go through your agent’s steps and ask which ones need judgment. Fetching a record, formatting a date, or posting to a webhook doesn’t. Move those into plain code. The same production list calls this “Hardcoding the non-reasoning steps in deterministic code.” Every step you take away from the model is a step that can’t compound errors.

If you’re still choosing a stack, our AI agent setup guide covers starting with one job and getting it working before you add more.

Step 2: Define “done” as something you can check

For each task, write down the result you can verify without asking the agent:

  • “Lead added to the CRM with a score between 1 and 10.”
  • “Draft reply saved in the inbox, not sent.”
  • “Invoice PDF exists in the folder and the total matches the order.”

Then add a check in code after the agent finishes. If the check fails, mark the run as failed, even if the agent’s last message says everything went fine.

Step 3: Cap steps, time, and spend

Anthropic recommends “stopping conditions (such as a maximum number of iterations) to maintain control.” Most frameworks have one built in. In the OpenAI Agents SDK, max_turns limits the agent loop and raises MaxTurnsExceeded when it’s hit, and an error_handlers option lets you return a controlled message instead of crashing (Running agents).

Set three limits for every run:

  • Steps: a turn limit a bit above what a normal successful run uses.
  • Time: a wall-clock timeout for the whole run, not just each call.
  • Spend: a token or cost ceiling per run, so one bad loop can’t eat your budget.

When a limit trips, stop and report what happened. Don’t silently retry the whole task.

Step 4: Treat tool failures as normal

AWS’s guide to retries is the best short read on this (Timeouts, retries, and backoff with jitter). The rules that matter most for agents:

  • Set a timeout on every tool call. AWS’s practice is a timeout “on any remote call.”
  • Retry a few times, then give up. Use exponential backoff with jitter, and cap the number of attempts.
  • Retry in one place. If your tool retries, your framework retries, and the model retries too, the load multiplies. AWS’s example is a five-layer stack with three retries per layer, which multiplies database load by 243 times.
  • Don’t retry errors that won’t change. AWS notes that client errors “should not be retried with the same request.” A 400 or a permissions error needs a different request, not the same one again.
  • Make side effects safe to repeat. AWS says APIs with side effects “aren’t safe to retry unless they provide idempotency.” Where an API supports idempotency keys, use them. Stripe’s docs explain that with a key, “you can safely repeat the request without risk of creating a second object or performing the update twice” (Stripe idempotent requests).

When a tool finally fails, return a short, plain error to the model (“Calendar API timed out after 3 tries”), not a stack trace, so it can decide whether to stop or try another path. If your tools connect over MCP, our MCP troubleshooting guide covers the connection failures that look like tool failures.

Step 5: Use structured outputs and validate them

If the agent’s output feeds another system, define a schema and enforce it. OpenAI’s Structured Outputs feature “ensures the model will always generate responses that adhere to your supplied JSON Schema” (Structured model outputs). There are two exceptions to plan for: OpenAI says output is reliable only when there’s no refusal and the response wasn’t cut off early, so check for both (Introducing Structured Outputs).

Other providers and frameworks have similar features. Whatever you use, validate the output in code before it reaches a webhook, a database, or a customer. Schema-valid isn’t the same as correct, so add business checks too (a score in range, a date in the future, an email that looks like an email).

Step 6: Save state so a crash doesn’t restart the task

Long runs fail partway through. Without saved state, the agent starts over and may repeat steps that already happened. The 99% post lists “Explicit state” first among its fixes.

Frameworks handle this with checkpoints. LangGraph’s checkpointers save a thread’s state for “conversation continuity, human-in-the-loop workflows, time travel, and fault tolerance.” Its docs also flag a common trap: the in-memory savers “store checkpoints in RAM. When the process restarts, all checkpoints are lost,” so use a persistent one like Postgres in production (LangGraph persistence).

Saved state is different from long-term memory about the user. Our AI agent memory guide covers that side.

Step 7: Trace every run

When a run fails, you need to see each model call, tool call, input, and output. The OpenAI Agents SDK turns tracing on by default and records “LLM generations, tool calls, handoffs, guardrails, and even custom events” (Tracing). Most other frameworks either have tracing or work with third-party tracing tools.

Two habits make traces useful:

  • Name and tag runs so you can find all runs for one workflow or customer.
  • Decide what’s sensitive. The SDK has a trace_include_sensitive_data setting that controls whether tool and model inputs and outputs are stored. Turn it off for workflows that handle personal or customer data.

Then read them. Anthropic’s advice on evals applies here too: “Read the transcripts!”

Step 8: Build a small eval set from real failures

You don’t need a big benchmark. Anthropic says “20-50 simple tasks drawn from real failures is a great start,” and if you’re already live, “look at your bug tracker and support queue.”

For each task, store the input, the starting state, and the check from Step 2. Run the set every time you change a prompt, a tool, or a model. Anthropic splits these into two suites:

  • Capability evals: hard tasks you’re trying to improve on. A low pass rate is expected.
  • Regression evals: tasks the agent already handles. These “should have a nearly 100% pass rate,” and a drop means something broke.

Run each task more than once, because agents don’t give the same result every time. Anthropic’s example: a 75% per-trial success rate means only about a 42% chance of passing three trials in a row. For a customer-facing agent, that consistency number matters more than a single lucky pass.

Step 9: Put a human on irreversible steps

Some mistakes can’t be retried away: deleting records, sending emails, moving money, or writing to a production database. The production list includes “Human approval before irreversible database writes,” and the 99% post lists “Human approval” next to step caps and traces.

Make approval part of the tool or platform, not a line in the prompt, and show the exact action before someone says yes. Our guardrails and permissions guide covers how to set up allow, ask, and deny tiers.

Step 10: Launch small and watch

Before you hand the agent to a client:

  1. Try to break it. Feed it empty inputs, huge inputs, wrong languages, and instructions hidden inside documents. Stress testing before launch is common enough that builders now sell it as a service, including for agents built in n8n (post).
  2. Start with a few users or a small share of traffic. Watch failed checks, step-limit hits, and cost per run.
  3. Turn every new failure into an eval task. That’s how the suite from Step 8 grows.

Pre-launch checklist

CheckDone when
Deterministic steps moved to codeThe model only handles steps that need judgment
Success checkCode verifies the outcome after every run
Step, time, and spend limitsAll three set, with a clear message when one trips
Tool timeouts and retriesTimeout on every call, capped retries in one layer, no retries on client errors
Safe side effectsIdempotency keys or a duplicate check on every write
Structured outputSchema enforced and validated in code, refusals handled
Saved statePersistent checkpoints, not in-memory
TracingEvery run traced and tagged, sensitive data setting reviewed
Evals20+ tasks from real failures, run on every change, multiple trials each
Human approvalRequired for deletes, sends, payments, and production writes

FAQ

Why does my AI agent work in testing but fail in production? Usually because real tasks are longer, real inputs are messier, and real APIs fail. Small per-step error rates compound over many steps, and without an outcome check, failures look like successes.

How do I stop an AI agent from looping forever? Set a turn limit, a wall-clock timeout, and a spend limit for every run. Cap retries on tool calls, retry in only one layer, and don’t retry errors that won’t change, like a 400 or a permissions error.

How many evals do I need for an AI agent? Anthropic suggests 20 to 50 simple tasks drawn from real failures as a starting point. Run each task several times, since agents don’t return the same result every time.

Should I use an agent or a workflow? Use a workflow, with steps fixed in code, when you know the steps in advance. Use an agent only for the parts where the steps can’t be predicted. Most production systems mix both.

Is it safe to retry a failed tool call? Only if the call is read-only or idempotent. For writes, use an idempotency key or check whether the action already happened before you try again.


Get the next guide in your inbox

We’re collecting production fixes from people who build AI agents and Grok Bot setups, and we share what holds up in our newsletter. Subscribe to the newsletter for practical guides and directory picks.