All Articles LLM orchestration

Building Production AI Agents: 7 Architecture Patterns That Scale

Most AI agents fail in real-world deployments”not because of weak models, but because of flawed system design. This guide breaks down 7 battle-tested architecture patterns used by companies like Stripe, Klarna, and Shopify to build scalable, cost-controlled, and compliant AI agents that survive production traffic.

January 20, 2026 12 min read Likhon
🎧 Listen to this article
Checking audio availability...

Building Production AI Agents: 7 Architecture Patterns That Scale

Meta Title: Building Production AI Agents: 7 Architecture Patterns That Scale | Enterprise AI Engineering

Meta Description: Learn the 7 production-grade AI agent architectures that actually scale in enterprise environments. Includes ReAct, Plan-and-Execute, hierarchical delegation, observability stacks, cost guardrails, and real-world case studies from Stripe, Klarna, and Shopify.


1. The 90% Failure Rate Nobody Talks About

Ninety percent of AI agents built in demos collapse under real user traffic. Not because the models fail—but because the architecture does. When Stripe deployed their first AI agent for payment processing, they discovered that naive ReAct loops would cascade into infinite tool-call chains, racking up $12,000 in API costs within 48 hours. Klarna's customer service agent initially hallucinated refund policies, requiring 15 human overrides per 1,000 conversations. Shopify's Sidekick prototype worked perfectly in staging but ground to a halt at 50 concurrent merchants due to unbounded context windows and no circuit breakers.

The gap between "it works in Jupyter" and "it survives production" isn't prompt engineering—it's systems engineering. Production agents face adversarial users, exponential cost curves, unpredictable latency distributions, and compliance regimes that tolerate zero data leakage. This post maps the architectural patterns that close that gap, drawn from actual deployments at companies processing billions of API calls. If you're a CTO, Staff Engineer, or AI Lead tasked with shipping agentic systems that don't become headline-generating liabilities, these are the patterns you need.


2. What "Production-Grade" Actually Means

A production-grade AI agent isn't defined by its model intelligence but by its operational guarantees. The semantic gap between demo and production is measured in SLAs, compliance matrices, and cost ceilings that don't flex when traffic spikes.

SLA Requirements

Production agents must meet latency budgets under load. The 95th percentile latency for customer-facing agents should stay under 2 seconds, requiring sub-100ms tool execution and deterministic prompt caching. Shopify enforces a 1.5-second p99 latency budget for Sidekick by pre-warming context caches and hard-capping reasoning loops at three iterations. Internal tooling agents can tolerate 10-second latencies but require throughput of 1,000+ requests/minute, which demands horizontal scaling of agent executors and connection pooling for vector databases. shopify

Compliance Expectations

GDPR Article 22 mandates explainability for automated decisions. Agents must emit audit trails showing which tools were called, what data was accessed, and why decisions were made. Klarna's assistant logs every LLM invocation with full prompt traces to satisfy Swedish financial regulators. SOC 2 Type II requires immutable logs of all data access—agents querying CRM systems must emit OpenTelemetry spans that capture PII redaction in real time. blog.langchain

Cost Ceilings

Unchecked agents burn budget. Production systems enforce per-request cost caps: $0.10 for customer support, $1.00 for complex research tasks. Stripe's Agent Toolkit integrates token budgeting at the API gateway, killing requests that exceed 50,000 tokens cumulatively across planning and execution phases. Without explicit cost guardrails, multi-agent swarms can spawn exponential tool calls, a failure mode observed when early AutoGPT prototypes incurred $3,000 daily bills. galileo

Failure Tolerance

Demo agents assume happy paths. Production agents assume Byzantine failures: vector DB connection timeouts, tool APIs returning 500s, LLMs emitting malformed JSON, users injecting jailbreak prompts. Shopify's architecture treats every component as unreliable, wrapping tool calls in circuit breakers with exponential backoff and fallback to cached deterministic responses. The system must degrade gracefully—when the LLM fails, return a structured error; when the vector DB times out, fall back to keyword search. shopify


3. The 7 Agent Architecture Patterns That Scale

Pattern 1: ReAct (Reason + Act)

Pattern Overview: ReAct agents interleave reasoning traces with tool execution, forming a tight loop: Thought → Action → Observation → Thought. The LLM generates a reasoning trace, selects a tool, observes its output, and repeats until reaching a final answer. LangChain's implementation uses a scratchpad to accumulate context, feeding the entire history back into the LLM at each step. docs.langchain

When to Use It: ReAct excels for tasks requiring dynamic tool selection based on evolving context, such as research assistants querying multiple APIs (Wikipedia, news, databases) or support agents that must fetch account data before diagnosing issues. Stripe uses ReAct for payment investigation agents that query transaction logs, customer profiles, and fraud scores sequentially. youtube

When NOT to Use It: Avoid ReAct when task steps are known upfront. The repeated LLM invocations introduce latency variance—each reasoning step adds 200-500ms and token cost. For deterministic workflows like invoice processing, Plan-and-Execute is 3x cheaper and 2x faster. blog.langchain

Failure Modes: The primary failure is tool-call hallucination: the LLM invents parameters or selects non-existent tools. LangChain mitigates this with strict tool schemas and validation layers that reject malformed calls before execution. Another failure is infinite loops when the LLM cannot determine completion; implement a hard step limit (typically 15-20 iterations) and a semantic stopping classifier. docs.langchain

Cost Profile: Linear with step count. Each ReAct iteration costs ~1,000-3,000 tokens. A 5-step research query runs $0.015-$0.045 with GPT-4o-mini, scaling to $0.30-$0.90 with Claude 3.5 Sonnet. Stripe caps ReAct loops at 10 steps, bounding cost at $0.50 per request. galileo

Latency Profile: Additive per step. Average 800ms per iteration with GPT-4o-mini, 1.2s with Claude 3.5 Sonnet. Shopify observes p95 latencies of 6.5 seconds for 5-step ReAct chains, requiring aggressive caching of tool responses. shopify

Tooling Ecosystem: LangChain's create_agent provides the canonical implementation. For observability, integrate LangSmith to trace each Thought-Action-Observation triplet. Use Anthropic's prompt caching with cache_control: {type: "ephemeral"} to reduce latency on repeated reasoning patterns. docs.langchain

Real-World Example: Klarna's dispute resolution agent uses ReAct to investigate claims. It thinks through the problem ("customer claims unauthorized transaction"), queries the transaction API (Action), observes the IP address and device fingerprint (Observation), reasons about fraud likelihood, queries the customer's dispute history, and synthesizes a decision. The agent achieves 80% automation but routes high-risk cases to humans after three reasoning steps. twig

Pattern 2: Plan-and-Execute

Pattern Overview: The system first generates a complete multi-step plan using an LLM planner, then executes each step sequentially with a separate executor agent. The planner sees the full task context and produces a structured list of steps; the executor focuses only on current step completion. LangGraph's implementation separates planning and execution into distinct nodes, enabling replanning after each step. langchain-ai.github

When to Use It: Ideal for complex tasks where the sequence can be determined upfront: data pipeline orchestration, multi-stage code generation, or customer onboarding workflows. Shopify uses Plan-and-Execute for merchant setup assistants that configure shipping, taxes, and payment gateways in a predetermined order. shopify

When NOT to Use It: Avoid when tasks require dynamic tool discovery. If the agent cannot know whether it needs a database or API until mid-execution, ReAct's tight loop outperforms repeated replanning overhead.

Failure Modes: The planner can generate invalid steps (e.g., calling non-existent tools). LangGraph addresses this by validating the plan against available tools before execution begins. Another failure is rigid plans that don't adapt to execution errors; implement replanning triggers when steps fail, but cap replanning attempts at three to prevent infinite loops. langchain-ai.github

Cost Profile: Bimodal. Planning costs 2,000-5,000 tokens once; execution costs 500-1,500 tokens per step. A 10-step workflow costs ~$0.08 with GPT-4o-mini, 60% cheaper than equivalent ReAct due to reduced LLM invocations.

Latency Profile: Planning adds 1-2 seconds upfront, but per-step execution is faster (300-600ms) since the executor LLM focuses narrowly. Shopify reports 40% lower p95 latency for Plan-and-Execute workflows versus ReAct on 8+ step tasks. shopify

Tooling Ecosystem: LangGraph's Plan-and-Execute template provides reference implementation. Use Pydantic models for plan serialization, enabling validation and versioning. Integrate with temporal.io for long-running workflow persistence. langchain-ai.github

Real-World Example: Zapier's workflow automation uses Plan-and-Execute to generate Zap creation plans. The planner maps user requests ("When I get a Gmail from my boss, create a Trello card") into API call sequences; the executor handles OAuth, rate limiting, and error handling per step. This architecture processes 100,000+ workflow creations daily with 99.9% reliability.

Pattern 3: Self-Discovery / Self-Reflection

Pattern Overview: Agents introspect on their own reasoning, identify errors, and refine strategies. The Reflexion pattern uses verbal reinforcement learning: after each action, a critic LLM evaluates the result, generating feedback that the agent incorporates into subsequent attempts. Self-Refine iteratively improves outputs through self-generated critique without external feedback. dbis.rwth-aachen

When to Use It: Essential for tasks where correctness matters more than speed: code generation, mathematical proofs, or policy document drafting. The SAGE framework demonstrates that self-reflection improves code generation accuracy by 22% on HumanEval, with smaller models benefiting most. Use when evaluation criteria are clear and verifiable (unit tests, syntax validation). arxiv

When NOT to Use It: Avoid for latency-sensitive applications. Reflection adds 2-4 LLM calls per iteration, ballooning costs and latency. For customer support, route to humans instead of reflexion loops—users won't wait 30 seconds for the agent to "think harder."

Failure Modes: Reflection can converge on suboptimal solutions or enter self-reinforcing error loops. SAGE mitigates this by storing reflections in episodic memory, allowing the agent to recall successful strategies from prior tasks. Without memory, agents repeat reflection mistakes indefinitely. arxiv

Cost Profile: Multiplicative. Each reflection step costs 2-3x a base generation. A coding task costing $0.05 without reflection reaches $0.15-$0.20 with two reflection iterations. Budget 5,000-15,000 tokens per reflected solution.

Latency Profile: Linear with reflection count. Two reflection iterations add 3-5 seconds. Shopify limits Sidekick's self-reflection to one pass on code generation, capping latency at 8 seconds. shopify

Tooling Ecosystem: Implement Reflexion using LangGraph's conditional edges: generate → critique → reflect → (revise or finish). Use LMSYS's SelfEval framework to benchmark reflection quality. Store reflections in vector DB for retrieval-augmented reflection. dbis.rwth-aachen

Real-World Example: GitHub Copilot uses lightweight self-reflection to improve code suggestions. After generating a function, a critic model checks for syntax errors and test failures; if found, the agent revises the code. This reduces erroneous suggestions by 35% while adding only 200ms latency. v7labs

Pattern 4: Tool-Augmented Agents (Toolformer-Style)

Pattern Overview: Agents are fine-tuned to invoke tools by predicting special tokens in their token stream. Unlike ReAct's explicit reasoning traces, Toolformer-style agents embed tool calls directly in generation, learning when to call APIs from pre-training data. This yields deterministic tool invocation patterns without iterative LLM calls.

When to Use It: High-volume, low-latency scenarios where tool usage patterns are stable: real-time product search, stock price queries, or internal data lookups. The pattern eliminates reasoning overhead, achieving 200ms end-to-end latency. Stripe's payment link generation uses this for instant price retrieval. galileo

When NOT to Use It: Avoid for novel tasks. Toolformer-style agents require extensive fine-tuning data; they struggle with ad-hoc tool combinations. ReAct is more flexible for exploratory analysis.

Failure Modes: Tool calls are opaque—agents cannot explain why they invoked a tool. Debuggability requires tracing token predictions back to training data. The primary failure is tool misuse: the agent calls wrong APIs due to token collisions. Mitigate by using distinct token IDs per tool and validation layers that reject out-of-domain calls.

Cost Profile: Fixed per request. Single LLM invocation costs 1,000-2,000 tokens regardless of tool count. At scale, this is 50-70% cheaper than ReAct for equivalent functionality.

Latency Profile: Single-pass generation yields 300-500ms latency. Stripe's tool-augmented agent serves payment queries at 250ms p95, 3x faster than their ReAct baseline. galileo

Tooling Ecosystem: Implement via HuggingFace's Toolformer implementation or OpenAI's function calling (which abstracts the pattern). Use vLLM for high-throughput serving with tool token prediction.

Real-World Example: Notion's AI autofill uses Toolformer-style agents to pull data from linked databases. When a user types @, the agent predicts database query tokens, executes them in real time, and embeds results. This processes 500,000 queries/hour with 120ms average latency.

Pattern 5: Multi-Agent Swarms

Pattern Overview: Decentralized agents collaborate without central coordination. Each agent subscribes to events, acts autonomously, and publishes results. The system emerges from local interactions rather than top-down planning. This pattern mirrors microservices: agents are single-purpose (e.g., "invoice validator," "fraud detector") and communicate via message bus.

When to Use It: Perfect for chaotic, event-driven domains where no single agent can maintain global state: fraud detection (multiple signals from transactions, devices, behavior), content moderation (text, image, user reports), or IoT data pipelines. Shopify's merchant monitoring uses swarms: inventory agents, pricing agents, and competitor analysis agents publish events that trigger coordinated responses. shopify

When NOT to Use It: Avoid for linear workflows requiring strict ordering. Swarms introduce non-determinism and eventual consistency. For customer onboarding, Plan-and-Execute's sequential guarantee is safer.

Failure Modes: Agents can enter conflict loops, issuing contradictory actions. Implement a lightweight consensus layer: agents vote on actions, and majority wins. Another failure is message bus overload; use Kafka with topic partitioning and retention policies to bound memory.

Cost Profile: Pay-per-agent. Each agent invocation costs independently; total cost equals sum of agent costs. A 5-agent swarm processing a transaction costs $0.025-$0.075. Stripe caps swarm size at 10 agents per request to prevent cost explosion. galileo

Latency Profile: Parallel execution reduces wall-clock time but introduces synchronization overhead. A 5-agent swarm completes in 1-2 seconds (max agent latency) versus 5 seconds sequentially. Shopify observes 60% latency reduction versus monolithic agents on multi-domain tasks. shopify

Tooling Ecosystem: Use AutoGen for swarm orchestration or build on Kafka + Temporal. LangGraph's distributed runtime supports multi-agent graphs across containers. For consensus, integrate Raft or Paxos implementations.

Real-World Example: PayPal's fraud detection runs a 12-agent swarm on every transaction. Device fingerprinting, velocity checking, merchant reputation, and behavioral analysis agents publish confidence scores; a consensus agent aggregates them. This reduced false positives by 40% while processing 200M transactions/day.

Pattern 6: Hierarchical Delegation Agents

Pattern Overview: A top-level coordinator delegates subtasks to specialized worker agents, which may further delegate. This creates a tree structure: root (coordinator) → supervisors → workers. Each level abstracts complexity, enabling centralized control with distributed execution. LangGraph's hierarchical patterns implement this via nested StateGraphs. getmaxim

When to Use It: Enterprise workflows with clear organizational boundaries: HR onboarding (coordinator → IT provisioning → payroll → training), financial audits (coordinator → compliance → transactions → reporting), or medical diagnosis (coordinator → symptoms → labs → imaging). Klarna's customer support hierarchy routes to

Likhon - Gen AI Specialist

Senior Cloud and AI Engineer

Generative AI expert with 6+ years experience and 300+ certifications. Building LLM, RAG systems, and multi-cloud AI solutions.