Hybrid State Caching for Higher Agent Prefill Throughput

    This article explains why prefix caching becomes more complex in hybrid attention-linear architectures, breaks down a three-part hybrid state caching scheme, and outlines what performance claims actually mean, what trade-offs exist, and what to verify before adopting the approach in multi-turn, long-context agent workloads.

    Hybrid architectures make prefix caching harder

    Recent frontier models increasingly adopt a hybrid structure that combines full attention layers with linear layers. Linear layers reduce decoding cost and cut the GPU memory occupied by KV caches. But in agent scenarios such as AI coding tools, where requests are multi-turn and carry long contexts, every request includes a large amount of historical content. If the inference engine recomputes from scratch each time, it wastes a significant amount of computation on repeated work. Caching only the KV cache does not allow the linear layer states to be reused directly, leading to incomplete computation or requiring additional patch-up logic.

    Where pure Transformer and hybrid architectures differ in caching

    In a pure Transformer, the KV cache can be partitioned into independent blocks, stored separately, and matched directly by prefix. In a hybrid architecture, the linear-layer state is the result of compressing the entire sequence; a prefix cannot be simply cut off and re-spliced.

    Two specific points stand out.

    1. State dependency: In a full attention layer, KV values can be saved per token block. In a linear layer (such as an RNN variant or a state-space model layer), the hidden state depends on all preceding tokens; the current state must be computed after the state from the previous time step.
    2. Context concatenation: In agent requests, system prompts, code-base snippets, and conversation history appear in alternation. When new content is appended, the system must continue computing from the state where the previous request left off. If state management is not precise, computation errors or memory alignment failures can occur.

    What the three parts of a hybrid state caching scheme cover

    The scheme described in the original article manages the KV cache and the linear-layer state within the same orchestration framework. It has three main components.

    1. State-aware memory layout: When allocating memory, the KV values of the full attention layers are bound to the linear-layer state at the same time step and placed in adjacent addresses. When loading a historical prefix, the system reads the complete state in one operation, reducing address lookup and data movement across memory pools.
    2. Incremental state updates: When appending new context, the system continues computation based on the previously saved state tensor and the new tokens, without replaying the entire history. For linear layers, this makes prefill cost grow roughly linearly with the length of the newly added segment. Full attention layers still require computation proportional to the historical KV length, so overall cost is not always linear.
    3. Hierarchical eviction: Not all historical states need to stay resident in GPU memory. Frequently used prefixes, such as system prompts, can be marked as hot data, while intermediate reasoning steps can be demoted to cold storage. The original article only describes the idea of “importance-score-based eviction” and does not provide a scoring formula. For actual implementation, three things need to be defined: the scoring criteria (e.g., hit count, last access time, recomputation cost); the eviction granularity (entire session vs. fixed-size state blocks); and the handling of a wrongly evicted state (recompute from the most recent valid snapshot, or recompute the entire sequence).

    How to interpret the reported performance numbers

    The original article reports that when replaying real coding-agent traces on high-performance GPUs, prefill throughput reached up to 3.14× that of a traditional framework, and the P90 time-to-first-token (TTFT) decreased by up to 88.4%. Both figures are peak values, not averages, and do not imply the same benefit for all workloads. The original article does not disclose the following test conditions:

    Item What needs to be confirmed
    Model Name, number of parameters, ratio of full attention layers to linear layers
    Hardware GPU model and count, CPU memory and storage configuration
    Baseline Name and version of the compared framework, and whether its built-in prefix caching was enabled
    Workload Trace length, number of conversation turns, concurrency, prefix hit rate
    Metrics Statistical range for throughput, start and end points for TTFT, and method used for percentile calculation

    Before citing these numbers, locate the original technical report and verify the above conditions. Numbers without context indicate direction only, not expected gains.

    Trade-offs compared with common practices

    Dimension Full recomputation KV cache only Hybrid state cache
    Computation after prefix hit Recompute everything Linear layers still need recomputation Continue from saved state
    Implementation complexity Low Medium High; state versions must be maintained
    Main risks High latency, wasted compute Incomplete states leading to computation errors State and KV becoming inconsistent, wrong eviction
    Suitable scenarios Short contexts, low concurrency Models with a high proportion of full attention layers Multi-turn long contexts, models with a high proportion of linear layers

    What to watch for in cross-node state reuse

    In a multi-node, multi-GPU environment, the system may migrate existing states to other nodes to avoid re-running forward computation. This approach introduces the following issues.

    • Storage hierarchy: GPU memory holds hot data, while CPU memory or SSD holds cold data. The CPU memory pool size should be estimated based on the number of sessions and the state size per session. The 512 GiB mentioned in the original article is only a configuration example and should not be copied directly.
    • Consistency validation: A state can be reused only when the model weights, tokenizer, configuration parameters, and model version are identical. Hash values or version numbers should be checked before loading.
    • Authentication and isolation: In multi-tenant environments, states may contain user code and conversation content. Access permissions must be controlled per session.
    • Failure fallback: If validation fails or a transfer times out, the system should fall back to recomputation and record the fallback ratio. If the fallback ratio is consistently high, the benefit of the scheme is limited under the current workload.

    Storage and scheduling can be handled by generic object storage and container platforms; the specific choice depends on the team’s existing infrastructure.

    Three checks to perform before adoption

    1. Replay your own real agent traces, recording prefix hit rate, prefill latency, and the P50 and P90 of TTFT.
    2. Run the same inputs with state caching enabled and disabled, and compare output for consistency. If discrepancies appear, inspect the state update and eviction logic first.
    3. Set up monitoring and alerts for state validation failures, and confirm that the fallback recomputation time remains acceptable.

    Hybrid state caching targets a specific bottleneck in multi-turn, long-context agent scenarios. How much benefit it delivers depends on model architecture, workload patterns, and implementation quality, so it must be validated with your own data.