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 서빙 엔진을 제안한다.
핵심 기여도
- 캐시 엔지니어링 기법을 제안하여 KV 캐시를 직접 제어할 수 있도록 함.
- `drop`과 `repos`라는 새로운 캐시 연산을 도입하여, 히스토리 수정 없이도 캐시 관리 가능.
- AKV 서빙 엔진을 설계하여 상태 없는 인터페이스를 유지하면서도 상태 기반 캐시 관리를 가능하게 함.
- 기존 임계치 기반 요약 대비 평균 점수 1.7점 향상, 비용 27.7% 절감.
핵심 아이디어
기존의 콘텍스트 엔지니어링은 히스토리 텍스트를 자르거나 요약하여 캐시 크기를 줄이는 방식이었으나, 이는 캐시 상태를 무효화하고 재전달(re-prefill)을 유발해 성능 저하를 초래했다. 본 연구는 텍스트 히스토리를 수정하지 않고도 KV 캐시를 직접 제어할 수 있는 **캐시 엔지니어링** 기법을 제안한다. 이는 `drop` 연산을 통해 선택된 캐시 항목을 미래 어텐션에서 제외하고, `repos` 연산을 통해 유지된 키의 위치 인코딩을 조정함으로써, 캐시 상태를 유연하게 관리한다. 이는 기존의 토큰 시퀀스와는 별도로 **캐시 연산 히스토리**가 캐시 상태에 영향을 미친다는 점에서 기존 캐시 시스템과 구별된다.
기술적 접근법
- **캐시 연산**: `append`, `drop`, `repos` 세 가지 연산을 도입.
- `drop`: 선택된 KV 항목을 미래 어텐션에서 제외.
- `repos`: 유지된 키의 위치 인코딩을 조정.
- **AKV 서빙 엔진**:
- 상태 없는(stateless) 인터페이스 제공.
- 내부적으로 **확장된 라디스 트리**(extended radix tree)를 사용해 캐시 재사용, 폐기, 복원을 관리.
- **세그먼트-배치 어텐션**(segment-batch attention)을 통해 누락된 캐시 상태를 한 번의 prefill 과정으로 복원.
- **캐시 정책**: 도구 응답 기반 **롤링 드롭**(rolling-drop) 정책을 제안.
- 평균 점수 1.7점 향상, 비용 27.7% 절감.
- AKV 서빙 시, 출력 처리량 1.2×, P95 요청 지연 1.5× 개선.
주요 결과
- **도구 응답 기반 롤링 드롭 정책**은 기존 임계치 기반 요약 대비 평균 점수 1.7점 향상, 평균 비용 27.7% 절감.
- **AKV 서빙 엔진**을 사용할 경우, 출력 처리량 1.2×, P95 요청 지연 1.5× 개선.
- **재귀적 자기 개선**(RSI) 정책을 적용하면, 전문가 설계 대비 추가 비용 절감 7.1%.
의의 및 한계
캐시 엔지니어링은 기존 캐시 관리 방식의 한계를 극복하고, 에이전트가 직접 캐시를 제어할 수 있는 새로운 패러다임을 제시한다. AKV 서빙 엔진은 기존 API와 호환되면서도 복잡한 캐시 관리를 내부적으로 처리함으로써, 실용성과 효율성을 동시에 담보한다. 그러나 캐시 정책의 최적화와 훈련 방법, 그리고 선형 어텐션 모델과의 호환성 확보는 향후 연구 주제로 남아 있다.
실용적 활용
LLM 기반 에이전트가 긴 작업 히스토리를 처리하는 산업 및 연구 환경에서 캐시 엔지니어링과 AKV 서빙 엔진은 비용 절감과 성능 향상을 동시에 달성할 수 있다. 특히, 대규모 캐시 관리가 필요한 대화형 시스템, 자동화된 작업 플랫폼, 복잡한 추론 작업 등에 유용하게 활용될 수 있다.