Redesigning the Cache for Hybrid-Architecture Agents: A 3x Prefill Throughput Boost
Linear attention, gated linear attention, and state space layers are increasingly combined with full attention to form hybrid LLM architectures that deliver higher throughput and longer context with lower decoding cost. However, agent workloads shift the bottleneck from decoding to prefill, because hybrid models must cache not only KV blocks but also recurrent states. This article analyzes why prefix caching is harder for hybrid models, presents a redesign based on unified cache entries, state checkpoints, prefix-aware scheduling, and tiered storage, and explains how it achieves up to 3.14x prefill throughput and 88.4% lower p90 time-to-first-token on real coding-agent traces, with practical guidance for deployment.
1. Background: For Hybrid Architectures Running Agents, the Bottleneck Shifts from Decoding to Prefill
Linear attention layers, gated linear attention layers, and state space layers are becoming common components in large model architectures. Combined with full attention layers, they form hybrid “full attention + linear/state space” architectures: the full attention layers retain strong global modeling capability, while the linear and state space layers trade for higher throughput and longer context capacity through lower decoding cost and smaller KV cache footprints. For coding-agent workloads that require multi-turn interaction, long-context reading, tool calls, and code modification, this architecture is naturally attractive.
However, agent workloads have a distinctive characteristic: requests are not one-shot Q&A. Instead, the context keeps expanding around the same repository, the same files, and the same task. Multi-turn dialogue, tool outputs, error logs, and code snippets repeatedly enter the prefix, and different branches may share a very long common prefix. Prefix caching for pure Transformers mainly manages KV blocks—when a prefix hits, the prefill for the corresponding tokens can be skipped. Hybrid architectures are different: in addition to the KV cache, the recurrent states of the linear and state space layers must also be maintained. During prefill, the system must restore not only KV but also the states, either by loading or recomputing them, which significantly increases cache management complexity.
2. Why Prefix Caching Is More Complex for Hybrid Models
2.1 KV Is Block-Splittable, but States Depend on the Entire Prefix
The KV cache of full attention layers can be organized into token blocks; on a prefix hit, the corresponding blocks can simply be concatenated or loaded. The states of linear attention and state space layers are usually fixed-size vectors or matrices, but they are derived by recurrent computation over the entire prefix and cannot be naively concatenated by token block. In other words, caching a prefix requires saving not only its KV but also a snapshot of each linear layer’s state at the end of that prefix. Without a state snapshot, the only options are recomputing from scratch or recomputing forward from the nearest checkpoint.
2.2 Agent Workloads Involve Heavy Branching and Rollback
Coding agents frequently loop through “read file—modify—run tests—fail—roll back—modify again.” The context may fork into multiple trajectories from a common prefix, and new content may be inserted after tool calls. A pure KV prefix cache can manage shared blocks with a prefix tree, but a hybrid model additionally requires every tree node to be bound to a state snapshot. Caching states only at the request level yields low branch reuse; storing a full state at every node causes storage and serialization overhead to grow rapidly.
2.3 Prefill Scheduling Must Consider Both KV Loading and State Restoration
Prefill throughput depends not only on GPU compute but also on the restoration path after a cache hit. KV blocks can be loaded from GPU memory, host memory, or remote storage; state snapshots may need deserialization, version validation, and copying to GPU memory. If the scheduler queues requests purely by KV hit rate, situations can arise where KV is ready but states are not, leaving the GPU idle. Hybrid architectures require KV loading, state loading, state recomputation, and batching to be decided jointly within a single cost model.
3. Core Ideas of the Cache Redesign
3.1 Unified Cache Entries: Binding KV Blocks to State Snapshots
A prefix cache entry can be defined as “prefix identifier + token range + KV block references + per-layer state snapshot references + checksum.” On a cache hit, what is returned is not a single KV block but a recoverable hybrid state package. The prefix identifier can be generated from a content hash combined with a structural path, supporting both linear conversations and tree-shaped branches.
# Pseudocode: unified hybrid cache entryentry = {"prefix_id": hash(prefix_tokens, parent_id),"token_range": (start, end),"kv_blocks": [...], # KV block references for full attention layers"layer_states": [...], # State snapshot references for linear/state space layers"checksum": "...","version": model_version}
3.2 State Checkpoints: Balancing Storage and Recomputation
There is no need to save a state for every token. A more reasonable approach is to set state checkpoints by block or by segment: save state snapshots at fixed intervals, restore from the nearest checkpoint on a hit, and recompute only a small number of trailing tokens. Denser checkpoints mean faster restoration but more storage; sparser checkpoints save storage but require more recomputation. In practice, the interval should be configured adaptively based on layer type, state size, request distribution, and storage bandwidth.
3.3 Prefill Scheduling: Shared-Prefix Merging and Pipeline Overlap
The scheduler can first aggregate requests by prefix tree and merge prefill tasks that share the same parent prefix into a single batch. For KV blocks and state snapshots that have already hit, asynchronous loading is used and overlapped with the recomputation of the missed portions. This way, the GPU does not have to wait for all cache restoration to complete before starting computation, and p90 time-to-first-token becomes more stable.
3.4 Tiered Storage and Cross-Node Reuse
The hybrid state cache is well suited to tiered placement: hot KV and states reside in GPU memory, warm data in host memory, and cold data is offloaded to CPU cache or distributed storage. Eviction and prefetching should be driven by a cost model rather than simple LRU. For cross-node reuse, state snapshots require serialization, version validation, and consistency checks to prevent erroneous hits caused by mismatched model or tokenizer versions.
4. Performance Gains and Engineering Explanation
Research has shown that when replaying real coding-agent traces on high-end GPUs, this hybrid state cache redesign can push prefill throughput to up to 3.14x that of a baseline inference engine and reduce p90 time-to-first-token by up to 88.4%. With a 512 GiB CPU cache attached, the gains remain significant, and the design supports distributed storage and cross-node hybrid state reuse. The gains come mainly from three sources: first, reducing repeated state recomputation by converting the recurrence cost of long prefixes into cache restoration cost; second, improving batch utilization during prefill through shared-prefix merging; third, hiding KV and state restoration latency through asynchronous loading and pipeline overlap.
5. Practical Recommendations
During implementation, teams should closely monitor cache hit rate, the number of recomputed state tokens, state loading latency, cache fragmentation, and cross-node hit rate. Checkpoint intervals should be tuned per workload; isolation and version validation between tenants are essential; and the cache metadata service needs high availability. In cloud environments such as Baidu AI Cloud, object storage can hold cold cache data, a container platform can run the scheduling service, and logging, monitoring, and alerting can track hit rates and latency. Overall, optimizing agents on hybrid-architecture models cannot focus on the KV cache alone—KV and recurrent states must be designed as a unified prefix caching object in order to improve prefill throughput and time-to-first-token at the same time.
