State Caching for Hybrid-Architecture LLMs and Prefill Optimization in Agent Workloads

    This article explains how to design a state cache for hybrid LLMs that combine full-attention layers with linear-attention or state-space layers, and how to integrate that cache with prefill scheduling for Agent workloads. It contrasts KV-cache reuse with block-boundary-constrained linear-state reuse, describes an atomic snapshot model with tiered and cross-node storage, and discusses scheduler-aware hit estimation. It also covers measured prefill throughput and TTFT tail-latency gains, validation methods using real Agent traces, and deployment considerations for enterprise inference platforms.

    1. Background: Hybrid Architectures Are Mainstream, but Cache Management Is Harder

    In recent years, a new generation of large language models has increasingly adopted hybrid architectures that combine full-attention layers with linear-attention layers or state-space layers. The motivation is clear: full-attention layers handle precise context retrieval and long-range dependency modeling, while linear layers replace a growing KV cache with a constant-size state, improving decoding throughput and reducing memory footprint. Several well-known industry model families have adopted similar structures, and hybrid architectures are becoming one of the de facto standards for long-context models.

    However, architectural benefits do not mean the inference system gets them for free. In Agent workloads such as intelligent coding assistants, requests have multi-turn conversations, very long prefixes, and heavy sharing. Multiple requests in the same session often share tens of thousands of tokens of system prompts and tool-call history. For pure Transformer models, prefix caching only needs to manage reuse of KV tensors. Hybrid models must also save, match, and restore the compressed states of linear layers, and those states have cross-layer dependencies. This makes cache consistency validation, memory layout, and swap-in/swap-out policies an order of magnitude more complex. Reusing traditional cache designs causes many prefixes that could have been hits to be recomputed, making the prefill stage a throughput bottleneck.

    2. Cache Semantics of Hybrid Architectures: Two State Types, Two Semantics

    To design a sound cache system, the first step is to clarify the state composition of hybrid models.

    The first type is the KV cache of full-attention layers. It grows linearly at token granularity and supports arbitrary truncation and reuse at the prefix level. As long as the prefix token sequence is identical, the KV at the corresponding positions is deterministic and can be shared directly.

    The second type is the state of linear layers. Unlike the KV cache, a linear-layer state is a compressed representation of historical information and can be accurately snapshotted only at specific computation boundaries, such as the end of a block. This means state reuse granularity is inherently limited by block boundaries: even if two requests differ only by a few tokens at the end of their prefixes, they may not be able to reuse a state snapshot and must fall back to the previous valid boundary. As a result, the cache matching algorithm cannot simply copy longest-prefix matching from KV cache. State-boundary alignment must be the first principle.

    A common engineering pitfall is to treat the two state types as independent cache pools managed separately. In practice, they must work together: when restoring a prefix, the KV cache and the linear state must come from the same computation and the same position; otherwise, the model output will contain silent errors. Therefore, cache entries should be designed around snapshot points, packing all layer states at that position into an atomic unit.

    3. Core Design: A Unified State Cache Centered on Snapshots

    An effective approach is to redesign the cache management layer for hybrid states. The core idea can be summarized in four points.

    1. Atomic snapshots. When the scheduler identifies a reusable prefix boundary, it serializes all layers at that position—attention-layer KV plus linear-layer states—into an immutable snapshot object. The snapshot carries metadata such as prefix hash, token length, and model version. Hit validation is based on metadata comparison to ensure correctness.

    2. Tiered storage. GPU memory is limited and cannot hold a large number of session snapshots. A reasonable approach is to build a three-tier system: GPU hot cache, host-memory warm cache, and a large-capacity remote or CPU-side distributed cache. The eviction policy should prioritize recently active sessions and the longest shared prefixes. Swap-in should be pipelined and overlapped with prefill scheduling to hide transfer latency. Practical experience shows that even with hundreds of GB of remote cache, the benefit remains significant because state transfer bandwidth is much lower than the cost of recomputation.

    3. Cross-node reuse. In multi-replica deployments, subsequent requests from the same session may be routed to different nodes. By registering snapshots in shared distributed storage and making snapshot location visible to the scheduler—routing requests to nodes that already hold the snapshot whenever possible—hybrid-state reuse can happen across nodes, avoiding duplicate prefill at the cluster level.

    4. Deep integration with the scheduler. Cache hits are not an isolated module; they are an input to scheduling decisions. During queuing, the system should estimate hit rates and transfer costs for candidate nodes and balance locality reuse against load balancing. During prefill batching, requests that share prefixes should be merged first to reduce the number of state reads.

    4. Performance Benefits and Validation Approach

    Evaluations under real coding-Agent trajectory replay workloads show that, compared with the default implementation of a general-purpose inference framework, this redesigned state cache can increase prefill throughput by up to about 3x and reduce first-token latency (TTFT) at high tail percentiles by nearly 90%. The gains come mainly from three areas: repeated computation of long prefixes is eliminated by snapshot hits; pipelining of swap-in/swap-out with computation reduces idle time; and cross-node reuse spreads cluster-wide prefill pressure.

    For teams that want to reproduce similar optimizations, a recommended validation path is as follows. First, build a replay benchmark from real session trajectories, focusing on p50/p90/p99 TTFT and prefill tokens/s. Then enable the three cache tiers—GPU memory, host memory, and remote cache—step by step and observe the marginal benefit of each tier. Finally, analyze hit logs to identify mismatch causes, such as boundary misalignment or hash inconsistency, and iterate on the matching strategy.

    5. Deployment Recommendations and Outlook

    When building an enterprise inference platform, hybrid-state caching should be planned together with general cloud capabilities such as elastic scaling, monitoring and alerting, and object storage. Monitoring should observe hit rates and TTFT distributions, while distributed storage should provide snapshot persistence and cross-node sharing. Looking ahead, as model contexts continue to grow and Agent sessions accumulate more turns, the idea that “state is an asset” will become increasingly important. Whoever achieves a better balance between cache hit rate and transfer cost will be able to serve more concurrent Agent sessions with the same amount of compute. State-cache design for hybrid architectures is becoming a key dividing line for inference-system competitiveness.