SXF FIELD GUIDE / AGENT INFRASTRUCTURE · PRODUCTION ENGINEERING
How to Deploy AI Agents in Production:
Architecture, Hosting, Scaling & Reliability
From prototype to a verifiable service: durable queues, state, safe retries, cloud hosting, cost per accepted task and rollback. Includes an executed original SXF replay experiment and free launch checklist.
How do you deploy an AI agent in production?
Deploy the agent as a versioned, permissioned workflow — not a long HTTP request. Put an authenticated API in front, persist task and session state, dispatch work through a durable queue or workflow engine, apply bounded concurrency and idempotent tool effects, and measure independently accepted results. Test crash recovery and rollback before routing real traffic.
A hosted model or agent SDK alone does not supply all these production guarantees. Choose a managed agent platform, serverless API plus worker queue, or custom container fleet according to the work's duration, data requirements and operational constraints.
FIELD GUIDE
Prototype vs production: the contract changes
An agent that solves one prompt on a laptop is not yet a production service. Production AI agent deployment means that separate users can submit tasks safely, an interrupted execution can resume or reach a well-defined terminal state, and operators can explain every real-world action. The shift is from “did the model respond?” to “did the intended outcome happen, exactly within the permitted boundary?”
| Prototype question | Production answer / evidence |
|---|---|
| Can it complete a task? | Define an accepted outcome and verify the downstream state, not only the final message. |
| Does it remember the session? | Use a durable session and workflow store; test resumed and expired sessions. |
| What if the provider times out? | Apply bounded retries, backoff, budget caps and explicit unknown-outcome handling. |
| What if it sends twice? | Create a stable business operation key; prove deduplication at the effect boundary. |
| Who can approve a refund? | Enforce typed permissions and approval independently of the model's text. |
| What if a deployment goes wrong? | Pin artifact and prompt versions, canary, observe and roll back deterministically. |
Scope: this article focuses on the deployment system. For planner/specialist design see How to Build an AI Super Agent; for model-level and multi-run assessment see AI Agent Reliability.
REFERENCE ARCHITECTURE
A production AI agent architecture that survives the first outage
The safest default is an asynchronous boundary between accepting a task and carrying out long-running actions. Short queries can sometimes be served synchronously, but a workflow that calls multiple tools, waits for approval or must recover from failure needs persisted state and a separate worker lifecycle.
- Entry API: authenticate callers, authorize tenant and action, validate schema, assign immutable
task_idand a request idempotency key. - Durable enqueue: persist the task and queue intent atomically where feasible (for example, an outbox pattern); return
202 Acceptedwith a status URL for asynchronous jobs. - Worker lease: claim a task for a bounded time, apply a global and per-tenant concurrency budget and record the execution version.
- Reasoning loop: run the chosen model inside application-owned time, tool and spend budgets; do not let the model assign its own authority.
- Tool gateway: validate typed inputs, enforce approvals and send stable operation keys to compatible external services.
- Commit and notify: save verified business state and final output; expose an audit trail, terminal status and controlled callbacks.
Design invariant: a user-visible completion status must not precede confirmation of the corresponding business effect. When a remote tool succeeds but its acknowledgement is lost, the system should mark the outcome unknown / reconciling rather than blindly executing the action again.
HOSTING DECISION
Where should you host AI agents? Three viable production patterns
“AI agent hosting” is a runtime decision, not a product ranking. Compare architectures against workflow length, state, approvals, regulated data, workload shape and operational staffing. The same application-owned identity, idempotency and monitoring obligations apply across all three.
| Pattern | Best fit | Trade-offs / not included | What to test |
|---|---|---|---|
| A. Managed agent platform e.g., Microsoft Foundry Hosted Agents | An integrated agent lifecycle where the platform's supported identity, versioning and runtime align with your needs. | Portability, supported regions, product boundaries, underlying service dependencies and pricing require evaluation. | Can you pin and roll back versions? Export traces? Bring your own tools, state and auth? |
| B. Serverless API + jobs / queue e.g., Cloud Run or Lambda front end plus durable queue | Bursty workload, bounded requests and independently scheduled tasks; small operations team. | Request/task timeouts, cold starts, queue semantics, provider concurrency and external persistence must be designed. | Timeout limits, p95 cold path, duplicate delivery, job drain and admission under bursts. |
| C. Container worker fleet Kubernetes / managed containers + durable orchestrator | Long-running custom workers, specialized libraries, multi-service dependencies, tighter platform control. | Platform and on-call complexity; autoscaling does not supply checkpoints or workflow semantics. | HPA metric relevance, graceful shutdown, lease renewal, worker replacement and recovery. |
Microsoft documents a deployment lifecycle built around publishing the container, creating an agent version and invoking its endpoint [6]. Google Cloud Run documents per-instance request concurrency as a configurable upper bound, not a guarantee that your model/tool dependencies can sustain that rate [1]. Kubernetes HPA controls replica count from metrics but does not repair partially executed business transactions [2].
Do not confuse agent framework with hosting platform. LangGraph, CrewAI and an SDK can run inside any supported runtime, subject to integration requirements. See AI Agent Frameworks Compared for framework selection, which is a separate choice.
FIELD GUIDE
Persistent state, memory and long-running jobs
Store at least three distinct categories: workflow state (status, steps, attempt, lease and checkpoints), conversation/context state (permitted context and memory), and business state (the external effect you are responsible for). They have different retention periods and consistency requirements.
| Data / state | Source of truth | Minimum recovery behavior |
|---|---|---|
| Task and workflow status | Durable DB / workflow history | Survives pod termination and client disconnect; step transition audit trail. |
| Conversation and retrieval context | Session store / controlled retrieval index | Versioned retrieval, tenant isolation, privacy retention and safe rehydration. |
| Side-effect ledger | Business DB or external provider operation record | Stable operation key, idempotency window and reconciliation when acknowledgement is lost. |
| Execution version | Immutable deployment manifest | Records code/prompt/model/tool versions responsible for each run. |
| Approval receipt | Immutable audit event with policy evidence | Who approved which exact action, scope, parameters and expiration. |
| Diagnostics | Redacted spans, metrics and structured event logs | Correlation by task ID without exposing secrets or full prompts by default. |
Durable workflow products such as Temporal reconstruct execution state from persisted event history [8]. That improves recoverability, but durable execution is not the same thing as exactly-once external effects. Any network call after a checkpoint can still need target-side idempotency and reconciliation. For the long-term memory design layer, see AI Agent Memory.
SCALING & ADMISSION
Queues, scaling and rate limits: scale accepted work, not just pods
The backlog is where burst absorption becomes measurable. A queue can protect the web API from long tasks, but it can also hide a capacity crisis unless you observe the oldest job age, retry load, dead-letter counts and time to an accepted outcome. Do not scale solely on CPU: agent tasks are often I/O bound on models and external APIs.
| Signal | Why it matters | Operational response |
|---|---|---|
| Oldest queued task age (seconds) | User waiting experience and missed completion objective | Add permitted worker capacity or reduce intake; alert before deadline is breached. |
| Queue depth / arrival vs departure rate | Backlog growth and saturation | Scale workers until downstream or spend limits become binding. |
| In-flight tasks by tenant | Noisy neighbor and fairness risk | Apply tenant quotas, weighted scheduling and concurrency caps. |
| Provider 429 / throttled tool calls | True downstream throughput ceiling | Backoff with jitter, lower concurrency; never retry immediately in a tight loop. |
| Attempts per accepted task | Retry amplification and hidden cost | Investigate provider failures, tool contracts and timeout policy. |
| Dead-letter or reconciliation backlog | Work that cannot safely auto-resume | Escalate to explicit review with task history and incident owner. |
As a rough capacity planning identity, average concurrency is arrival rate × mean time in the system (Little's Law under stable conditions); it is not a safe production cap by itself. Use p95/p99 task durations, memory footprint, runtime budgets and rate-limit tests to set an initial bound. Some tasks must stop at the tool boundary, no matter how many worker pods you create. See the interactive cost and capacity worksheet below.
FIELD GUIDE
Retries, idempotency and the unknown-outcome trap
At-least-once delivery is normal in many queue and retry systems. Replaying a model call is often only a cost issue; replaying send_email, create_refund or transfer_funds can be a real-world harm. AWS explicitly documents that replay can execute a side-effectful step again [3, 4].
Construct an idempotency key from stable business identity, such as tenant_id + order_id + refund_version, not from a random retry attempt ID. Enforce uniqueness transactionally where the effect and ledger share a database. For remote effects, use the external service's documented idempotency guarantee and query its state after an ambiguous timeout. A local “already called” flag is not proof that the remote operation succeeded.
REQUEST → validate permission → durable task + operation_key
WORKER → if completed: return recorded result
→ if external status unknown: reconcile first
→ else call tool with operation_key (when supported)
→ verify downstream state → record completion
TIMEOUT → bounded backoff + jitter, then retry/reconcile
EXHAUST → dead-letter / human review; never claim success
Important nuance: AWS describes an “exactly-once” execution model for some Step Functions Standard workflow tasks, with explicit retry qualifications [5]. That statement must not be generalized into an end-to-end guarantee for every remote side effect. An agent architecture should be precise about which boundary provides which guarantee.
ORIGINAL SXF EVIDENCE
SXF original experiment: what a worker restart does to duplicate actions
We built and executed an original offline fault-injection demonstration in Python using only the standard library and SQLite. It asks a narrow, falsifiable question: if the same logical work is delivered three times and an in-process worker restarts before the final pass, which deduplication strategy preserves one locally committed effect per logical job?
| Implementation | Effects recorded | Duplicate effects | Suppressed deliveries |
|---|---|---|---|
| No deduplication | 360 | 240 | 0 |
| Per-process memory set | 240 | 120 | 120 |
| SQLite transactional idempotency ledger | 120 | 0 | 240 |
For each of 120 unique task-N:send-confirmation keys, our test delivered the action three times: once in pass 1, again in pass 2, and again after the simulated restart. The naive implementation wrote each delivery. The RAM approach kept a set but lost it across the restart. The SQLite approach used a unique ledger key and inserted the local effect in the same database transaction. The test contains assertions for all expected counts.
python deployment-replay-lab.pyInspect source on GitHub ↗Read and audit the exact experiment logicWhat this DOES prove: in this deterministic local workload, the transactional ledger prevents duplicate local SQL writes despite replay and a worker restart. What it does NOT prove: real cloud uptime, throughput, end-to-end exactly-once effects, network partitions, email delivery or behavior of any agent vendor. There are no model API calls, live cloud services, benchmark timings or production users in this demonstration. A payment or email API that cannot participate in the same DB transaction still needs its own idempotency and reconciliation contract.
RELEASE ENGINEERING
Step-by-step deployment and safe rollout
- Specify the outcome: pick one narrow workflow and define acceptance criteria, tool permissions, budget cap and a failure-state taxonomy.
- Package and version: commit application source, tests, dependency lockfile, prompt templates and tool schemas; build an immutable container or platform artifact.
- Prepare infrastructure: isolated staging environment, secrets manager, database, queue, worker identity, tracing and per-tenant restrictions.
- Make state recoverable: implement persisted checkpoints or workflow history, visibility timeouts/leases, idempotency keys, reconciliation and dead-letter handling.
- Test before traffic: run evaluation fixtures, duplicate deliveries, worker kill/restart, tool timeout, approval rejection, schema migration and cost budget tests.
- Canary the version: move a small, pre-defined share of eligible traffic to the release; compare outcome, tail latency, cost, safety events and support escalation against baseline.
- Roll back safely: shift new task intake back to the prior version and explicitly decide what happens to in-flight jobs, schema changes and pending approvals.
- Close the loop: write a release record with artifact ID, model/prompt version, observed metrics, on-call owner and review date.
Do not assume a “rollback” can undo an external action such as sending a customer email. Design reversible and irreversible steps separately; irreversible actions may require compensation, escalation or a human decision.
UNIT ECONOMICS
AI agent deployment cost: calculate price per accepted outcome
Token prices alone are not production TCO. The operational question is cost per independently accepted task, including attempts, external tools, fixed runtime and human review. The worksheet below uses your assumptions, not real-time quotes from any provider; defaults are illustrative and are not vendor claims.
Model: monthly = accepted tasks × attempts × per-attempt cost + fixed infrastructure + accepted tasks × review cost. This does not estimate throughput, customer value, cost of failures, provider discounts or carbon footprint; add those separately. Worker capacity is workload-specific: test the entered limit against external service throttling.
For an enterprise interpretation, connect this scenario to the existing AI Agent Cost, TCO & ROI research and SXF model cost calculator. A cheap request that fails verification is not a cheap business outcome.
SECURITY & GOVERNANCE
Security, authorization and human approval belong outside the model
The model may suggest an action; the policy service decides whether it can execute. Give each workload a scoped identity, restrict network egress, isolate tenants, pin allowed tools and apply maximum transaction limits. Audit an approval against the exact operation payload, not an abstract blanket instruction. Sanitize logs and never store secrets in task context.
| Boundary | Example enforceable control | Verification evidence |
|---|---|---|
| Caller → API | OIDC/OAuth or equivalent identity, tenant-scoped authorization | Forbidden tenant request rejected in integration test. |
| Agent → tool gateway | Schema validation, allowlist, scoped token, rate limit | Unauthorized tool denied even when model text requests it. |
| Approval → irreversible action | Action-specific receipt, owner, amount/recipient, expiration | Rejected/expired receipt cannot authorize a second action. |
| Worker → secrets / network | Secret manager, short-lived identity, controlled egress | No credentials in traces, prompts, stdout or public artifacts. |
| Data & memory | Tenant isolation, retention and deletion policy | Cross-tenant retrieval tests and privacy review. |
See AI Agent Authorization, AI Agent Security and Prompt Injection for detailed threats. OWASP's agentic application materials describe why tool access and delegated autonomy expand the risk surface [13].
FIELD GUIDE
Observability, SLOs and incident response
Observe more than the provider response code. Attach the same task_id and trace ID to API admission, model calls, tool requests, checkpoints, approvals, retries and final verified outcomes. OpenTelemetry has evolving GenAI agent span conventions; treat unstable conventions as versioned interfaces [9].
| Metric / SLI | Why decision-makers need it | Example alerting philosophy |
|---|---|---|
| Accepted task success rate | Measures actual business completion | Page on a sustained breach of a workload SLO. |
| p95 / p99 end-to-end completion time | Captures queue wait + all retries + approval delay | Alert when end-user completion deadlines risk failure. |
| Side-effect duplication / unknown state | Severe data-integrity or financial signal | Zero-tolerance investigation for high-impact side effects. |
| Queue age and dead-letter count | Backlog that the web server cannot see | Act before oldest-task age reaches contracted maximum. |
| Cost per accepted outcome | Makes retry amplification visible | Warn on abnormal spend growth, not just token spikes. |
| Approval bypass attempts and denied tools | Trust boundary integrity | Triage anomalies without treating every refusal as an outage. |
Incident drill: inject a tool timeout after the remote effect may have committed. Do you trace the attempt? Does the task show unknown? Can the operator query the downstream system and resolve it without a second side effect? If not, the deployment is not ready for high-consequence actions. The operational instrumentation is covered in AI Agent Observability; evaluation criteria and downloadable scoring are in AI Agent Evaluation Checklist.
FIELD GUIDE
Disaster recovery, data residency and exit strategy
Define RPO (how much verified workflow data can be lost) and RTO (how long the service may be unavailable). Map dependencies beyond the agent host: model endpoints, queues, database, vector retrieval, object storage, IAM and tool APIs. Store infrastructure and agent definitions as code, practice restore drills, and document data residency and retention obligations before procurement.
In a region-level outage, simply launching a second container is insufficient if all workflow state and secrets remain in the failed region. Microsoft describes disaster-recovery planning for agent services as explicitly involving the agent definitions and stateful dependencies [7]. Choose recovery architecture based on business requirements; avoid publishing an untested “multi-region ready” claim.
Exit contract for vendors: can you export prompts, run state, audit trail, dataset snapshots and versioned tool definitions in usable formats? Can your workers continue elsewhere without silently changing the approved authority model?
RELEASE GATES
Production readiness checklist: the go/no-go release gate
Teams should not use a universal numeric “85% ready” score. Assign each gate a named owner, evidence link, risk severity and a pass/waiver decision. A safety-critical failure cannot be averaged away by good scores elsewhere. Download and adapt the original SXF CSV below.
| Gate | Owner / evidence | Pass criterion |
|---|---|---|
| Workload acceptance | Product + QA | Accepted output verified in downstream state |
| Security and tenant isolation | Security | Cross-tenant and disallowed-action tests passed |
| Tool idempotency and reconciliation | Backend | Duplicate delivery and ambiguous acknowledgement tests passed |
| Crash and replay recovery | Backend / SRE | Interrupted workflow safely resumes or fails explicitly |
| Rate limits and graceful degradation | SRE | Model and tool throttling do not create retry storms |
| Durable state and migration | DBA / SRE | State restored after restart and rollback tested |
| Canary and rollback | Release engineering | Traffic split, abort triggers and in-flight policy exercised |
| Monitoring and privacy | SRE / Privacy | Redacted traces, outcomes, alerts and retention verified |
| Budget and review controls | Finance / Ops | Spend ceiling and approval workflow tested |
| Incident and disaster recovery | SRE | Runbook owner, RTO/RPO and restoration drill documented |
| Provenance and evidence | Technical editor | Claims, sources, model versions and test conditions disclosed |
FIELD GUIDE
Seven deployment mistakes that create expensive incidents
- Using a web request as a durable job: a timeout can interrupt work after the API has already returned to a user.
- Assuming retries equal reliability: an unguarded retry can multiply irreversible tool actions.
- Storing task truth in worker RAM: autoscaling and restarts lose the very state needed for recovery.
- Scaling agent pods without controlling provider quota: additional concurrency increases 429s and costs.
- Allowing the model to approve itself: permission checks belong to external deterministic controls.
- Celebrating a green trace instead of a verified outcome: the tool can return 200 while the business state remains incorrect.
- Rolling back code without handling in-flight workflows: old and new workers may interpret schema or checkpoints differently.
For a focused quantitative approach to repeated failures, see AI Agent Reliability: 12 Metrics. For operational traces, see AI Agent Observability.
FIELD GUIDE
Frequently asked questions about deploying AI agents
How do you deploy an AI agent in production?
Package the agent as a versioned runtime, add a durable task queue and persistent state, bind tools to least-privilege identities, define retries and idempotency for side effects, instrument outcomes and run a staged release with rollback.
Where should I host an AI agent?
Use a managed agent platform for integrated deployment if its portability and controls fit; serverless for short stateless entrypoints and bounded jobs; or containers and Kubernetes for custom workers and control. Hosting is only one layer of the system.
Do production AI agents need Kubernetes?
No. Begin with the least complex platform that meets the requirements. Kubernetes can help with custom worker fleets but does not automatically solve durable state, model quality, permissions or idempotent tool calls.
How do AI agents recover from a crash?
Persist job state and workflow checkpoints outside the worker, redeliver or replay unfinished work, deduplicate by business operation key, and reconcile any external side effects whose result may be unknown.
Can retries guarantee exactly once execution?
No universal end-to-end guarantee follows from retries or a workflow engine alone. For side effects, use transactional boundaries where possible or the target API's idempotency support plus reconciliation.
How do you scale AI agents?
Scale workers using queue age, backlog, throughput and downstream limits; apply bounded concurrency, tenant quotas, model provider rate limits, backoff and admission control rather than scaling pods on CPU alone.
What should a production AI agent deployment checklist include?
A release checklist should specify reproducible build and rollback, data migration safety, task replay, human approval, access permissions, redacted traces, SLOs, disaster recovery, cost limits and independent outcome evaluation.
How much does it cost to deploy an AI agent?
Total cost includes inference, repeated attempts, tool APIs, runtime and queues, storage, monitoring, review and on-call labor. Measure cost per independently accepted business outcome; a model token price alone is not sufficient.
RESEARCH LEDGER
Primary sources, reproducibility and editorial method
Evidence hierarchy: official platform/runtime documentation for platform semantics; NIST and OWASP for governance and threat framing; SXF's own executed, explicitly bounded offline experiment for the local replay result. Comparison judgments and architecture trade-offs are editorial analysis, not independent provider benchmarks.
Original test disclosure: 120 tasks × three passes; deterministic synthetic deliveries; one simulated restart before pass three; Python standard library and SQLite; no production or hosted infrastructure tested. No sponsored placements or vendor payments were used in this editorial guide. Check the official documentation and your region/plan before making operational decisions.