Cache Engineering for Agents

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

arXiv:2610.28577 · 2026-10-22 공개 · arXiv · PDF

llm-agents benchmarking kv-cache latency-optimization context-length trajectory-optimization cache-eviction cache-reuse

Abstract

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.

한국어 요약

한 줄 요약

LLM 에이전트의 KV 캐시 관리를 위한 새로운 기법인 캐시 엔지니어링과 이를 지원하는 AKV 서빙 엔진을 제안한다.

핵심 기여도

핵심 아이디어

기존의 콘텍스트 엔지니어링은 히스토리 텍스트를 자르거나 요약하여 캐시 크기를 줄이는 방식이었으나, 이는 캐시 상태를 무효화하고 재전달(re-prefill)을 유발해 성능 저하를 초래했다. 본 연구는 텍스트 히스토리를 수정하지 않고도 KV 캐시를 직접 제어할 수 있는 **캐시 엔지니어링** 기법을 제안한다. 이는 `drop` 연산을 통해 선택된 캐시 항목을 미래 어텐션에서 제외하고, `repos` 연산을 통해 유지된 키의 위치 인코딩을 조정함으로써, 캐시 상태를 유연하게 관리한다. 이는 기존의 토큰 시퀀스와는 별도로 **캐시 연산 히스토리**가 캐시 상태에 영향을 미친다는 점에서 기존 캐시 시스템과 구별된다.

기술적 접근법

주요 결과

의의 및 한계

캐시 엔지니어링은 기존 캐시 관리 방식의 한계를 극복하고, 에이전트가 직접 캐시를 제어할 수 있는 새로운 패러다임을 제시한다. AKV 서빙 엔진은 기존 API와 호환되면서도 복잡한 캐시 관리를 내부적으로 처리함으로써, 실용성과 효율성을 동시에 담보한다. 그러나 캐시 정책의 최적화와 훈련 방법, 그리고 선형 어텐션 모델과의 호환성 확보는 향후 연구 주제로 남아 있다.

실용적 활용

LLM 기반 에이전트가 긴 작업 히스토리를 처리하는 산업 및 연구 환경에서 캐시 엔지니어링과 AKV 서빙 엔진은 비용 절감과 성능 향상을 동시에 달성할 수 있다. 특히, 대규모 캐시 관리가 필요한 대화형 시스템, 자동화된 작업 플랫폼, 복잡한 추론 작업 등에 유용하게 활용될 수 있다.