3x Higher Prefill Throughput for Agents in Hybrid Architectures

    This article explains why prefill becomes the main bottleneck for AI Agent workloads running on hybrid models that combine full attention layers with linear (state-space or gated recurrence) layers. It covers why hybrid state caching is more complex than standard KV Cache, then presents a redesign based on unified state addressing, checkpoint plus incremental replay, layered reuse with block-level prefetching, and batch-friendly scheduling. It also lists practical implementation tips and common pitfalls, helping teams reduce time-to-first-token without sacrificing output quality.

    1. Background: Agent Workloads Turn Prefill into the Main Bottleneck

    A clear trend has emerged in mainstream LLM design over the past year: to achieve faster decoding and a smaller cache footprint at the same time, more models are adopting a hybrid structure of “full attention layers + linear layers (state-space or gated recurrence types).” A few full attention layers handle long-range precise retrieval, while a large number of linear layers handle low-cost state recurrence. This structure delivers clear benefits in single-turn question answering, but it exposes new problems in Agent scenarios.

    The essential difference between Agents and chatbots lies in the shape of requests:

    • Very short requests: the instruction for a single tool call is often only a few hundred to a few thousand tokens;
    • Very long context: system prompts, tool schemas, historical trajectories, and retrieved fragments keep accumulating;
    • Very dense requests: a single task may trigger dozens of serial or parallel calls;
    • Highly repetitive prefixes: multiple calls within the same task share large identical prefixes.

    Under this workload, the latency users perceive is mainly not “slow token-by-token generation,” but “the first token arrives too slowly”—that is, the time spent in the prefill stage. Prefill must process all input tokens at once. It is compute-intensive and highly parallel, putting pressure on both compute and memory bandwidth. Therefore, improving prefill throughput has become the key engineering problem for deploying hybrid-architecture models in Agent systems.

    2. Why Hybrid Architectures Make Caching Complex

    A traditional pure-attention model has only one form of cache: key-value pairs (KV Cache) stored by layer and by head. Its access pattern is regular, supporting sequential appends by token position, prefix-hash reuse, and block-level eviction.

    A hybrid architecture has two types of state at the same time:

    1. Attention state: grows with token position, supports random access, and naturally enables prefix sharing;
    2. Recurrent state: each linear layer maintains a fixed-size hidden state. It is a compressed representation of “everything from the start to the current position,” independent of specific positions, but once a new token is written in, it cannot roll back.

    This creates three structural conflicts:

    • Semantic mismatch: recurrent state is path-dependent. Even if two different prefixes share the first 1,000 tokens, once they diverge afterward, the state cannot be reused directly;
    • Lifecycle mismatch: attention cache can be long or short, while recurrent state occupies a constant amount of memory, causing memory fragmentation and scheduling difficulties;
    • Eviction mismatch: attention blocks can be evicted and reloaded by reference count, but recomputing recurrent state after eviction is expensive, and simple eviction causes throughput jitter.

    The conclusion is straightforward: forcing both types of state into the same cache management logic inevitably produces a large amount of wasted recomputation and drags down prefill throughput.

    3. Core Idea: Redesigning the Hybrid State Cache

    A widely accepted approach in the industry is to redesign the “hybrid state cache” as a first-class citizen, rather than patching the existing KV management. This can be summarized into four mechanisms.

    3.1 State Decoupling and Unified Addressing

    Abstract the two types of state as different “state objects” within the same addressing space, located by a unified global identifier (prefix content fingerprint + layer type + branch index):

    1. state_key = hash(prefix_fingerprint, layer_type, branch_id, block_index)

    Attention objects can be split into blocks and shared; recurrent objects are periodically persisted as “checkpoints” at key positions, forming a traceable chain of states.

    3.2 Checkpoint + Incremental Replay

    For recurrent layers, there is no need to save state for every token. Instead, save a checkpoint at fixed intervals (such as every N tokens or at each semantic boundary). After hitting a checkpoint, replaying only a few tokens is enough to restore to the branch point:

    1. def restore_state(ckpt, replay_tokens):
    2. st = ckpt.state
    3. for t in replay_tokens: # usually far smaller than the full prefix
    4. st = linear_layer.step(st, t)
    5. return st

    This turns “no reuse possible” into “approximate reuse,” and is the main source of throughput improvement.

    3.3 Layered Reuse and Block-Level Prefetching

    At the scheduling layer, organize requests by a “prefix tree,” identify shared prefixes as common nodes, and perform real computation only on the diverging suffix. At the same time, based on the tool-call topology (which calls can run in parallel and which must be serial), prefetch the state blocks needed for the next hop in advance, overlapping memory transfers with computation.

    3.4 Batch-Oriented Scheduling and Prioritization

    The other half of improving prefill throughput comes from “keeping the compute fed”:

    • Short-request aggregation: pack many short-prefix requests into a large batch to improve matrix multiplication efficiency;
    • Long/short separation: put long-context requests and short requests in separate queues to avoid long requests blocking the head of the line;
    • Preemption and backfill: high-priority requests can preempt; preempted requests keep their checkpoints and recover quickly when backfilled;
    • Memory watermark control: reserve a fixed pool for recurrent state to avoid allocation failures caused by fragmentation.

    With these mechanisms stacked together, in Agent workloads with a high proportion of repeated prefixes, effective prefill throughput can improve by several times—note that the specific multiple is strongly correlated with model structure, prefix repetition rate, and checkpoint interval, and should be based on your own load testing.

    4. Implementation Essentials

    1. Metrics first: separately observe time-to-first-token, prefill token throughput, cache hit rate, and the proportion of recomputed tokens, rather than only looking at total QPS.
    2. Prioritize hit rate: the biggest gain for Agent systems comes from prefix hit rate. Unify how system prompts and tool descriptions are organized to reduce meaningless changes.
    3. Tune checkpoints: too small an interval increases memory usage and write amplification, while too large an interval increases replay cost. It is recommended to scan based on the distribution of prefix lengths in your business.
    4. Elasticity and observability: use a container platform for elastic scaling, use object storage to hold checkpoints and trajectory snapshots, and use logging services and monitoring alerts to locate hit-rate drops and long-tail requests.
    5. Load testing method: build a branching-prefix dataset close to real traffic, compare the metrics of cache reuse on versus off, and form a regression-capable performance baseline.

    5. Common Pitfalls

    • Pitfall 1: optimizing only decoding. The bottleneck in Agent scenarios is often prefill, and optimizing decoding helps little with time-to-first-token.
    • Pitfall 2: evicting recurrent state like KV. Ignoring path dependence leads to a large amount of recomputation.
    • Pitfall 3: pursuing 100% hit rate. Engineering should pursue “high hit rate + controllable replay,” not absolute hits.
    • Pitfall 4: ignoring request organization. If prefixes are unstable on the business side, any cache design will fail.

    6. Conclusion

    The hybrid architecture trades “a few full attention layers + many linear layers” for lower decoding cost and a smaller cache, but shifts the complexity to state management. Rebuilding the hybrid state cache as an independent subsystem—unified addressing, checkpoint replay, layered reuse, and batch-friendly scheduling—is the key path to achieving a several-fold improvement in Agent prefill throughput. Combined with thorough metrics observability and elastic infrastructure, teams can reduce time-to-first-token to a range users are satisfied with, without sacrificing generation quality.