Running an agent for yourself is one thing; running it for thousands of users is a distributed-systems problem with an unpredictable component in the middle. Production agents need sandboxes provisioned per session, a gateway in front of model providers with quotas and fallbacks, durable session state, versioned prompts and harness configuration, audit logs, kill switches, and an incident process that understands model behaviour. This final lesson assembles everything in the track into a production architecture and a launch checklist.
- Describe a production architecture for an agent service
- Version and roll out prompts, tools and harness configuration safely
- Handle provider outages, rate limits and per-tenant quotas
- Prepare kill switches, audit logs and incident runbooks for agents
- Run a launch review using a production readiness checklist
A production architecture
| Component | Responsibility |
|---|---|
| API and session service | Authenticates users, stores durable session state, streams progress |
| Agent workers | Run the loop; stateless so they can scale and restart |
| Sandbox pool | Pre-warmed isolated containers or microVMs, one per session, destroyed after |
| Model gateway | Routes to providers, enforces quotas, retries, fallbacks, caching, logging |
| Tool services and MCP servers | Business actions with the user's permissions |
| Policy and approvals | Permission rules, approval queue, audit log |
| Telemetry | Traces, metrics, online evals, cost tracking |
| Config and flags | Versioned prompts, tool sets, budgets, kill switches |
Keep agent workers stateless and store session state (messages, task list, workspace snapshot references) durably, so a crashed worker or a deploy does not lose a user's task. Long tasks should survive restarts by resuming from the last completed step.
Versioned configuration and rollout
Prompts, tool definitions, budgets and model choices are behaviour, so manage them like code: versioned in a repository, reviewed, evaluated in CI and rolled out gradually. Record the configuration version in every trace. Being able to roll back a prompt in one minute is as important as rolling back a deploy.
version: 2026.10.1
prompt: prompts/support-v14.md
tools: [orders_search, orders_refund_preview, orders_refund, tickets_create]
models:
primary: provider-a/large
fallback: provider-b/large
router_small: provider-a/small
budgets:
max_steps: 30
max_tokens: 300000
max_seconds: 600
approvals:
orders_refund: always
tickets_create: never
rollout:
canary_percent: 5
guardrail_metric: unsafe_action_rate
kill_switch: falseProviders, quotas and fallbacks
- Gateway: all model traffic passes through one internal gateway that holds keys, enforces per-tenant and per-user quotas, and records usage for cost attribution.
- Rate limits: queue and smooth bursts; back off on provider limits; prioritise interactive sessions over background jobs.
- Fallbacks: a second provider or model for outages, evaluated in advance on the benchmark so you know the quality you fall back to.
- Timeouts: per call and per session, with clear user-facing messages when exceeded.
- Cost controls: per-tenant budgets and alerts on spend anomalies, since a looping agent can burn money quickly.
Safety operations
Agents can take actions, so incidents can be actions, not only bad text. Prepare for that before launch.
Agent incidents differ from ordinary outages in one important way: the system may be up and fast while doing the wrong thing. Dashboards of errors and latency stay green. That is why online evals, unsafe-action metrics and user reports must feed the on-call alerting, and why the first response is usually to narrow what the agent may do (a tool, writes, a tenant) rather than to take the whole service down.
- Kill switches at several levels: disable one tool, disable write actions, disable the agent for a tenant, disable it globally. They must work without a deploy.
- Audit log of every consequential action: who, which session, which tool, arguments, approval, result. Keep it separate from debug traces and tamper-evident.
- Runbooks for agent incidents: stop the behaviour, find affected sessions from traces, reverse actions where possible, notify users, add eval cases, then re-enable.
- Data handling: retention limits for prompts and traces, redaction, regional storage where required, and clear user-facing disclosure that an AI agent is acting.
def check_switches(flags, tenant: str, tool: str, is_write: bool) -> str | None:
if flags.get("agent_disabled") or flags.get(f"tenant_disabled:{tenant}"):
return "The assistant is temporarily unavailable."
if flags.get(f"tool_disabled:{tool}"):
return f"{tool} is temporarily disabled; tell the user and offer a human handoff."
if is_write and flags.get("writes_disabled"):
return "Write actions are paused; prepare the change for a human to apply."
return NoneLaunch readiness
- Evals: held-out benchmark meets the target with intervals; pass^k for key tasks; safety suite at zero failures; red-team findings fixed and added as cases.
- Isolation: sandboxes per session, no network by default, least-privilege credentials, approvals on irreversible actions.
- Operations: tracing, dashboards for success, cost and unsafe actions, alerts, on-call owner, runbooks, kill switches tested.
- Resilience: fallback provider evaluated, quotas and budgets set, sessions survive worker restarts.
- Rollout: canary percentage, success and guardrail metrics, rollback procedure rehearsed.
- Compliance: data retention, redaction, audit log, user disclosure and human escalation path.
Rehearse the bad day before launch: flip each kill switch in staging, fail the primary provider, and walk through reversing a wrong refund from the audit log.