Hybrid Architecture KV Cache Redesign: How to Accelerate Prefill for AI Agents

    This article explains why hybrid architectures that mix full attention and linear layers struggle with multi-turn agent workloads, where prefix reuse matters more than decode speed. It contrasts the two state types involved—addressable attention KV caches and fixed-size recurrent states—and outlines a hybrid state cache design built on unified prefix addressing, sparse state snapshots at turn boundaries, and hot/cold tiering with prefetching. Engineering guidance and a reproducible validation method are included.

    1. Background: Why Hybrid Architectures Struggle with Agent Workloads

    Over the past year, a clear trend has emerged in mainstream LLM architecture: linear or state-space layers are interleaved between standard full attention layers, producing a hybrid structure of “full attention plus linear layers.” The benefit is direct—during decoding, there is no longer a need to maintain a growing key-value cache for every layer, memory usage drops significantly, and long-sequence decoding becomes more stable.

    But the problems surface once the workload shifts from “single-turn question answering” to scenarios like coding agents. Agents are characterized by multiple tool calls, very long system prompts, repeated reads of the same set of code files, and a small amount of new content appended to an existing prefix on every turn. What really determines the experience here is not decode speed but whether the prefix can be reused. If every turn has to recompute a prefix of tens of thousands of tokens, time to first token (TTFT) deteriorates quickly.

    Hybrid architectures make this harder. In a pure attention model, the cache is a homogeneous set of key-value tensors that can be aligned by token and managed in blocks. A hybrid model holds two kinds of state at once—the key-value cache on the attention side and the recurrent state on the linear layer side. The two have different lifecycles, different addressing schemes, and different migration costs, so a single management policy inevitably trades one off against the other.

    2. The Two State Types Are Fundamentally Different

    Understanding where the optimization room lies starts with seeing how the two state types differ.

    The attention-side cache is “addressable history.” The key and value of token i depend only on that token itself, so it naturally supports splitting by position, hashing by block, and sharing across requests. It has only one problem: its size grows linearly with context length.

    The linear layer state is a “compressed summary.” It folds history into a fixed-size matrix or vector. Its size is constant, but it cannot be split by token—you cannot reuse “the state of the first 4096 tokens” without recomputing, because the state evolves continuously.

    This produces three typical engineering conflicts:

    • Granularity mismatch: block-level prefix reuse is a strength of the attention cache but nearly useless for the state cache.
    • Unsynchronized eviction: evicting under a unified policy can produce a “partial hit” where attention blocks hit but the state is missing, which triggers extra recomputation instead of saving it.
    • Asymmetric transfer: the attention cache is large but can be sharded and pipelined; the state is small but a single point of hard dependency, and easily becomes a serial bottleneck when migrated across nodes.

    3. Core Ideas of the Redesign

    A class of solutions that have appeared recently (referred to here collectively as a “hybrid state cache”) generally follows three main lines.

    First, unified addressing with tiered storage. Both state types are given the same prefix identifier (prefix id), so a single lookup can locate both the attention blocks and the corresponding state snapshot, avoiding partial hits. Sketch:

    1. prefix_id = hash(parent_prefix_id, chunk_tokens)
    2. entry = {
    3. kv_blocks: [block_id ...], # shardable, can be remote
    4. state_snap: state_id, # fixed size, hard dependency
    5. meta: {layers, dtype, seq_len}
    6. }

    Second, sparse selection of state snapshot points. Since the state cannot be split by token, take snapshots periodically at key positions instead—for example when the system prompt ends, when a tool result returns, and when a file read completes—so that agent turn boundaries naturally align with snapshot boundaries and the hit rate is maximized.

    Third, hot/cold tiering and prefetching. The fixed-size state is small and valuable, making it suitable for the hot tier in GPU memory or host memory; the bulky attention blocks sink to host memory or remote storage and are prefetched ahead of time based on the prefix id when a new request arrives, hiding transfer latency inside queueing time.

    4. Implementation Notes

    • Hit rate takes priority over compression rate. Under mixed workloads, one miss and its recomputation costs far more than the extra tens of GB of memory.
    • Eviction must work in pairs. Use the prefix id as the unit for reference counting and least-recently-used decisions so the two state types do not fall out of sync in lifecycle.
    • Make transfer asynchronous. Load attention blocks in a sharded pipeline and send state snapshots over an independent channel to reduce serial waiting.
    • Observability first. At minimum, collect prefix hit rate, state hit rate, prefetch lead time, queueing duration, and TTFT percentiles (p50/p90/p99); otherwise there is no way to tell where the gains come from.
    • Plan capacity by tier. Keep hot states and recent blocks in GPU memory, warm blocks in host memory, and cold blocks in object storage or a distributed cache layer, forming a clear data temperature gradient.

    5. Where the Gains Come From and How to Validate

    The throughput improvement and tail latency gains from a hybrid state cache come mainly from three places: prefix recomputation is eliminated and prefill compute drops; the fixed-size state stays resident, so memory pressure under long context is controlled and higher concurrency is possible; and prefetching plus asynchronous transfer compress queueing and load time, directly improving p90 TTFT.

    Validation should follow a reproducibility principle: replay real multi-turn agent traces, fix the input length distribution and concurrency gradient, record three baselines—“no cache, attention cache only, hybrid state cache”—and report hit rate and recomputed token counts separately. Only by looking at hits and recomputation apart can you confirm the optimization was not bought by sacrificing correctness.

    6. Conclusion

    The payoff of hybrid architectures is shifting from “faster decoding” to “cheaper caching,” and the real bottleneck has moved to state management. Unified addressing, tiered storage, paired eviction, and asynchronous prefetching of the two state types are the key path to stable gains under multi-turn, long-context workloads. For teams building agent platforms, the same approach applies to combining a self-built inference service with general-purpose caching capabilities in the cloud.