Hybrid-Architecture Agent State Caching: Redesigning Prefix Cache for 3x Prefill Throughput
This article examines why prefix cache management is more complex for hybrid LLMs that combine full-attention layers with linear layers, and introduces the FlashStates design for state checkpointing, joint indexing, and tiered distributed storage. It also summarizes measured gains in prefill throughput and TTFT for long-context coding Agent workloads, plus practical lessons for engineering teams building Agent inference services.
Running Agents on Hybrid-Architecture Models: Redesigning State Caching for 3x Prefill Throughput
The Rise of Hybrid Architectures and a New Caching Problem
Recent generations of large language models increasingly use hybrid architectures that combine full-attention layers with linear layers, such as linear attention or state-space layers. The motivation is straightforward: a pure Transformer’s KV cache grows linearly with context length, consuming GPU memory and slowing decoding. Linear layers, by contrast, represent history with a fixed-size recurrent state, so decoding cost is independent of context length. By mixing the two, a model retains the precise retrieval capability of full-attention layers while gaining a smaller cache footprint and faster decoding.
However, when such models are deployed for multi-turn, long-context workloads such as coding Agents, engineering teams quickly encounter a practical issue: prefix cache management for hybrid models is far more complex than for pure Transformers.
In a pure Transformer, prefix reuse is clear. If two requests share the same token prefix, the corresponding KV cache blocks can be reused directly, and block-level hash matching is sufficient. Hybrid architectures introduce new state dimensions:
- Linear-layer state is a rolling compression. After processing a sequence, the linear layer’s state is a function of the entire prefix. There is no independently reusable unit equivalent to a per-block KV entry. Even when two requests share a prefix at a given token position, they can reuse only the complete state snapshot at that position, not finely concatenate pieces as with KV blocks.
- State snapshot granularity does not align with full-attention KV blocks. KV cache is paged in fixed block sizes, while linear-layer state is meaningful only at certain alignment points, such as after processing a fixed-length block. The caching system must coordinate between these two granularities.
- State size and lifetime differ. A single linear-layer state snapshot is usually much larger than a KV block at the same position, and its reuse frequency pattern is different. Applying the same eviction policy directly can cause a sharp drop in hit rate.
The Core Problem: Three Challenges for Hybrid State Caching
Abstracting from these observations, prefix caching for hybrid architectures faces three systemic challenges.
First, checkpoint placement. Linear-layer state cannot be reused at arbitrary positions, so the system must decide at which token boundaries to save state snapshots. If checkpoints are too dense, storage and bandwidth costs explode. If they are too sparse, a prefix hit still requires long-distance recomputation, diluting the benefit of reuse.
Second, joint indexing of cross-layer state. A prefix hit requires both KV blocks from multiple full-attention layers and state snapshots from all linear layers, all from the same prefix position. The cache index must evolve from a single-block hash into a composite structure that maps a prefix position to a set of multi-component state.
Third, coordination across storage tiers. In Agent workloads, session contexts can reach hundreds of thousands of tokens, and GPU memory cannot hold all historical state. State must move across GPU memory, host memory, and remote distributed storage. Moving large state snapshots can easily become a new bottleneck that offsets the compute saved by reuse.
Core Design Approach
To address these challenges, research teams from academia and the inference systems community proposed a system called FlashStates. Its core ideas can be summarized in three parts.
3.1 State Checkpoints as the Minimum Reuse Unit
The system splits a sequence into fixed-length segments and generates linear-layer state checkpoints only at segment boundaries. It binds the full-attention KV blocks at that position and the linear-layer state into one logical cache entry. A prefix hit is then defined as the longest cached segment-aligned prefix. Lookup, hit detection, and loading all operate at segment granularity, and indexing complexity is comparable to a pure KV paging scheme.
3.2 Balancing Computation and Recovery
When a request prefix hits only part of the cache, the system starts from the nearest checkpoint and performs incremental prefill for the missed portion. Because incremental computation in linear layers is inexpensive, the main cost is short-distance recomputation in full-attention layers. By choosing the segment length appropriately, the system can balance snapshot storage overhead against miss recomputation overhead and minimize expected prefill cost. In engineering practice, segment length is often set based on the edit-distance distribution of typical sessions: adjacent turns in coding Agents tend to differ mainly in appended suffixes, so segment-aligned hit rates are naturally high.
3.3 Tiered and Distributed State Storage
Cache entries are placed across GPU memory, host memory, and remote storage according to hotness. Large state snapshots are asynchronously demoted in the background to host memory or even cross-node distributed cache, then prefetched back to GPU memory in a pipelined manner after a hit, overlapping with ongoing decoding. This allows cache capacity to scale to hundreds of GiB and cover the full history of long sessions.
Measured Results
The research team evaluated the system on new-generation data-center GPUs using replayed traces from real interactive intelligent coding tools. The results showed:
- Prefill throughput reached up to 3.14x that of baseline mainstream open-source inference frameworks;
- p90 time to first token (TTFT) was reduced by as much as 88.4%, with especially clear interaction-response improvements in long-session scenarios;
- With a 512GiB-level host-memory extended cache, throughput and latency gains remained significant even when many states were no longer in GPU memory, showing that the tiered pipeline’s prefetch and demotion strategy effectively hides the cost of moving large state snapshots;
- The system supports distributed storage and cross-node hybrid state reuse, allowing multiple Agent session replicas to share the same prefix state.
Implications for Engineering Practice
For teams building their own Agent inference services, this work offers several transferable lessons:
- Treat “state” as a first-class citizen. Under hybrid architectures, the cache system manages not only KV blocks but composite objects of “KV + linear state.” Indexing, eviction, and transfer should all be designed around composite entries.
- Prefer alignment over fine granularity. Segment-aligned coarse-grained reuse may waste a small number of reusable tokens, but it brings a simpler index and a deterministic recovery path. The overall benefit is much higher than pursuing arbitrary-position hits.
- Tiered caching requires asynchronous pipelines. Large state size means slow movement. Prefetch, demotion, and computation must overlap; otherwise, tiering introduces latency instead of reducing it.
- For cloud platform selection, teams can use general object storage for cold state, container platforms for elastic scheduling of inference instances, and monitoring and alerting to track hit rate and TTFT distribution, building a serving system that can be continuously optimized.
Hybrid architectures are becoming one of the mainstream forms of LLM inference, and state cache management is a key part of unlocking their performance benefits. The FlashStates practice shows that with the right cache abstraction, hybrid models can achieve both high throughput and low latency under long-context Agent workloads.
