Redesigning Agent Caching for Hybrid Architectures to Boost Prefill Throughput
Hybrid model architectures that combine full attention layers with linear or recurrent state layers pose unique caching challenges for multi-turn AI Agent workloads. This article explains why traditional prefix caching based on key-value blocks falls short when linear state snapshots must also be restored, and presents a redesign that treats KV blocks and linear states as a unified cache unit. It covers segment-based state checkpoints, a benefit-cost eviction model, tiered storage with cross-node reuse, and evaluation metrics. On real coding Agent traces, this approach reportedly improves prefill throughput up to 3.14x over common inference engine baselines and reduces p90 time-to-first-token by up to 88.4%.
Redesigning Agent Caching for Hybrid Architectures to Boost Prefill Throughput
The Problem: Prefix Caching Shifts from “Block Reuse” to “State Reuse”
In recent years, to balance long-context understanding with decoding efficiency, more and more models have adopted hybrid architectures that combine full attention layers with linear or recurrent state layers. Full attention layers excel at precise retrieval and global modeling, while linear layers trade lower state overhead for faster decoding and a smaller KV cache footprint. For typical Q&A workloads, this combination delivers clear benefits. But in coding Agent scenarios—multi-turn, long-context, and frequent tool calls—cache management becomes significantly harder.
In traditional pure-attention models, prefix caching revolves around KV blocks: requests sharing the same prefix can reuse already computed KV blocks, skipping redundant prefill. Hybrid architectures are different. Beyond the KV cache, they must also maintain the recurrent or compressed states produced by linear layers. In other words, reusing a prefix requires not only restoring “what attention has seen” but also “where the linear state has evolved to.” If state snapshots and KV blocks are out of sync, or if state checkpoints are too coarse-grained, you get reuse failures, redundant computation, or even incorrect results.
In real coding Agent trajectories, requests tend to follow a chained structure: system prompts, project documentation, file snippets, conversation history, and tool outputs recur across turns. Prefix similarity is high, but interleaved content is common, making cache hit paths complex. Managing the cache the way a pure Transformer does leads to three problems: first, state and KV caches are handled separately, so hit detection is incomplete; second, long prefixes get invalidated wholesale, forcing extensive recomputation of reusable segments; third, the cache hierarchy stops at single-node GPU memory, preventing cross-node reuse and amplifying first-token latency for long-tail requests.
The Core Idea: Treat “KV Blocks + Linear State” as a Unified Cache Unit
To improve prefill throughput for hybrid architectures under Agent workloads, the key is not to optimize any single layer but to redesign the caching abstraction. A reusable prefix segment can be modeled as a unified cache entry containing four types of information:
- KV block indices: the full attention layers’ KV blocks at specific prefix positions, loadable at block granularity.
- Linear state snapshots: the compressed states of the linear/recurrent layers at the end of the prefix, tagged with a state version and checkpoint position.
- Prefix fingerprint: generated jointly from the model identifier, token sequence, block size, and state version, used to determine whether reuse is safe.
- Lifecycle metadata: last access time, reference count, storage tier, eviction cost, and validation status.
With this design, cache matching no longer just checks “are the KV blocks identical”—it also verifies “can the state be restored.” For partial hits, KV blocks can be loaded per block and linear states restored from the nearest checkpoint, with prefill executed only for missing segments. The following pseudocode illustrates the logic (for illustration only, not tied to any specific interface):
def build_cache_key(model_id, prefix_tokens, block_size, state_version):return fingerprint(model_id, prefix_tokens, block_size, state_version)class HybridCacheEntry:kv_blocks # KV block indices for full attention layerslinear_states # linear layer state snapshots or checkpoint referencesprefix_len # covered prefix lengthstate_version # state version to prevent cross-version misuseref_count # current reference countlast_access # last access timetier # GPU memory, CPU memory, remote storage, etc.def schedule_prefill(request, cache):match = cache.match_longest_prefix(request.tokens,need_kv=True,need_state=True,version=request.model_state_version)if match:request.load_kv_blocks(match.kv_blocks)request.restore_linear_state(match.linear_states)remaining = request.tokens[match.prefix_len:]return build_prefill_batch(remaining, request)
The key point here is “longest verifiable prefix” rather than “longest matching string.” Prefill may only be skipped when both the KV blocks and the state snapshot pass version, position, and integrity checks. For long prefixes that cannot be fully restored, the system can fall back to segment-by-segment reuse via checkpoints instead of invalidating the whole prefix.
Prefix Organization: Segment-Based Checkpoints to Reduce State Restoration Cost
Linear states in hybrid architectures are strongly position-dependent and cannot be freely concatenated the way ordinary KV blocks can. Saving a state snapshot for every token creates excessive storage overhead; saving only the final state of an entire prefix makes reuse granularity too coarse once content is inserted in the middle. A more practical approach is segment-based checkpointing: save state snapshots at fixed block sizes or semantic boundaries, and record the corresponding checkpoint positions in the KV block indices.
When a request hits a long prefix, the system first locates the nearest checkpoint that does not exceed the matched length, restores the linear state from that checkpoint, and recomputes only the small number of tokens after it. This converts “state restoration” from a full recomputation into “checkpoint loading + short-segment recomputation.” The checkpoint interval requires a trade-off among state size, recomputation cost, and hit rate: smaller intervals make restoration more flexible but increase storage and loading overhead; larger intervals save storage but require more recomputation on partial hits.
In practice, different checkpoint policies can be applied to different tiers. Frequently reused system prompts, project-level documentation, and common tool descriptions can use denser checkpoints; rarely accessed long documents can use sparser ones. Cache entries should also record state validation information to prevent stale states from being reused after model version, quantization, or execution backend changes.
Scheduling and Eviction: From “Least Recently Used” to a Benefit-Cost Model
Cache access in Agent workloads is highly uneven. System prompts and project context may be shared by many requests, while a single tool call’s output may only be used by a few subsequent turns. Evicting purely by recency tends to push out highly shared, high-restoration-cost state snapshots, increasing overall prefill volume.
A better eviction policy should account for hit benefit, restoration cost, sharing scope, and tier-migration cost together. A simplified benefit-cost score looks like this:
score = expected_hit_count * saved_prefill_cost- state_load_cost- kv_load_cost- migration_cost
Here, expected_hit_count can be estimated from historical access frequency and the number of child nodes in the prefix tree; saved_prefill_cost depends on segment length, model depth, and batch size; and state_load_cost depends on the state snapshot size and its storage tier. Eviction should prioritize entries with zero reference counts, low sharing scope, and low restoration cost, keeping high-value entries in faster tiers.
The scheduler should also support “prefetching” and “merging.” When multiple requests share the same long prefix, state restoration and KV loading can be merged into a single batch to reduce fragmented loads. When file snippets under a project directory are referenced consecutively, the relevant checkpoints can be prefetched from CPU memory or remote storage into GPU memory ahead of time. This improves prefill throughput while also reducing p90 first-token latency for long-tail requests.
Tiered Caching and Cross-Node Reuse: Making State Cache a Migratable Resource
Single-node GPU memory is limited, and long-context Agent workloads generate large numbers of prefix variants. Hybrid state caches therefore need to be tiered: hot entries in GPU memory, warm entries in CPU memory, and cold entries in remote object or distributed storage. Migration should operate at the cache-entry level, moving KV block indices and state snapshot references together to keep versions consistent at restoration time.
In general cloud environments, the remote persistence layer can sit in object storage, the cache scheduling component can run in a container platform, and hit rate, loading latency, and first-token latency percentiles can be monitored through logging and alerting services. The key here is not any specific product but the tiering principle: hot data near compute, cold data persisted, metadata centrally managed, and migration verifiable and rollback-safe.
For cross-node reuse, consistency and isolation are the main concerns. Each cache entry should carry the model version, state version, block size, checksum, and tenant identifier. Lightweight validation must run before cross-node loading to keep incompatible states out of the execution queue. In multi-tenant scenarios, prefix fingerprints must not leak original text—salted hashing should be used—and shared caches should support per-tenant quotas and reference-count-based reclamation so that long-tail entries do not occupy capacity indefinitely.
Evaluating the Gains: Prefill Throughput and First-Token Latency
According to published experiment descriptions, replaying real coding Agent traces on high-end accelerators, this kind of hybrid state cache redesign improved prefill throughput by up to 3.14x compared with common inference engine baselines, and reduced p90 first-token latency by up to 88.4%. After adding a 512GiB CPU cache tier, the gains remained significant, with further support for distributed storage and cross-node hybrid state reuse.
These numbers show that cache optimization for hybrid architectures cannot focus only on the decoding phase. An Agent request’s first-token latency depends heavily on prefill: system prompts, conversation history, and tool outputs combine into long contexts, and redundant prefill directly inflates TTFT. Through a unified cache unit, segment-based checkpoints, and tiered scheduling, “repeated computation” can be converted into “state loading + short recomputation,” improving both throughput and tail latency.
Evaluation should cover at least the following metrics: prefix cache hit rate, state checkpoint restoration success rate, average restored token count, prefill batch utilization, p50/p90/p99 TTFT, cache entry migration time, GPU and CPU memory usage, and cross-node loading failure rate. Only by examining hit rate together with restoration cost can you judge whether a caching strategy is truly effective.
Implementation Recommendations and Summary
Rollout is best done in three steps. First, model KV blocks and linear states uniformly, ensuring cache keys include both the model version and the state version to avoid hits that look valid but are unusable. Second, introduce segment-based checkpoints and longest-verifiable-prefix matching so that partial hits can be safely reused. Third, build the CPU memory and remote storage tiers, adding benefit-cost eviction and cross-node validation.
Cache management for hybrid architecture models in Agent scenarios is, at its core, an upgrade from “prefix caching” to “hybrid state caching.” It requires the system to understand attention KV data, linear states, prefix structure, and scheduling costs simultaneously. With a unified cache unit, checkpoint-based restoration, tiered migration, and benefit-cost scheduling, redundant prefill can be significantly reduced without changing the model architecture—boosting prefill throughput and improving the first-token latency experience for long-context Agents.
