众力资讯网

清华新作:Agent不改上下文改KV缓存,成本直降27.7%




  1. Large Language Model (LLM) agents can handle increasingly complex tasks, navigating long trajectories of observations and actions. 大语言模型智能体能处理越来越复杂的任务,在由观察和动作组成的长轨迹中推进。
  2. As these trajectories grow, key-value (KV) cache I/O and storage become the dominant cost. 随着轨迹变长,KV 缓存的读写和存储成为主要开销。
  3. Trajectories can also exceed the LLM's maximum context length, requiring control over active cache growth. 轨迹还可能超过模型的最大上下文长度,因此需要控制活跃缓存的增长。
  4. Prior work uses context engineering to reduce cache size by trimming or summarizing history. 已有工作用"上下文工程"来缩小缓存,也就是裁剪或总结历史。
  5. However, modifying the trajectory prefix invalidates subsequent cached states and triggers costly re-prefilling of retained context. 但是修改轨迹前缀会让后续的缓存全部失效,保留下来的上下文要重新预填充,代价很高。


  1. Task accuracy can also suffer when too little context is retained to limit re-prefill costs. 如果为了压低重新预填充的成本而只保留很少的上下文,任务准确率也会下降。
  2. We propose cache engineering as a new scheme. 我们提出一种新方案:"缓存工程"。
  3. It allows agents to directly control their active KV cache without modifying the trajectory or re-prefilling retained context. 它让智能体直接控制自己的活跃 KV 缓存,既不用修改轨迹,也不用对保留的上下文重新预填充。
  4. Specifically, agents can proactively use drop to exclude selected cache from future attention and repos to adjust retained keys' position encodings. 具体来说,智能体可以主动用 drop 把选中的缓存排除在后续注意力之外,并用 repos 调整保留下来的 key 的位置编码。
  5. 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. 我们形式化定义了这些缓存操作,并指出"历史依赖性"是推理服务要解决的难题:同一个 token 序列,在不同的操作序列下会得到不同的缓存状态,所以光靠前缀匹配不能保证缓存被正确复用。
  6. Thus, we co-design the AKV serving engine. 为此,我们协同设计了 AKV 推理服务引擎。It provides a stateless interface compatible with existing serving APIs, while internally managing stateful cache reuse, eviction, and restoration. 它对外是兼容现有 API 的无状态接口,内部则有状态地管理缓存的复用、淘汰和恢复。
  7. 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. 实验表明,和常规的"到阈值就做总结"相比,"工具响应滚动丢弃"策略让基准平均分提高 1.7 分,平均成本降低 27.7%。
  8. With AKV, it achieves up to 1.2× the output throughput and a 1.5× speedup in P95 request latency. 在 AKV 上运行时,输出吞吐量最高达到基线的 1.2 倍,P95 请求延迟加速 1.5 倍。
  9. Recursive self-improvement of cache policies further reduces cost by 7.1% over expert design. 对缓存策略做递归自我改进,成本比人工专家设计的策略再降 7.1%。
  10. 论文承认:策略还有很大的探索空间;还没有专门为这种方式训练 agent;暂不支持线性注意力模型。