AI Agent Scaling in Production: Why Infrastructure Becomes the Bottleneck

    This article examines why AI agent prototypes often perform well in demos but fail in production because of infrastructure issues rather than model reasoning. It covers common problems such as sandbox disconnects, state loss, and asynchronous timeouts; provides troubleshooting checks and remediation guidance; and includes a state-persistent, retry-aware code pattern. It also discusses cloud integration options, model-harness pairing, and three multi-agent orchestration patterns with their applicable boundaries. Finally, it outlines deployment and security practices for agents with independent identities, permissions, and long-term memory.

    AI agent prototypes often perform well in demonstrations, but once they enter production, they frequently experience execution interruptions, context loss, and request timeouts. Observations from many engineering teams indicate that most of these issues stem from infrastructure rather than model reasoning capability. This article reviews common pain points, provides troubleshooting approaches and remediation directions, and explains the applicable boundaries of multi-agent orchestration.

    1. Why Harness Engineering Is Often Overestimated

    Harness engineering refers to the peripheral code written around large models, including prompt templates, tool-call wrappers, output parsing, and retry logic. During the prototype stage, teams often put most of their effort into these areas, hoping to extract more performance from the model. Such investment is valuable, but if it becomes excessive, teams can easily overlook failure risks in production.

    After a prototype works, problems usually concentrate on three types of infrastructure.

    2. How to Troubleshoot Infrastructure Pain Points

    The following table lists common symptoms, root causes, checks, and remediation recommendations for three types of issues.

    Problem Common symptoms Common root causes Checks Remediation recommendations
    Sandbox disconnects Code execution exits midway; tasks get stuck Resource exhaustion, network jitter, improper container lifecycle management Container restart count, memory and CPU levels, connection keepalive configuration Set resource quotas; add health checks and automatic rebuild
    State loss After a process restart, the agent re-executes or falls into a loop State is kept only in memory and not persisted Whether state is written after each step; whether state has version numbers Write to persistent storage after each step; record step sequence numbers
    Asynchronous timeouts Gateway timeouts; worker threads are exhausted Synchronously waiting for long-running tool calls Latency distribution per call; timeout configuration Switch to asynchronous tasks with callbacks; set tiered timeouts

    The example below shows a more robust approach. The original synchronous call did not save state after a timeout, making tasks prone to deadlock. The improved version first persists execution state, sets a timeout and backoff retry, and moves failed tasks to a dead letter queue.

    1. import asyncio
    2. # Illustrative code only; not for direct production use.
    3. # Requires Python 3.10 or later. Replace load_task_state, save_task_state,
    4. # call_external_tool, and send_to_dead_letter_queue with actual implementations.
    5. MAX_RETRIES = 3
    6. TOOL_TIMEOUT_SECONDS = 120
    7. async def execute_agent_step(task_id: str, step_index: int) -> None:
    8. state = await load_task_state(task_id)
    9. # Idempotency key consists of task ID and step index; each step executes only once
    10. idempotency_key = f"{task_id}:{step_index}"
    11. if state.is_completed(step_index):
    12. return
    13. # Persist "running" state before execution so it can recover after process interruption
    14. state.mark_running(step_index)
    15. await save_task_state(state)
    16. for attempt in range(1, MAX_RETRIES + 1):
    17. try:
    18. result = await asyncio.wait_for(
    19. call_external_tool(state.context, idempotency_key),
    20. timeout=TOOL_TIMEOUT_SECONDS,
    21. )
    22. state.complete_step(step_index, result)
    23. await save_task_state(state)
    24. return
    25. except asyncio.TimeoutError:
    26. # Exponential backoff to avoid retry storms
    27. await asyncio.sleep(2 ** attempt)
    28. # After retries are exhausted, move to dead letter queue for compensation or manual handling
    29. state.mark_failed(step_index)
    30. await save_task_state(state)
    31. await send_to_dead_letter_queue(task_id, step_index)

    When implementing this, note the following points. External tools must be able to recognize the same idempotency key; otherwise, retries may produce duplicate side effects. Timeouts should be tiered by tool type rather than using the same value for all tools. Backoff time can include random jitter to reduce many tasks retrying at the same time. The dead letter queue needs monitoring and alerting; otherwise, failed tasks may go unnoticed.

    3. Cloud Integration Approaches

    The core approach to cloud-hosted integration is to delegate sandboxes, state storage, and asynchronous decoupling to mature cloud services, reducing self-built scaffolding. Common components and their applicable boundaries are as follows.

    Component Applicable scenario Considerations
    Managed container services Sandboxes requiring stable resource isolation and elastic scaling Requires dedicated cluster maintenance; image management and cold start need separate planning
    Serverless container instances Burst concurrency and short-duration sandbox execution Cold start latency exists; confirm execution duration and network limits
    Object storage and distributed cache Saving file context and short-term memory Design write consistency and expiration policies; encrypt sensitive data
    Message queues Decoupling long-running tool calls Consumers must handle idempotency; configure maximum delivery attempts and a dead letter queue

    Managed services can reduce low-level code, but they do not automatically eliminate errors in business logic. Teams still need to define their own task state machines and failure handling rules. Before selection, stress test with real workloads; cost mainly depends on concurrency and per-task duration.

    4. Model and Harness Pairing

    Some teams have found that prompts and tool-call formats tuned for one model often need to be adjusted when migrated to another model. Therefore, general-purpose frameworks that emphasize seamless switching may underperform in performance-sensitive scenarios. Deep binding between a model and its harness also comes at a cost: migration becomes more expensive, and every model switch requires re-evaluation.

    A more robust approach is to keep a model adapter layer, bring prompts and tool formats under version management, and run the same evaluation set whenever switching models.

    5. Three Patterns for Multi-Agent Orchestration

    Multi-agent orchestration is being used to build new types of harnesses. Three common patterns are as follows.

    1. Execution and advice separation: The planning agent only outputs plans, and the execution agent handles only a single task. This is suitable for high-risk operations that require human review. Monitor plan adoption rate and execution deviation rate.
    2. Generation and review adversarial: The generation agent produces content, and the review agent checks it according to rules. This is suitable for code and compliance text. If the review agent and generation agent are based on similar models, they may share the same blind spots, so rule-based checks and human spot checks are still needed. Monitor review pass rate, false positive rate, and missed detection rate.
    3. Parallel exploration: Multiple homogeneous lightweight instances search the same codebase in parallel, and results are aggregated into shared state. This is suitable for vulnerability clue collection, defect reproduction, and other parallelizable tasks. Monitor effective findings per call, duplicate discovery rate, and cost.

    Effectiveness data promoted by some tools should not be applied directly to your own business. Measure on your own task set against baselines such as a single agent, and record the task set size and statistical methodology.

    6. Next Steps for Deployment and Security

    Agents are gradually gaining independent identities, call permissions, and long-term memory, so security boundaries need to move earlier. Recommended practices include the following: each agent uses an independent service identity, and permissions are granted with least privilege per task; tool calls pass through gateway authentication and produce audit logs; sandboxes are isolated from the production network; and access to memory and files is isolated by tenant.