Optimizing KV-Cache Loading with a Dual-Path Approach for Agentic Inference

    This article explains why data movement, rather than compute, often bottlenecks agentic LLM inference, and how a dual-path KV-Cache loading design separates decode and prefill traffic. It covers the core resource contention problem, scheduling design, key engineering practices, evaluation metrics, common pitfalls, and deployment suggestions on Baidu AI Cloud.

    1. Background: Why Agentic Inference Gets Stuck on Data Movement

    In agentic scenarios, model inference is rarely a single question-and-answer exchange. It is a long-chain workflow made up of multiple tool calls, retrieval augmentation, code execution, and result write-back. Each round brings longer context, more intermediate state, and more frequent session restoration, so both the size and the access frequency of the KV-Cache keep growing. At that point, the bottleneck is often not compute but the process of moving data to the compute units.

    Mainstream inference architectures split execution into two stages: prefill and decode. Prefill processes the input prompt in one pass and produces the internal representation (the KV vectors); decode then generates output autoregressively, token by token. To avoid redundant work, systems reuse the historical KV-Cache instead of recomputing the same prefix. But this reuse shifts pressure from the compute side to the read side: once the cache sits outside the compute units, storage network bandwidth, memory capacity, and concurrent access all become new constraints.

    The tension is more visible in multi-turn conversations. Historical messages computed in a previous turn do not need to be recomputed in the next request; they only need to be loaded from cache. That loading step itself consumes a large amount of bandwidth. If prefill and decode share the same loading channel, you get a resource mismatch in which prefill is busy moving data while decode has nothing to do, dragging down overall utilization.

    2. The Core Conflict: Resource Mismatch and Bandwidth Contention

    A single inference request can be broken into two kinds of resource demand: compute-intensive and movement-intensive. Prefill is compute-intensive, but under cache reuse it also becomes movement-intensive; decode has relatively steady compute demand yet is latency-sensitive. When both workloads are bound to the same resource path, they end up waiting on each other.

    In resource-constrained environments, simply adding more accelerators is not always a viable option. A more practical path is to raise the output efficiency of the existing hardware. The dual-path idea starts right there: since the decode side has spare loading and network capacity, it can take on part of the cache movement work and divide labor with the prefill side instead of waiting passively.

    3. Design of Dual-Path Loading

    “Dual-path” can be abstracted as two parallel loading channels: one serving the decode path for latency-sensitive, small, frequently accessed blocks, and the other serving the prefill path for large, highly sequential historical context loads. Both are orchestrated together at the scheduling layer while remaining consistent at the data layer.

    The scheduling pseudocode below is illustrative only; it expresses the division of responsibility and does not correspond to any specific API:

    1. schedule(request):
    2. if request.stage == PREFILL and cache.is_reusable(request.prefix):
    3. path = choose_path(load_size=large, latency_sensitive=false)
    4. else:
    5. path = choose_path(load_size=small, latency_sensitive=true)
    6. async load_kv(cache, path)
    7. overlap_with_compute(path)

    The design has three key points. First, workload identification: distinguish large sequential loads from small random accesses so that latency-sensitive decode requests are not queued behind long jobs. Second, path isolation and sharing: prevent the two paths from competing for bandwidth with each other, while allowing elastic borrowing when one is idle. Third, overlapped execution: overlap data movement with computation so that waiting time is covered by compute time rather than added serially.

    4. Key Engineering Practices

    1. Cache tiering and placement. Keep hot data closer to the compute units and push cold data down to external storage, adjusting placement dynamically by access heat to reduce long-tail reads.
    2. Prefetching and batched loading. Prefetch predictable historical context and merge random small reads into sequential large reads to improve bandwidth efficiency.
    3. Consistency guarantees. With parallel writes and reads across multiple paths, version and invalidation rules must be explicit so that stale cache is never read.
    4. Observability. Monitoring, alerting, and logging service metrics for load latency, bandwidth usage, hit rate, and queue length are what let you tell whether the bottleneck is in storage, network, or scheduling.
    5. Elastic degradation. When bandwidth is tight, allow some requests to fall back to recomputation or to a narrower cache reuse scope, prioritizing the overall latency target.

    5. Evaluation and Common Pitfalls

    Evaluation should cover three categories of metrics: throughput (requests and tokens completed per unit time), latency (time to first token and per-token latency), and cost (resource consumption per token). Load testing with real agentic chains is recommended rather than single-turn question answering, because only multi-turn tool calls amplify cache read pressure.

    There are three common pitfalls. The first is optimizing bandwidth while ignoring scheduling, which makes the two paths interfere with each other. The second is treating all cache as reusable and overlooking invalidation and consistency. The third is having no degradation strategy, so the system collapses at peak. The sensible approach is to validate path separation and overlap in a test environment first, then ramp traffic gradually.

    6. Deployment Suggestions on Baidu AI Cloud

    To implement a similar optimization in the cloud, you can combine general product categories: object storage for cold cache, a container platform for deploying the inference and scheduling components, a message queue to decouple requests from write-back, and logging plus monitoring and alerting to close the observability loop. Baidu AI Cloud provides these general capabilities, which makes it easier for teams to validate the actual gains of dual-path loading in utilization and latency without changing business logic.

    Overall, the value of the dual-path approach lies not in any single technique but in turning “movement” from implicit waiting into a schedulable resource. For resource-constrained teams, this kind of engineering optimization is often more cost-effective than simply scaling up capacity.