Cache Engineering for Agents
作者: Tianyu Fu, Ruoxi Wang, Zihan Min, Zhongqi Ren, Zhihao Li, Tengxuan Liu, Shengxu Mu, Hanling Zhang, Yu Wang
分类: cs.CL
发布日期: 2026-10-20
🔗 代码/项目: GITHUB
💡 一句话要点
提出缓存工程方案以优化大语言模型代理的任务处理
🎯 匹配领域: 支柱九:具身大模型 (Embodied Foundation Models)
关键词: 缓存管理 大语言模型 任务处理 性能优化 智能代理
📋 核心要点
- 现有方法在处理长轨迹时,缓存的管理和上下文的有效利用存在显著挑战,导致性能下降。
- 本文提出的缓存工程方案允许代理直接控制KV缓存,避免了轨迹修改和重新填充的需求。
- 实验表明,新的缓存策略显著提高了性能,减少了成本,展示了更高的输出吞吐量和请求延迟的加速。
📝 摘要(中文)
大型语言模型(LLM)代理能够处理日益复杂的任务,但随着观察和行动轨迹的增长,关键值(KV)缓存的输入输出和存储成本成为主要瓶颈。现有方法通过上下文工程来减少缓存大小,但修改轨迹前缀会导致后续缓存状态失效,增加了重新填充的成本。本文提出了一种新的缓存工程方案,使代理能够在不修改轨迹或重新填充上下文的情况下,直接控制其活动KV缓存。具体而言,代理可以主动使用丢弃操作排除未来关注的缓存,并通过重新定位调整保留键的位置编码。实验结果表明,所提出的工具响应滚动丢弃缓存策略在基准测试中平均提升了1.7分,并将平均成本降低了27.7%。
🔬 方法详解
问题定义:本文解决的是在处理长轨迹时,如何有效管理KV缓存的问题。现有方法通过修改轨迹前缀来减少缓存大小,但这会导致后续缓存状态失效,增加了重新填充的成本,影响任务准确性。
核心思路:论文提出的缓存工程方案使代理能够主动控制其KV缓存,采用丢弃和重新定位操作来优化缓存使用,而不需要修改轨迹或重新填充上下文。
技术框架:整体架构包括一个无状态的AKV服务引擎,兼容现有服务API,内部管理状态缓存的重用、驱逐和恢复。代理通过定义的缓存操作来优化其缓存策略。
关键创新:最重要的创新在于引入了缓存操作的概念,允许代理在不修改轨迹的情况下,灵活调整缓存的使用方式,从而提高了缓存的重用效率。
关键设计:设计中包括了丢弃操作和重新定位操作的具体实现,确保代理能够根据任务需求动态调整缓存,同时在实验中通过递归自我改进进一步降低了成本。
🖼️ 关键图片
📊 实验亮点
实验结果显示,工具响应滚动丢弃缓存策略在基准测试中平均提升了1.7分,平均成本降低了27.7%。使用AKV引擎时,输出吞吐量提高了1.2倍,P95请求延迟加速了1.5倍,展示了显著的性能提升。
🎯 应用场景
该研究的潜在应用领域包括智能助手、自动化客服和复杂任务调度等场景。通过优化缓存管理,能够显著提升大语言模型在实际应用中的响应速度和处理能力,具有重要的实际价值和广泛的应用前景。
📄 摘要(原文)
Large Language Model (LLM) agents can handle increasingly complex tasks, navigating long trajectories of observations and actions. As these trajectories grow, key-value (KV) cache I/O and storage become the dominant cost. Trajectories can also exceed the LLM's maximum context length, requiring control over active cache growth. Prior work uses context engineering to reduce cache size by trimming or summarizing history. However, modifying the trajectory prefix invalidates subsequent cached states and triggers costly re-prefilling of retained context. Task accuracy can also suffer when too little context is retained to limit re-prefill costs. We propose cache engineering as a new scheme. It allows agents to directly control their active KV cache without modifying the trajectory or re-prefilling retained context. Specifically, agents can proactively use drop to exclude selected cache from future attention and repos to adjust retained keys' position encodings. We formalize these cache operations and identify history dependence as a serving challenge: identical token sequences can yield different cache states under different cache operation sequences, making prefix matching insufficient for correct cache reuse. Thus, we co-design the AKV serving engine. It provides a stateless interface compatible with existing serving APIs, while internally managing stateful cache reuse, eviction, and restoration. Experiments show that a tool-response rolling-drop cache policy improves average benchmark scores by 1.7 points and reduces average cost by 27.7%, compared with conventional threshold-triggered summarization. With AKV, it achieves up to 1.2x the output throughput and a 1.5x speedup in P95 request latency. Recursive self-improvement of cache policies further reduces cost by 7.1% over expert design. Our code is at https://github.com/thu-nics/AKV.