每天早上一封邮件,把昨天的 AI 梳理好订阅邮件

METAL LAB

ReCache: Efficient KV Cache Reuse and Compression for Tool-Augmented LLM Agents

arXiv:2608.196622026-08-21

让AI智能体不用每次都重新读一遍工具说明书,响应速度提升3倍以上

会调用外部工具的AI智能体,每次请求里工具和技能的说明文字(资源)出现的组合和顺序都不一样,导致标准的前缀缓存机制无法复用之前算好的结果,只能重新计算。ReCache让每个工具说明可以独立缓存复用,并只保留对判断该调用哪个工具真正有用的部分,大幅精简存储。结果是首字响应速度最多提升3.655倍,缓存内存占用减少92.43%,而准确率几乎没有下降。

他们做了什么

  1. 问题:智能体调用的工具、技能说明(资源)在不同请求中以不同组合和顺序出现,而传统前缀缓存要求开头文字完全一致才能复用计算结果,因此常常失效
  2. 方案一:资源级注意力(resource-wise attention),让不同工具说明之间互不干扰,并把每段说明内部的位置编号重新从零开始计数,这样不管组合顺序怎么变,生成的缓存块都保持一致、可复用
  3. 方案二:结构剪枝,先测量模型的哪些层、哪些注意力头组真正对正确调用工具有贡献,只让这些被选中的通路能看到工具信息,其余通路一律屏蔽
  4. 方案三:语义剪枝,只保留工具名称、参数名称、参数描述以及末尾的摘要token等调用时真正必需的内容,其余文字全部删除
  5. 实验结果:在由七个公开工具/技能使用数据集构建的基准上,仅用资源级注意力,准确率与完整密集注意力几乎一致(82.3% 对 82.4% 的调用F1),首字响应速度提升3.655倍;完整的ReCache框架将缓存显存占用减少92.43%,注意力计算速度提升1.423倍
Figure 1: Cross-resource attention on Qwen3-4B.
Figure 1: Cross-resource attention on Qwen3-4B.
Table 1: Selected structural budgets. CC and ρ are percentages; ΔInv-F1 is measured relative to Ωfull after full-data training.
ModelKL/LKG/GCCLCCGρΔInv-F1 (%)
Ql20/363/897.747.379.2−0.2
Qs20/287/899.899.337.5−0.7
(b) Attention from subsequent conversation tokens onto resources, normalized and aligned by relative position.
(b) Attention from subsequent conversation tokens onto resources, normalized and aligned by relative position.
Table 2: Resource-wise attention ablation.
MethodInv-F1ID-F1Halluc.TTFT (ms)
Dense82.496.00.026.319
Block82.295.80.1
Ωfull82.396.00.27.200
Figure 2: ReCache constructs reusable KV blocks for each Ri and progressively reduces their subsequent cache retention and access. (a) Resource-wise attention removes inter-resource attention and resets positions from zero within each Ri. (b) Structural pruning exposes resource KV states (using Mresource) only through selected layer (Li)–KV-head-group (Gi) routes Ω⋆ (highlighted in blue). The remaining routes use Mcontext. (c) Semantic pruning retains resource names, argument (arg) names and descriptions (desc.), and the final suffix token. The final mask combines these decisions, ensuring that Y attends exclusively to retained semantic fields within assigned routes during decoding.
Figure 2: ReCache constructs reusable KV blocks for each Ri and progressively reduces their subsequent cache retention and access. (a) Resource-wise attention removes inter-resource attention and resets positions from zero within each Ri. (b) Structural pruning exposes resource KV states (using Mresource) only through selected layer (Li)–KV-head-group (Gi) routes Ω⋆ (highlighted in blue). The remaining routes use Mcontext. (c) Semantic pruning retains resource names, argument (arg) names and descriptions (desc.), and the final suffix token. The final mask combines these decisions, ensuring that Y attends exclusively to retained semantic fields within assigned routes during decoding.
Table 3: Results on 𝒯IND. Efficiency is reported relative to Dense. SMP denotes Semantic Pruning.
MethodAttn. ×Mem. ↓Inv-F1ID-F1Halluc.
Dense82.496.00.0
Ωfull1.001×0.47%82.396.00.2
Structural pruning
Ω20,G1.016×44.71%82.595.70.3
Ωfull + SPEED1.013×44.71%79.392.92.8
Ω20,31.314×79.27%82.195.60.2
Ωfull + SA20,31.302×79.27%79.193.71.0
Semantic pruning
Ωfull + Gist1.029×99.22%39.246.951.4
Ωfull + Beacon1.020×75.42%78.692.51.4
Ωfull + SMP1.021×63.57%81.695.20.2
ReCache1.423×92.43%80.394.90.2
Figure 3: Structural contribution coverage in Ql and Qs. Cumulative leave-one-in contributions of layers (top) and KV head groups (bottom); vertical lines mark the selected budgets.
Figure 3: Structural contribution coverage in Ql and Qs. Cumulative leave-one-in contributions of layers (top) and KV head groups (bottom); vertical lines mark the selected budgets.
Table 4: 𝒯OOD Results. SMP denotes Semantic Pruning.
MethodInv-F1ID-F1Halluc.
Dense66.395.60.0
Ωfull64.794.40.4
Structural pruning
Ω20,G64.394.30.5
Ωfull + SPEED54.381.613.4
Ω20,363.293.30.5
Ωfull + SA20,358.288.45.1
Semantic pruning
Ωfull + Gist9.717.879.9
Ωfull + Beacon58.589.74.2
Ωfull + SMP62.894.10.3
ReCache60.892.80.6
Figure 4: Efficiency on varying resource lengths Dℛ. Requests are grouped by average resource length into Small (0≤Dℛ<1​K), Medium (1​K≤Dℛ<5​K), Large (5​K≤Dℛ<10​K), and XL (Dℛ≥10​K). SMP denotes semantic pruning.
Figure 4: Efficiency on varying resource lengths Dℛ. Requests are grouped by average resource length into Small (0≤Dℛ<1​K), Medium (1​K≤Dℛ<5​K), Large (5​K≤Dℛ<10​K), and XL (Dℛ≥10​K). SMP denotes semantic pruning.
Table 5: Dataset composition and split statistics. Source rows report eligible examples before final selection; the Toucan aggregate is not double-counted in the summary row. Distinct names counts source-level unique declared tools or skills, Subset dup. counts records beyond the first occurrence of an identical candidate configuration, and Recurring names counts resources appearing in multiple records. The summary row corresponds to 18.8% duplicated candidate records and 77.3% recurring resource names. IND cand. and OOD cand. denote eligible in-distribution and out-of-distribution candidates, and dashes mark unavailable statistics.
GroupSourceTrain poolDistinct namesSubset dup.Recurring namesIND cand.OOD cand.
ToolToolACE8,40014,5661787,144200195
APIGEN10,0002,8067342,805500146
Toucan (all generators)13,0714,3556,9014,355600493
- Kimi-K23,3331,1031,7721,103200145
- GPT-OSS-120B4,1841,4122,1621,412200130
- Qwen3-32B5,5541,8402,9671,840200218
ToolRet1,1501,593235431100150
ToolMind20,00014,5041,85314,497500190
WildToolBench256
SkillSkillRouter87
Sources with frequency statistics52,62137,8249,90129,2321,9001,174
Candidate pool52,9641,9001,174
Final dataset49,4241,0001,000
(b) TPOT
(b) TPOT
Table 6: Structural budget ablation for Qs across training data regimes with comparable budgets.
ConfigInv-F1Resource IDHalluc.
ID-PID-RID-F1
Ωfull72.192.090.890.90.4
ΩL,549.674.573.573.44.8
ΩL,653.479.677.978.33.2
ΩL,757.383.481.882.12.9
Ω15,G69.389.288.388.31.1
Ω20,G70.590.689.589.61.1
(c) Attn.
(c) Attn.
Table 7: Structural budget ablation trained on 𝒟.
ConfigInv-F1Resource IDHalluc.
ID-PID-RID-F1
𝑸𝒔
Ωfull80.794.994.394.40.1
Ω20,578.894.193.593.60.5
Ω20,780.094.794.094.10.3
𝑸𝒍
Ωfull82.396.495.896.00.2
Ω20,281.995.394.794.70.3
Ω20,382.196.195.595.60.2
(d) Mem.
(d) Mem.
Table 8: Semantic pruning ablation trained on 𝒟subset. Arg stands for argument, Desc. stands for description. Ω20,3 denotes the routing configuration with KL=20,KG=3.
ConfigInv-F1Resource IDHalluc.
ID-PID-RID-F1
Ω20,376.193.192.892.50.9
Schema representation ablation
Suffix-only Schema14.822.823.022.976.0
+ Resource Name45.289.988.888.91.8
+ Arg Name67.792.191.191.21.3
+ Resource Desc.67.992.291.491.41.1
+ Arg Desc.72.892.891.992.01.0
+ Both Desc.73.493.092.292.21.2
Table 9: Individual contribution weights and cumulative contribution coverage of structural units. Within each panel, units are ranked independently by decreasing wi, and CC at rank k is the cumulative positive contribution weight through rank k. Bold entries fall within the empirical budgets KL=20,KG=3 for Ql and KL=20,KG=7 for Qs.
Layers
𝑸𝒍(Qwen3-4B)𝑸𝒔(Qwen3-1.7B)
rankunit𝒘𝒊 (%)CC (%)rankunit𝒘𝒊 (%)CC (%)
1L3415.5615.61L2220.0920.1
2L3510.5326.12L2512.9033.0
3L239.3735.53L2012.1445.1
4L258.3143.84L2610.9056.0
5L328.0151.85L2710.3966.4
6L306.9558.76L176.8273.2
7L336.8965.67L216.7079.9
8L275.1770.88L194.6584.6
9L214.8775.79L244.0088.6
10L284.6480.310L232.1390.7
11L244.0284.311L181.8992.6
12L223.7488.112L151.7394.3
13L172.3090.413L131.3995.7
14L311.9692.314L101.1396.9
15L181.2993.615L91.0397.9
16L141.2694.916L40.8898.8
17L200.7895.717L160.5699.3
18L360.6996.318L120.1899.5
19L190.6897.019L110.1599.7
20L160.6897.720L80.1499.8
21L100.6098.321L280.1199.9
22L50.3398.622L50.06100.0
23L110.2998.923L20.02100.0
24L90.2799.224L10.00100.0
25L120.2699.525L30.00100.0
26L150.2699.726L60.00100.0
27L130.1399.827L70.00100.0
28L80.0799.928L140.00100.0

为什么重要

调用工具的AI智能体目前每次请求都要重新处理冗长的工具说明,拖慢响应并推高服务成本,ReCache提供了一种在几乎不损失准确率的前提下削减这部分重复计算的实用方法。代码已经公开,开发智能体系统的工程师可以直接使用。

本文术语

  • KV缓存 · 语言模型把之前处理过的token的中间计算结果(键值)存起来,供后续复用而不必重算
  • 前缀缓存 · 一种缓存方式,只有当新输入的开头部分与之前完全相同时才能复用计算结果
  • TTFT(首字延迟) · 模型收到请求后生成第一个输出token所需的时间,直接影响用户感受到的响应速度
  • 结构剪枝/语义剪枝 · 分别在模型的层与注意力头层面、以及文本token层面去掉不重要部分的压缩方法
  • 资源(工具/技能说明) · 描述一个可调用工具或技能的结构化文本,包含名称、参数、说明等信息

论文原文摘要(英文)

Agentic language models repeatedly encode tool and skill schemas that recur across requests in different combinations and orders, preventing standard prefix caching from reusing their key--value (KV) states. We introduce \textbf{ReCache}, a framework for independently caching resource representations while reducing their inference-time computational and memory overhead. Resource-wise attention removes cross-resource interactions and assigns resource-local positions, producing composition-invariant KV blocks. ReCache then restricts resource visibility to contribution-selected layer--KV-head-group routes and retains only invocation-critical fields through structural and semantic pruning. We evaluate ReCache on a benchmark assembled from seven public tool- and skill-use datasets, including resource-disjoint tests. Resource-wise attention matches dense invocation performance (82.3\% versus 82.4\% Inv-F1) while providing a 3.655$\times$ time-to-first-token speedup. The complete framework reduces allocated KV-tensor memory by 92.43\% and accelerates attention by 1.423$\times$. These results show that separating reusable schema encoding from selective resource access substantially reduces agentic inference costs with limited effectiveness loss. The code is available at https://github.com/EIT-NLP/ReCache.

作者 · Yichu Fang, Sitong Wei, Haozhe Hu, Xiaoyu Shen

在 arXiv 阅读

最新论文

全部论文 →

METAL LAB 最新报道

图片来源: Yichu Fang et al., arXiv:2608.19662, arxiv-nonexclusive