Introduction
As artificial intelligence tackles increasingly complex tasks, the paradigm is shifting from monolithic models to Multi-Agent Systems (MAS). In these collaborative architectures, specialized Large Language Model (LLM) agents work together—for instance, an "Architect" agent might generate a software specification that a "Developer" agent subsequently uses to write code.
However, this collaborative hand-off introduces a critical computational bottleneck: the redundant prefill tax. Every time an agent receives text generated by a previous agent, it must process that text from scratch. RelayCaching is a novel, training-free inference method designed to eliminate this inefficiency. By directly reusing the Key-Value (KV) cache generated during one agent's decoding phase as the prefill for the next, RelayCaching achieves up to a $4.7\times$ reduction in Time-to-First-Token (TTFT) with negligible loss in accuracy.
The Bottleneck: Why Standard Caching Fails in MAS
To avoid recomputing token states at every step, LLMs store previous states in a KV cache. In a single-agent scenario, "Prefix Caching" works well because the prompt remains static.
In a Multi-Agent System, however, the same piece of text (e.g., the Architect's specification) appears in different contexts for different agents. Because the system prompt or instructions preceding that shared text change from agent to agent, standard prefix caching fails. The mathematical states of the shared tokens are altered by the new prefix. Consequently, current systems are forced to recompute the KV cache from scratch every time an agent receives an upstream output. In multi-turn pipelines, this redundant prefill cost grows quadratically, leading to massive memory consumption and sluggish response times.
The Solution: RelayCaching
Instead of discarding the upstream agent's KV cache, RelayCaching reuses it via a process called selective rectification. The authors discovered that while a changing prefix does alter the mathematical states of subsequent tokens, these deviations are highly predictable and localized.
RelayCaching relies on two core components to fix only the broken parts of the cache:
1. Layer-Range Profiler and the "U-Shaped" Deviation
The researchers uncovered a fascinating "U-shaped" deviation pattern within the LLM's layers. When a prefix changes, the shallow (early) and deep (late) layers of the model remain surprisingly resilient and consistent. The vast majority of the deviation occurs in the middle layers.
By profiling the model offline, RelayCaching identifies this critical middle-layer range $[L_{start}, L_{end}]$ and a specific "detection layer" ($L_{det}$) where these deviations stabilize. The system can safely "relay" the KV cache for the shallow and deep layers without any recomputation.
2. Token Selector: Sparsity and Persistence
Even within the sensitive middle layers, not all tokens are affected equally by a new prefix. Deviations are sparse (only a few tokens are "corrupted") and persistent (if a token deviates at layer 10, it likely continues to deviate through layer 20).
The Token Selector identifies this sparse set of high-deviation tokens at the detection layer. It utilizes an "influence-based" metric—focusing on the direction of the Value vectors in the attention mechanism (Value Cosine Similarity)—to prioritize tokens that the model attends to most heavily.
The Workflow: RelayCaching takes the upstream agent's KV cache and relays it forward. It only performs a "full recompute" for the specific middle layers, and only for the sparse tokens flagged by the selector. The rest of the cache is reused as-is.
Performance and Results
The researchers rigorously evaluated RelayCaching across diverse benchmarks, including mathematical reasoning (GSM8K), code generation (HumanEval), general knowledge (MMLU), and stress tests (AIME24). The results demonstrate a superior accuracy-efficiency trade-off:
- Massive Speedups: RelayCaching achieved up to a $4.7\times$ speedup in TTFT compared to standard full-prefill pipelines.
- High Efficiency: The method maintains over 80% KV cache reuse across most tasks. In long-context scenarios (up to 12k tokens), it demonstrated sub-linear scaling, effectively neutralizing the quadratic scaling problem of standard systems.
- Negligible Accuracy Drop: The selective rectification process preserves model performance. On GSM8K using Llama-3.1-8B, RelayCaching achieved 84.84% accuracy, nearly identical to the 85.97% achieved by a full, computationally expensive recomputation.
- Minimal Memory Overhead: Compared to recent state-of-the-art baselines like KVCOMM, RelayCaching reduced auxiliary memory overhead from gigabytes to less than 50MB.
Limitations and Future Directions
While RelayCaching offers a massive leap in MAS efficiency, it currently has a few constraints:
- Homogeneous Models: The system requires all agents to use the same model architecture (e.g., all Llama-3.1-8B). It cannot yet translate a KV cache from a Llama model to a Qwen model due to differing internal dimensions and tokenizers.
- Bandwidth Constraints: In distributed settings where agents operate on different GPUs, the hidden states must be transferred over the network. While faster than recomputing, maximizing this benefit requires high-bandwidth interconnects like NVLink.
- Static Profiling: The layer ranges for rectification are currently determined offline. Future iterations could feature online adaptation, dynamically deciding which layers to rectify based on real-time deviation sensing.
Conclusion
As Multi-Agent Systems become the standard for complex AI workflows, eliminating redundant computation is paramount. RelayCaching proves that we do not need to throw away perfectly good KV caches just because the prefix changed. By intelligently identifying and repairing only the sparse, middle-layer deviations, RelayCaching paves the way for faster, highly scalable, and memory-efficient LLM collaboration.
Summary updated