Why Your AI Agent Keeps Surprising You (And How to Fix It)

You've probably been there: you ask an AI coding agent to refactor a function, and it returns something that looks right but quietly breaks three downstream callers. The problem isn't the model's intelligence β€” it's the absence of a tight feedback loop.

At scale, this is the same challenge Meta's ads ranking team faced. Their serving stack spans hundreds of models, multiple hardware generations, and millions of hosts. Every unit of compute has a different marginal return depending on the request, the surface, and the system state. Throwing more GPUs at the problem doesn't work β€” you need a system that knows where to spend.

That's the core insight behind Intelligent Delivery: an ML-driven, increasingly AI-operated optimization layer that continuously routes resources toward the highest marginal utility. Since 2017, it has contributed roughly 10% incremental ranking performance on top of model and system advances. And the feedback loop is what makes it predictable.

πŸ“Ž 근거자료: Meta Engineering β€” Intelligent Delivery

Server racks with distributed compute nodes representing Meta's intelligent delivery system for ads ranking Software Concept Art

The Three-Layer Feedback Architecture

Meta's system decomposes the problem into three tightly coupled capabilities. Each one is a feedback loop in disguise.

1. Request Understanding β€” Predict the Return on Compute

Before you can allocate, you must predict. Meta built a Resource Core Model (6B sparse + 20M dense parameters) that runs once per request and is shared across the funnel. It learns embeddings that capture nuanced request patterns manual segmentation can't.

The model is then fine-tuned into specialized heads predicting:

  • Expected outcome (click/conversion lift)
  • Compute consumption
  • Latency impact
# Simplified sketch of a Resource Core Model head
class ResourceHead(nn.Module):
    def __init__(self, backbone):
        super().__init__()
        self.backbone = backbone  # shared 6B sparse / 20M dense
        self.outcome_head = nn.Linear(512, 1)
        self.compute_head = nn.Linear(512, 1)
        self.latency_head = nn.Linear(512, 1)

    def forward(self, request_features):
        emb = self.backbone(request_features)
        return {
            "outcome": self.outcome_head(emb),   # predicted lift
            "compute": self.compute_head(emb),   # predicted cost
            "latency": self.latency_head(emb),   # predicted tail latency
        }

This reframing delivered ~20% improvement in identifying high-impact requests versus the previous production model.

2. Allocation Mechanisms β€” A Hierarchy of Decision Engines

A single controller can't manage a globally distributed fleet. So Meta decomposed allocation into layers:

LayerDecisionSignal Used
RegionWhich data center serves the request?Real-time capacity headroom per region
HardwareWhich SKU (CPU/GPU/MTIA) runs it?Measured efficiency per workload-SKU pair
HostHow much of this machine does it get?Predicted outcome vs. latency cost under SLO
StageHow many candidates to rank?Marginal utility per funnel stage

Each layer is a feedback controller. Shift traffic between regions β†’ per-host load changes β†’ the host-level controller re-balances work. The layers are validated in a closed-loop hardware test environment so you optimize for the global optimum, not a local one.

3. Agentic Optimization β€” The Loop That Watches Itself

This is where it gets interesting for AI coding agents. Meta's team couldn't brute-force millions of tunable dimensions for every new model or hardware generation. Instead, they deployed AI agents that:

  1. Read mechanism source code, design docs, and a decade of experiment logs in a long context window
  2. Narrow the search to a handful of promising changes
  3. Design and run rigorous experiments
  4. Surface the final change to a human engineer for approval

In H1 2026, agents contributed to ~20% of Intelligent Delivery optimizations overall, and ~80% of engineering effort on the most automated mechanism. The optimization loop shrank from months to weeks β€” with humans firmly in control.

This is the pattern that makes AI agents predictable: they don't guess, they propose, test, and converge. The feedback loop is the safety net.

AI agent analyzing system logs and code to optimize resource allocation in a feedback loop Development Concept Image

Limitations and Caveats

  • The moving target problem is real. Every new model, hardware generation, or architecture invalidates prior optimal allocations. Meta's system must re-converge continuously β€” a property most teams underestimate when adopting agentic optimization.
  • Heterogeneous hardware isn't interchangeable. Retrieval is memory-bound, ranking is compute-bound, inference is accelerator-throughput-bound. There is no single "fastest SKU" β€” only a best match per workload. If you're planning a GPU migration, budget time for re-benchmarking every workload-SKU pair.
  • Human oversight is still load-bearing. Even at 80% agent contribution, engineers approve every shipped change. Removing that gate is not a supported pattern yet.
  • GPU optimization is an open frontier. GPU capacity comes in whole fixed blocks, unlike CPU time. The levers built for a CPU world don't transfer directly.

πŸ’‘ ν•¨κ»˜ 보면 쒋은 κΈ€: Engineering Predictable AI Coding Agents: The Power of Strong Feedback Loops β€” a deeper dive into why feedback loops are the difference between a demo agent and a production agent.

Data flow diagram showing ML models predicting marginal utility of compute across heterogeneous hardware Coding Session Visual

What to Take Away

The lesson for anyone building AI coding agents isn't "copy Meta's architecture." It's this: predictability comes from feedback, not from model size.

Three practices you can adopt today:

  1. Predict before you act. Before an agent edits code, have it estimate the blast radius (test coverage, callers, latency impact). That prediction is your first feedback signal.
  2. Decompose allocation into layers. Don't build one mega-controller. Build region-level, host-level, and stage-level controllers that each own a narrow decision and feed back to each other.
  3. Keep humans in the approval loop. Agents propose; humans gate. This is not a limitation β€” it's what makes the system trustworthy enough to run at scale.

Next steps for learning:

  • Read up on TRL v1.0 and post-training library design to understand how training loops shape agent behavior.
  • Study constrained optimization and bandit methods β€” they're the mathematical backbone of allocation controllers.
  • If you're moving to GPU serving, benchmark your actual workloads before assuming throughput scales linearly.
This content was drafted using AI tools based on reliable sources, and has been reviewed by our editorial team before publication. It is not intended to replace professional advice.