Organizations: Beijing University of Posts and Telecommunications, Beijing, China · Tsinghua University, Beijing, China · University of Electronic Science and Technology of China, Chengdu, China · Peking University, Beijing, China
The increasing complexity of AI tasks has shifted the paradigm from monolithic models toward multi-agent large language model (LLM) systems. However, these collaborative architectures introduce a critical bottleneck: redundant prefill computation for shared content generated by previous agents, which significantly increases KV cache memory usage and time-to-first-token (TTFT). While various KV cache methods have been proposed to mitigate prefill redundancy, they either fail to maintain accuracy on agent-generated outputs or exhibit low reuse rates due to rigid constraints. We present RelayCaching, a training-free inference method that directly reuses decoding phase KV caches from previous agents in subsequent prefill phases. Our key insight is that KV caches for identical content are highly consistent across phases, while prefix-induced deviations are sparse and localized within a limited range of layers and token positions. By selectively recomputing KV caches at these positions, RelayCaching preserves model accuracy with minimal overhead, yielding a superior accuracy-efficiency trade-off over existing methods. Experiments on diverse collaborative LLM tasks spanning mathematical reasoning, general knowledge, and code generation demonstrate that RelayCaching achieves over 80% KV cache reuse, reduces TTFT by up to 4.7× compared to the standard pipeline, all with negligible accuracy degradation.
Figures & tables
Figure 1: Overview of KV cache reuse in multi-agent LLM collaboration. Top: A typical workflow where an Architect generates {spec} , a Developer produces {code} based on it, and a Reviewer evaluates the result, so each agent’s output becomes the next agent’s input, causing cascading redundant prefill. Bottom: Comparison of caching strategies. (a) Prefix Caching fails due to prefix mismatch; (b) Pre-computed Caching cannot handle dynamic content; (c) RelayCaching enables decode-to-prefill KV reuse via selective rectification.
Figure 2: Macro-level KV similarity. Average cosine and norm similarity between Decoding KV caches and Full-Prefill KV caches across layers and tokens on 2WikiMQA, compared against Random KV and Independent KV .
Figure 3: Layer-wise structured deviations. (a) Layer-wise similarity between decoding and full-prefill KV caches, highlighting a U-shaped value cosine similarity profile across layers. (b) Relative recovery of value cosine similarity for tokens after the reuse position when decoding KV caches are replaced with their full-prefill counterparts either up to or from a given layer index.
Figure 4: Token-wise structured deviations. (a) Token-wise similarity between decoding and full-prefill KV caches, averaged over layers, revealing a sparse set of high-deviation positions. (b) Spearman rank correlation of token-wise value cosine deviations between adjacent layers, showing that high-deviation positions, once emerged, tend to persist.
Figure 5: Overview of RelayCaching. (1) An offline layer-range profiler analyzes calibration data to identify a critical layer range [Lstart,Lend] from the similarity profile and a detection layer Ldet from the inter-layer correlation profile. (2) During stage- (i−1) decoding, the cache manager stores pre-RoPE KV caches, saves hidden states at Lstart , and accumulates influence scores sinf(j) . (3) At stage- i prefilling, RelayCaching re-applies RoPE to align reused KV caches to new positions, performs token selection at Ldet via combined deviation- and influence-based criteria, and finally applies sparse rectification on selected tokens within [Lstart,Lend] .
Figure 6: Computational reuse efficiency across diverse benchmarks. We compare the Reuse Rate of RelayCaching against baselines on (a) GSM8K, (b) MMLU, and (c) HumanEval as the number of agents increases.
Dataset
Method
2 Agents
3 Agents
4 Agents
Llama-3.1-8B-Instruct (Accuracy %)
GSM8K
Full Prefill
85.97
84.69
84.69
Zero Reuse
40.33
40.03
53.68
CacheBlend
76.72
77.56
74.73
EPIC
58.73
66.46
58.42
KVComm
84.23
82.34
84.91
Table 1: RelayCaching consistently maintains performance comparable to the Full-prefill . Columns indicate the number of agents in the workflow. Bold indicates the best performance; underline marks the second best.
Figure 7: Ablation on key RelayCaching hyperparameters. We analyze the trade-off between Accuracy (left axis) and Reuse Rate (right axis) by varying: (a) the influence score factor τdown , (b) the deviation score factor τdiff , and (c) the suffix length Lsuf . Red markers denote the default configuration used in the main experiments.
Figure 8: Scalability of TTFT with context growth. We measure the average TTFT of downstream agents as the cumulative output length scales from 512 to 12,288 tokens.
Method
Reuse (%)
Acc (%)
Full Prefill
0.00
85.97
+ Layer Range Profiler
46.88
85.90
+ Idev
90.37
79.68
+ Iinf-score
85.84
81.65
+ Iinf-suffix (Ours)
85.35
84.84
Table 3: Ablation study on GSM8K (Llama-3.1-8B-Instruct).
Appendix figures & tables4 assets
Supplementary material from the paper’s appendix.
Appendix
Figure 9: Universality of layer-wise structured deviations. Left Column: Layer-wise cosine similarity and norm similarity profiles. The distinct U-shaped drop in value cosine similarity (red lines) is consistent across diverse models. Right Column: Relative recovery curves. In all cases, recomputing the middle layers (where the similarity drops) yields the most efficient recovery of downstream token fidelity.
Figure 10: Universality of token-wise structured deviations. Left Column: Token-wise similarity profiles averaged over middle layers. The deviations are consistently sparse, with most tokens retaining high fidelity. Right Column: Spearman rank correlation of value cosine deviation between adjacent layers. The high correlation confirms that deviation patterns are persistent and predictable across depths.
Symbol
Description
Default
τlow
Lower similarity threshold
0.99
T
Right-tail layers
5
λ
Stable multiplier
2.0
Nmin
Min rise samples
3
C
Consecutive stables
2
Appendix
Table 4: Hyperparameters for Critical Layer Selection. These values are used to identify the deviation-prone middle layers based on the U-shaped similarity profile.
Model
Lstart
Ldet
Lend
Llama-3.1-8B-Instruct
1
3
18
Qwen2.5-Coder-7B-Instruct
3
4
22
Qwen3-0.6B
2
3
19
Appendix
Table 5: Model-specific layer configurations derived from offline profiling.
LLM inference acceleration develops algorithms and systems that reduce language-model latency, memory use, and serving cost while preserving output quality.