State Cache Redesign for Hybrid Architecture Models: Accelerating Agent Prefill
Hybrid architectures that combine full attention with linear and state-space layers are becoming common for agent workloads, but their prefix caching is more complex than KV-only caching. This article explains why state caches need first-class management, describes a unified approach that block-manages KV and state caches, extends radix-tree reuse to state tensors, adds validation and hierarchical storage, and summarizes measured prefill and TTFT gains from real agent traces along with engineering lessons.
Background: Why Hybrid Architectures Are a Mainstream Choice for Agents
In recent years, linear attention and state-space model layers—such as various gated Delta rule variants and state-space sequence layers—have been widely introduced into open-source large models, forming hybrid architectures that combine full-attention layers with linear layers. The motivation is straightforward:
- Faster decoding: Linear layers compress historical information into a fixed-size state matrix. During inference, there is no need to compute attention over the entire history. For long contexts, decoding latency hardly grows with sequence length.
- Lower memory usage: The KV Cache of a traditional Transformer grows linearly with context length, while a linear layer only needs to maintain a fixed-size state cache. In long sessions, memory consumption drops substantially.
As a result, models behind mainstream coding agents and intelligent coding tools increasingly adopt this hybrid architecture to handle multi-turn dialogue, long contexts, and high-concurrency workloads.
The Problem: Prefix Cache Management Is More Complex for Hybrid Architectures
Agent workloads have typical characteristics: multiple interaction turns, a long shared common prefix across turns, and continuously growing context. In this setting, prefix caching is critical to performance. If every turn has to recompute the entire history from scratch, prefill overhead will erase all architectural advantages.
For pure Transformers, prefix caching is relatively simple: manage the KV Cache by blocks and reuse it on a hit. Hybrid architectures introduce new complexity:
- Heterogeneous cache structures: In the same model, attention layers cache a gradually growing KV Cache, while linear layers cache fixed-size state tensors. Their block granularity, reuse conditions, and memory layouts are completely different.
- Nonlinear dependency of state: The state of a linear layer is obtained by recursively processing the historical sequence step by step. Any token change in the prefix cascades to subsequent states, so the state cannot be reused simply by positional block like KV.
- Blind spots in traditional serving frameworks: Many inference frameworks design prefix caching for KV Cache and lack first-class support for state caches. As a result, hybrid models under agent workloads suffer from low cache hit rates, and prefill throughput is severely underestimated.
The Solution: Unified Management of KV and State Caches
The latest industry approach is to elevate state caches to the same management level as KV Cache and redesign the cache system for hybrid architectures. The core points include:
Block management of state caches. Organize the state of linear layers using the same block boundaries as attention layers so that the reuse granularity of the two cache types is aligned. When a prefix block is hit, the corresponding KV block and state block are reused together, avoiding a partially invalid state in which KV hits but the state must be recomputed.
Extended reuse with a radix structure. Drawing on radix-tree-style prefix indexing, attach state tensors to prefix-tree nodes. As long as multiple agent sessions share a prefix, both KV and state can be reused, enabling state reuse across requests and sessions.
Fine-grained invalidation and validation. Because state is more sensitive to the token sequence than KV, the approach records token-range validation information for each state block to ensure correctness during reuse and prevent state pollution caused by partial prefix matches.
Hierarchical storage and cross-node reuse. Under agent workloads, even compressed caches may exceed single-machine GPU memory. The approach supports offloading state caches to CPU memory and even distributed storage, forming a hierarchy of GPU memory, memory, and remote storage. When a remote state is hit, the context can be restored through one bulk transfer, at a much lower cost than full recomputation.
An illustrative cache management logic is as follows:
# Pseudocode: unified prefix cache lookupdef lookup(prefix_tokens):node = radix_tree.match_longest(prefix_tokens)kv_blocks = node.kv_cache # Attention-layer cachestate_blocks = node.state_cache # Linear-layer state cacheif kv_blocks and state_blocks and verify(node, prefix_tokens):return reuse(kv_blocks, state_blocks)return recompute_from(node.last_valid_pos)
Performance Gains: Results on Real Agent Traces
On flagship data-center GPUs, replay tests using multi-turn interaction traces from real intelligent coding tools showed:
- Prefill throughput improved by up to more than 3x, an order-of-magnitude-level improvement over default implementations in general inference frameworks.
- Long-tail first-token latency (TTFT) improved significantly, with p90 reduced by up to nearly 90%. This means the “stutter” in multi-turn agent interaction is largely eliminated.
- After adding large-capacity CPU-side cache, the gains remained, showing that the hierarchical storage strategy is effective under real workloads.
- The approach supports distributed deployment, where multiple nodes can share state caches and further improve cluster-level cache hit rates.
Engineering Takeaways
For teams building agent inference services, the article offers several general recommendations:
- When evaluating hybrid models, stress-test prefill with real multi-turn traces rather than looking only at single-turn decoding speed.
- Including state caches in the prefix reuse system is a prerequisite for hybrid architectures to deliver performance.
- For long-context agent scenarios, plan the GPU-memory, memory, and remote-storage hierarchical cache design as early as possible.
- Cache correctness validation cannot be omitted. Errors in state reuse can silently contaminate output quality.
Hybrid architectures are an important direction for large-model serving, and redesigning the cache management system is the key step to actually realizing the architectural benefits.
