# How to deploy AI agents to production

> Deploy an AI agent by setting limits, guardrails, durable state and human checkpoints first, then tracing, online evals and alerts, and roll out in stages.

Source: https://www.honeyhive.ai/learn/ai-agent-deployment (updated 2026-11-18)

To deploy an AI agent to production, put controls around the loop before you put users in front of it: limits on how long it can run, guardrails on what goes in and out, state that survives a restart, a human checkpoint for risky actions, and traces so you can see what it did. Then roll it out in stages and score live traffic, because a passing test suite does not tell you how real inputs behave.

Below, each of those concerns is matched to what the official framework and provider docs say. It assumes you already have a working agent; if not, start with [how to build AI agents](/learn/how-to-build-ai-agents).

## What changes when an agent goes live

Anthropic's [Building effective agents](https://www.anthropic.com/engineering/building-effective-agents) (published Dec 19, 2024; the post now notes that much of the tooling it describes has changed since) names the two production risks directly: "The autonomous nature of agents means higher costs, and the potential for compounding errors." Its answer is to test in a sandbox, keep guardrails in place, set stopping conditions and let the agent "pause for human feedback at checkpoints or when encountering blockers."

Each of those becomes a deployment task. The table maps them to documented mechanisms.

| Concern | What to put in place | Documented mechanism |
|---|---|---|
| Runaway loops and cost | A turn limit | `max_turns` and `MaxTurnsExceeded` in the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/running_agents/) |
| Bad inputs and outputs | Guardrails | Input, output and tool guardrails in the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/guardrails/) |
| Restarts and long waits | Durable state | Checkpointers and thread IDs in [LangGraph](https://docs.langchain.com/oss/python/langgraph/durable-execution) |
| Risky actions | A human checkpoint | Pause for feedback, per [Anthropic](https://www.anthropic.com/engineering/building-effective-agents) |
| Not knowing what happened | Tracing, online evals, alerts | [HoneyHive monitoring docs](https://docs.honeyhive.ai/v2/monitoring/overview.md) |

## Set limits before launch

Anthropic [advises](https://www.anthropic.com/engineering/building-effective-agents) including "stopping conditions (such as a maximum number of iterations) to maintain control." In the OpenAI Agents SDK the limit is `max_turns`, and the run raises `MaxTurnsExceeded` when it is passed. The [running agents docs](https://openai.github.io/openai-agents-python/running_agents/) also say `max_turns=None` disables the limit, so check that nothing in your config does that.

Hitting a limit should not look like a crash to the user. The same docs describe error handlers for when you "want to return a controlled final output instead of ending the run with the corresponding error."

## Add guardrails where they run

The [OpenAI Agents SDK guardrails docs](https://openai.github.io/openai-agents-python/guardrails/) split checks into three kinds, and where each runs matters for deployment:

- Input guardrails run "on the initial user input" and only for the first agent in the chain. By default they run in parallel with the agent, so the agent can start spending tokens before a tripwire fires. Setting `run_in_parallel=False` makes the guardrail finish first.
- Output guardrails check the final answer, only for the agent that produces it, and always run after the agent completes.
- Tool guardrails wrap function tools and check calls before and after they execute. Handoffs do not use this pipeline.

When a guardrail trips, the runner raises an exception and halts the run, and a rejected final output is not saved to the session. Your service has to catch those exceptions and return something sensible. Anthropic [describes](https://www.anthropic.com/engineering/building-effective-agents) the same idea as one model instance handling the query while another screens it. For the concepts, see [AI guardrails](/learn/ai-guardrails), and for the attack side see [prompt injection](/learn/prompt-injection).

## Keep state somewhere that survives a restart

In-memory state disappears when a container restarts or a request lands on another instance. LangGraph's [persistence docs](https://docs.langchain.com/oss/python/langgraph/durable-execution) say checkpointers "persist a thread's graph state as checkpoints" and list "fault tolerance" and "human-in-the-loop workflows" among their uses. Runs are scoped by a thread ID passed in config. The docs also note that `InMemorySaver` and `MemorySaver` keep checkpoints in RAM, so they are lost on restart; the docs say to use a persistent checkpointer such as `PostgresSaver` for production. See [LangGraph](/learn/langgraph-framework).

The OpenAI SDK has a related rule: its [running agents docs](https://openai.github.io/openai-agents-python/running_agents/) say "In most applications, pick one persistence strategy per conversation", and that session persistence cannot be combined with server-managed conversation settings.

## Decide where a human steps in

Anthropic [says](https://www.anthropic.com/engineering/building-effective-agents) agents can "pause for human feedback at checkpoints or when encountering blockers." In deployment terms, pick the actions that need approval (the ones you cannot undo), and make sure the agent's state is saved while it waits, which is where the checkpointer above matters. The patterns are covered in [human-in-the-loop AI](/learn/human-in-the-loop-ai). If the agent acts with credentials, see [AI agent identity](/learn/ai-agent-identity).

## Roll out in stages

Anthropic [recommends](https://www.anthropic.com/engineering/building-effective-agents) "extensive testing in [sandboxed environments](/learn/ai-agent-sandboxing), along with the appropriate guardrails." Sandbox first, then a small share of real traffic with the scores below watched, then more. HoneyHive's [trace configuration docs](https://docs.honeyhive.ai/v2/tracing/configuration-details.md) list `rollout_percentage`, `feature_flag` and `ab_variant` as fields you can attach to traces, so each version's results can be compared.

## Watch it after launch

Three layers cover what you can observe once the agent is live:

- Traces record each step. See [agent observability](/learn/agent-observability).
- Online evaluations score live traffic. HoneyHive's [online evaluation docs](https://docs.honeyhive.ai/v2/monitoring/onlineevals.md) say evaluators run asynchronously on incoming traces without adding latency to your application, and note that "Python evaluators are much cheaper to run than LLM evaluators." They suggest full coverage under 1K events a day, roughly 25 to 50% from 1K to 10K, and roughly 5 to 25% above 10K.
- Alerts tell you when something moves. HoneyHive describes [two types](https://docs.honeyhive.ai/v2/monitoring/alerts/alerts_overview.md): aggregate alerts that "Monitor when metrics cross absolute thresholds" and drift alerts that "Detect when performance degrades compared to previous periods."

More on what to track is in [AI agent monitoring](/learn/ai-agent-monitoring). The checks you ran before launch carry over; see [AI agent evaluation](/learn/ai-agent-evaluation).

## Production monitoring in HoneyHive

HoneyHive's [monitoring docs](https://docs.honeyhive.ai/v2/monitoring/overview.md) describe a dashboard for "cost, latency, token usage, and evaluator scores", automated evaluations on production traces, and alerts for thresholds or drift. To set it up, send traces from your deployed agent, attach version fields such as `prompt_version` and `environment` as described in the [trace configuration docs](https://docs.honeyhive.ai/v2/tracing/configuration-details.md), turn on the online evaluators you need, and create alerts on the metrics you care about.

## FAQ

### What should an AI agent have before it goes to production?

A turn limit, guardrails on inputs, outputs and tool calls, state that survives a restart, a human checkpoint for risky actions, and tracing. Anthropic recommends "extensive testing in sandboxed environments, along with the appropriate guardrails" ([source](https://www.anthropic.com/engineering/building-effective-agents)).

### How do I stop an agent from looping forever in production?

Set a maximum number of iterations. Anthropic [advises](https://www.anthropic.com/engineering/building-effective-agents) including "stopping conditions (such as a maximum number of iterations) to maintain control", and the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/running_agents/) raises `MaxTurnsExceeded` when a run passes `max_turns`.

### Can I evaluate every production trace?

Code-based evaluators are cheap enough to run on all traces. LLM judges cost model usage, so sample them. HoneyHive's [online evaluation docs](https://docs.honeyhive.ai/v2/monitoring/onlineevals.md) suggest roughly 5 to 25% above 10K events a day.
