Agent State Caching Optimization for Hybrid LLM Architectures

    This article examines why prefix caching becomes difficult for agent workloads on hybrid attention/linear LLM architectures, where KV cache and recurrent state differ in granularity and lifecycle. It describes a unified hybrid-state cache design built around joint indexing, tiered storage and asynchronous swapping, scheduler-aware affinity, and cross-node reuse. Replay tests on real coding-agent traces show up to 3.14x higher prefill throughput and up to 88.4% lower p90 TTFT, followed by practical recommendations for production deployment.

    1. The Rise of Hybrid Architectures and the Caching Challenge

    In recent years, mainstream open-source large language models have gradually shifted from pure attention architectures to hybrid designs combining full-attention layers with linear layers. These architectures maintain a fixed-size recurrent state in the linear layers, replacing the key-value cache that grows linearly with sequence length. The result is faster decoding and lower memory usage. For online services where decoding is the bottleneck, this is an attractive trade-off.

    The problem becomes more complex when the model is used for long-context workloads such as coding agents and multi-turn conversational agents. These workloads typically carry a large historical prefix with every request—system prompts, tool definitions, code and execution results from earlier turns—and append only a small amount of new content at the end. As a result, whether the prefix cache hits directly determines the amount of computation in the prefill phase.

    In pure attention models, prefix caching only needs to manage one data structure: the KV cache. It is token-aligned, can be truncated and reused at arbitrary positions, and has relatively mature engineering implementations. Hybrid architecture models, however, have two types of state at the same time:

    • KV cache in attention layers: organized at token granularity and truncatable at any position.
    • Recurrent state in linear layers: a single tensor produced by compressing the entire prefix. It can only be restored at specific checkpoints and cannot be split arbitrarily.

    The two state types have completely different sizes, alignment granularities, and lifecycles. Traditional cache managers cannot handle them uniformly, so hybrid models achieve a much lower cache hit rate than the theoretical value in agent scenarios, and prefill overhead remains high.

    2. Core Design for Hybrid-State Cache Management

    To address these issues, a new hybrid-state cache management approach has been proposed. Its core idea is to treat linear-layer state as a first-class citizen equal in status to the KV cache and to apply unified indexing, scheduling, and tiered storage. The design can be summarized in four points.

    2.1 Joint Indexing and Matching for Two State Types

    The approach records both the KV cache block table and recurrent-state checkpoints for each prefix segment. When a new request arrives, the matching logic no longer searches only for the “longest reusable KV prefix.” Instead, it solves a joint matching problem: find the longest prefix position p such that the KV cache is reusable at p and a usable recurrent state exists at p or at the nearest checkpoint before p. This avoids the worst case where the KV cache hits but the state is missing, forcing a full recomputation.

    Checkpoint insertion strategy is also critical. Too few checkpoints waste matching opportunities, while too many increase storage and write overhead. In practice, checkpoints are usually written in a rolling manner at fixed token intervals—for example, every few thousand tokens—and adaptively adjusted based on prefix heat.

    2.2 Tiered Storage and Asynchronous Swapping

    Although individual recurrent-state tensors are not large, their number can be substantial under high concurrency. The approach uses a three-tier hierarchy: GPU memory, host memory, and a remote distributed cache.

    • Hot states reside in GPU memory, ensuring zero-copy availability after a hit.
    • Warm states are swapped out to host memory and prefetched back to GPU memory via asynchronous DMA during scheduling gaps.
    • Cold states are written to a large-capacity distributed cache pool built on CPU memory, enabling cross-node reuse.

    Because agent workloads have strong locality—multiple requests for the same task tend to arrive in a burst—even a remote cache hit saves far more recomputation time than the network transfer overhead.

    2.3 Scheduler-Aware Cache Affinity

    The cache system and the request scheduler must work together. The approach introduces a state affinity score during scheduling: requests are preferentially scheduled to nodes that already hold their prefix states. Under GPU memory pressure, the system evicts states “least likely to be reused by subsequent requests” rather than using simple LRU. For agent sessions, session IDs can also be used for soft binding, significantly reducing the frequency of cross-node state migration.

    2.4 Distributed State Reuse Across Nodes

    In a cluster environment, the approach supports publishing hybrid states to a shared storage layer so that different inference nodes can pull prefix states produced by one another. This is especially important for multi-instance elastic scaling: newly scaled instances do not need to cold-start and recompute common prefixes such as system prompts and tool schemas; they can directly reuse existing states.

    3. Measured Gains: Replay with Real Agent Traces

    The approach was tested on the latest-generation data center GPU using replay of real coding-agent session traces. The results show:

    • Prefill throughput: up to about 3.14x improvement compared with the default cache implementation of a widely used high-performance inference engine.
    • Time to first token (TTFT): p90 tail latency dropped by up to 88.4%, meaning the response experience for the vast majority of requests improved substantially.
    • Large-capacity cache support: after adding about 512GiB of host-side cache, the gains remained significant. This indicates that the benefits do not come only from GPU memory hit rate; the tiered design itself continues to deliver value in longer sessions and under higher concurrency.

    It is worth emphasizing that the tests used real traces rather than synthetic workloads. Prefix overlap patterns in real agent sessions are highly irregular—code files are repeatedly modified, and tool outputs are interleaved—which exposes cache management weaknesses more effectively than regular multi-turn dialogue. The results therefore have strong reference value.

    4. Practical Recommendations for Production Deployment

    For teams that want to optimize hybrid-model agent services on their own infrastructure, the following recommendations are broadly applicable:

    1. Quantify before optimizing: establish monitoring and alerting baselines for prefix hit rate, recomputed tokens per request, and TTFT percentiles. Confirm that the bottleneck is state management rather than compute capacity itself.
    2. Unify the state abstraction: whether building in-house or adopting new features from an inference framework, incorporate recurrent state into the same allocator and lifecycle management as the KV cache to avoid inconsistent metadata across two systems.
    3. Leverage tiered caching: host memory costs far less than GPU memory. By combining general cloud capabilities such as object storage or distributed memory pools, teams can expand cache capacity by an order of magnitude at relatively low cost.
    4. Couple scheduling with caching: when deploying inference services on container platforms, use session-affinity routing and state-aware scheduling to prevent caches from being scattered by load-balancing policies.
    5. Run regression tests with real traces: synthetic stress tests tend to overestimate hit rates. Collect desensitized production session traces for replay evaluation to validate the benefits under real distributions.

    5. Conclusion and Outlook

    Hybrid architecture models trade fixed-size linear state for decoding efficiency, but they shift complexity into prefix cache management. The hybrid-state cache redesign described in this article demonstrates that joint indexing of two state types, tiered storage, scheduler cooperation, and cross-node reuse can deliver more than 3x prefill throughput improvement and nearly a 90% reduction in tail latency on real agent workloads. As agent applications move toward longer task chains and larger concurrency, state cache management will replace pure operator optimization as a key differentiator for inference systems. For engineering teams, establishing a unified state management abstraction and evaluation system early is the most practical way to prepare for this trend.