Hybrid Architecture Agent Cache Redesign and Prefill Throughput Optimization
As large model inference architectures evolve toward hybrid structures combining full-attention and linear/state-space layers, managing prefix caches for Agent workloads becomes increasingly complex. This article explores the challenges of hybrid architecture caching, including mismatched lifecycles between KV caches and recursive states, and the overhead of repeated prefill computations. It introduces a cache redesign strategy utilizing unified prefix keys, two-tier caching (KV paging and state snapshots), and incremental prefill. By aligning these mechanisms, the approach eliminates redundant computation, reduces recovery costs, and can achieve up to a 3x improvement in prefill throughput under specific Agent workloads.
Hybrid Architecture Agent Cache Redesign and Prefill Throughput Optimization
1. Background: Why Hybrid Architectures are Gaining Traction in Agent Scenarios
Recent years have seen LLM inference architectures evolve from using entirely full-attention layers to hybrid structures combining full-attention layers with linear attention layers or state-space layers. Full-attention layers excel at accurately modeling long-range dependencies, but their KV Cache grows linearly with context length. Linear attention and state-space layers process historical information recursively or via compressed states, resulting in lighter computation during decoding and smaller cache footprints. Combining these two layer types offers a balanced trade-off among performance, decoding speed, and memory usage, making it a popular choice in modern model architecture design.
However, once hybrid architectures are applied to workloads like coding agents, tool-calling agents, or multi-turn conversational agents, cache management becomes more complicated than merely storing the KV Cache. Agent requests typically exhibit the following characteristics:
- Multi-turn: A single task involves planning, tool calls, observation results, corrections, and replanning.
- Long context: Code files, logs, retrieval results, and tool outputs are constantly appended to the context.
- Strong prefix reuse: Subsequent turns within the same session often reuse all or most of the prefix from the previous turn.
- Branching and rollback: Agents may try different approaches, generating multiple context branches that require returning to a specific historical node.
- Concurrency and isolation: Multiple users, sessions, and toolchains run in parallel; caches must be both shareable and isolated.
Under these workloads, prefix cache management for hybrid architectures is more complex than for pure full-attention models. Pure full-attention models primarily manage KV tensors, whereas hybrid models must also manage the recursive states of linear/state-space layers. These states are not simple concatenations of historical tokens; they are compressed representations accumulated sequentially. If the prefix changes, the state cannot be merely truncated like a KV Cache. Instead, it often needs to be recomputed from a stable checkpoint. Therefore, cache design directly dictates the amount of redundant computation during the prefill phase, ultimately determining agent inference throughput and Time-To-First-Token (TTFT).
2. Three Core Challenges of Hybrid Architecture Caching
2.1 Inconsistent Lifecycles for Two Cache Types
The KV Cache for full-attention layers can be stored in pages by token position, allowing new token KVs to be appended upon a prefix hit. Conversely, the state of linear/state-space layers is the result of recursion, typically retaining a fixed-size state vector or matrix per layer. The former is a “growable sequence cache,” while the latter is a “snapshotable state cache.” Their capacity, update methods, invalidation conditions, and recovery costs differ. Managing them separately can easily lead to scenarios where the KV hits but the state misses, or where the KV positions become inconsistent after state recovery.
2.2 Recursive States Cannot Be Simply Truncated
Suppose a session has already computed state S based on a historical prefix P. When an agent appends new tool output, computation can continue from S. However, if content is inserted into the middle of the history, tool returns are modified, or a branch is switched, P is no longer the prefix of the new context, and S cannot be directly reused. In this case, the system must find the most recent common prefix checkpoint, restore the state to that checkpoint, and recompute the differing segments. If the checkpoint granularity is too coarse, the recomputation volume is high; if too fine, the number of snapshots and memory overhead increase.
2.3 The Prefill Phase is Easily Slowed by Redundant Computation
In multi-turn agent requests, a large number of tokens have already been processed in the prefill of the previous turn. Without a reliable prefix cache, the system repeatedly prefills system prompts, code contexts, and historical tool outputs. Full-attention layers redundantly compute KV, while linear/state layers redundantly accumulate recursive states. The combination of both significantly inflates prefill latency. The goal of cache redesign is not simply to add compute power, but to transform “already computed prefixes” into recoverable checkpoints, allowing the prefill to process only the incremental tokens.
3. Core Redesign Strategy: KV Paging and State Snapshot Synergy
A cache solution tailored for hybrid architecture agents should revolve around unified prefix identification, two-tier caching, checkpoint recovery, incremental prefill, and prefix-aware scheduling.
3.1 Unified Prefix Key: Aligning KV and State
The cache key should not only contain the session ID but also elements like model version, layer configuration version, context prefix hash, token range, and branch ID. This ensures that both the KV cache and state snapshots point to the same logical prefix. For agent branching scenarios, “session ID + branch ID + prefix hash” can locate the cache. For appended tool output scenarios, incremental block hashes can be used for verification to prevent incorrect reuse.
Example pseudocode:
class HybridPrefixKey:def __init__(self, model_ver, tokenizer_ver, session_id,branch_id, prefix_hash, token_range):self.model_ver = model_verself.tokenizer_ver = tokenizer_verself.session_id = session_idself.branch_id = branch_idself.prefix_hash = prefix_hashself.token_range = token_rangedef as_tuple(self):return (self.model_ver, self.tokenizer_ver, self.session_id,self.branch_id, self.prefix_hash, self.token_range)
Model and tokenizer versions must participate in the key calculation; otherwise, reusing old caches after model updates or tokenizer changes poses correctness risks. The prefix hash quickly identifies the reusable range, while the token range restores positions.
3.2 Two-Tier Cache: KV Paged Cache + State Checkpoint Cache
Two cache tiers can be maintained:
- KV Paged Cache: Stores KV tensors for full-attention layers by layer, head, and page. Supports reference counting, prefix sharing, and on-demand eviction.
- State Checkpoint Cache: Stores state snapshots for linear/state-space layers at specific positions per layer. Supports continuing recursive computation from the checkpoint.
The two tiers are associated via the unified prefix key. Upon a hit, the system first queries the state checkpoint, then the KV pages. During recovery, both state and KV are loaded simultaneously to ensure subsequent layer computations see a consistent history. For misses where a longer common prefix exists, it falls back to the nearest checkpoint and recomputes only the differing tokens.
3.3 Checkpoint Granularity: Balancing Recomputation Cost and Memory Amplification
State checkpoints should not be saved for every token. A “fixed interval + key event trigger” strategy can be adopted: save every N tokens, with additional saves at critical points like the end of a system prompt, tool call returns, branch creation, or context compression. A smaller interval means faster recovery but larger snapshot memory; a larger interval saves memory but increases recomputation during branch rollbacks. In practice, this can be dynamically adjusted based on agent turn length, branch frequency, and memory budget.
3.4 Incremental Prefill: Computing Only the Unmatched Suffix
When a request arrives, perform block hashing on the complete prefix to find the longest matched prefix. If a state checkpoint is hit, restore the states of all layers from it. If KV pages are hit, restore the KV. Then, execute prefill only on the suffix tokens. Incremental prefill significantly reduces redundant computation, especially when system prompts are long, tool outputs recur, or the same session has consecutive turns.
4. Mechanisms Behind the ~3x Prefill Throughput Improvement
Under suitable multi-turn agent workloads and high prefix reuse rates, related solutions report approximately a 3x improvement in prefill throughput. This gain does not come from a single optimization but is the cumulative result of multiple mechanisms.
First, eliminating redundant prefix computation. System prompts, historical conversations, and read code often occupy the majority of tokens in an agent request. Upon cache hit, these tokens no longer enter the prefill compute graph, reducing the workload from the “full context” to the “incremental suffix.”
Second, state snapshots reduce recovery costs. If linear/state-space layers recursively accumulate from scratch every time, the cost under long contexts cannot be ignored. Checkpoint recovery transforms “accumulating from scratch” into “continuing from the latest snapshot,” reducing serial overhead caused by sequential dependencies.
Third, prefix-aware batching improves utilization. The scheduler can merge multiple requests sharing the same prefix into a single batch, performing a common prefix prefill once, then computing their respective suffixes. In concurrent agent scenarios, multiple branches may share a large amount of history, and intra-batch sharing boosts GPU utilization.
Fourth, asynchronous snapshots and paging management reduce blocking. State snapshots can be asynchronously flushed to disk or written to the cache pool after prefill. KV pages are shared via reference counting, avoiding frequent copies. The eviction policy prioritizes clearing cache pages with low reuse, low references, and long idle times to reduce memory pressure.
It should be emphasized that the 3x figure is a result under specific experimental conditions and workload characteristics. Actual gains depend on prefix hit rate, state checkpoint granularity, concurrency sharing degree, model layer configuration, and memory bandwidth. Engineering evaluations should focus on the hit distribution of their own agent workloads rather than simply applying a fixed multiplier.
5. Implementation Points for Agent Scenarios
5.1 Manage Branches with a Session Tree
An agent’s trials, rollbacks, and parallel approaches naturally form a tree-like context. Each node can store “parent node, incremental tokens, prefix hash, state checkpoint reference.” During a rollback, directly locate the ancestor node, restore its KV and state, and compute the new branch. This is more aligned with agent behavior than linear session caching.
5.2 Perform Content Verification for Tool Outputs
Tool returns may vary due to timing, environment, or randomness. The cache key should include a content hash of the tool output to prevent incorrectly reusing old tool results for new requests. For mutable file contents or log snippets, it is recommended to use content hashes rather than just positions as verification criteria.
5.3 Multi-Tenant Isolation and Security
Cache sharing must be confined within tenant or session boundaries. Cross-tenant prefix sharing poses data leakage risks. Even if system prompts are identical, cache keys should be isolated via tenant namespaces. For sensitive contexts, persistent snapshots can be disabled, retaining only short-term in-process caches.
5.4 Observability Metrics
It is recommended to monitor at least: prefix hit rate, state checkpoint hit rate, average recovered tokens, prefill token throughput, Time-To-First-Token (TTFT), cache memory amplification ratio, eviction rate, branch rollback recomputation volume, and cache verification failure rate. These metrics help identify whether the issue is insufficient KV paging, sparse checkpoints, or scheduling failing to reuse common prefixes.
6. Simplified Pseudocode: An Incremental Prefill Flow
def prefill_with_hybrid_cache(request, cache, model):key = build_prefix_key(request)hit = cache.find_longest_prefix(key)if hit.has_state_checkpoint:state = cache.load_state(hit.checkpoint_id)else:state = model.init_state()if hit.has_kv_pages:kv = cache.load_kv_pages(hit.page_ids)else:kv = empty_kv_cache()suffix = request.tokens[hit.matched_len:]state, kv, logits = model.prefill_incremental(suffix_tokens=suffix,init_state=state,init_kv=kv,positions=request.positions[hit.matched_len:])cache.save_kv_pages(key, kv)if should_checkpoint(request, hit.matched_len + len(suffix)):cache.save_state_checkpoint(key, state)return logits, state, kv
This pseudocode reflects three principles: find the longest prefix first, restore state and KV, and finally compute only the suffix and write back to the cache. Actual implementations must also handle inter-layer consistency, paging reference counting, asynchronous write-backs, and failure fallbacks.
7. Conclusion
Hybrid architecture models bring lighter decoding and smaller cache footprints to agent inference, but they also upgrade prefix cache management from “single-type KV management” to “synergistic management of KV paging and recursive state snapshots.” For multi-turn, long-context, highly branching agent workloads, the correct approach is to align the two cache types with unified prefix keys, reduce recursive recovery costs with state checkpoints, eliminate redundant computation via incremental prefill, and improve batching efficiency with prefix-aware scheduling, all while using observability metrics to continuously calibrate checkpoint granularity and eviction policies. Only by balancing correctness, isolation, and performance can the redesign of hybrid architecture caches translate into stable prefill throughput gains.
