arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2610.28577cs.CL
收藏

智能体的缓存工程

Cache Engineering for Agents

Tsinghua University(清华大学);The Chinese University of Hong Kong(香港中文大学)

Tianyu Fu, Ruoxi Wang, Zihan Min, Zhongqi Ren, Zhihao Li, Tengxuan Liu, Shengxu Mu, Hanling Zhang, Yu Wang

AI总结:

针对LLM智能体的KV缓存成本高、轨迹超上下文长度的问题,提出缓存工程方案,设计AKV服务引擎,实验显示该方案可提升基准分数、降低成本并优化吞吐量与延迟。

摘要:

大型语言模型(LLM)智能体能够处理日益复杂的任务,在由观测和动作构成的长轨迹中导航。随着这些轨迹变长,键值(KV)缓存的I/O和存储成为主要成本。轨迹还可能超过LLM的最大上下文长度,需要对活跃缓存的增长进行控制。现有研究采用上下文工程,通过修剪或总结历史来减小缓存大小,但修改轨迹前缀会使后续缓存状态失效,触发保留上下文的高成本重新预填充,且当保留的上下文过少以限制重新预填充成本时,任务准确率可能下降。我们提出缓存工程作为新方案,它允许智能体直接控制其活跃KV缓存,无需修改轨迹或重新预填充保留的上下文。具体而言,智能体可主动使用drop(丢弃)操作排除选定缓存供未来注意力机制使用,使用repos(重定位)操作调整保留键的位置编码。我们将这些缓存操作形式化,并确定历史依赖性是服务阶段的挑战:相同的token序列在不同缓存操作序列下会产生不同的缓存状态,使得前缀匹配不足以实现正确的缓存复用。因此,我们协同设计了AKV服务引擎,它提供与现有服务API兼容的无状态接口,同时在内部管理有状态的缓存复用、驱逐和恢复。实验表明,与传统阈值触发的总结方法相比,工具-响应滚动丢弃缓存策略将平均基准分数提高1.7个百分点,平均成本降低27.7%;结合AKV后,其输出吞吐量最高可达1.2倍,P95请求延迟加速1.5倍;缓存策略的递归自改进进一步将成本降低7.1%。我们的代码位于此https URL。

英文摘要:

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.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑