智能体程序调用API因中间等待导致缓存失效重复收费?这篇论文给出简单解法:每隔4分钟发个ping请求保持缓存,能省12倍成本,很实用。
前沿大模型提供商(如Anthropic、OpenAI、Google、DeepSeek)缓存已处理的提示前缀,后续相同前缀请求仅需支付约10%输入价格并跳过大部分预填充延迟。然而智能体工作流因工具调用或等待常间隔数分钟,导致缓存被清除而需全额重新预填充。本文提出客户端保活机制,在空闲期间定时重放前缀以保持缓存热度,在Anthropic的5分钟TTL下最优为4分钟间隔,可将后续请求成本降低最多12.5倍。盈亏平衡分析显示,对于Anthropic,若空闲超过约46分钟则保活不再优于重新预填充。
Keeping the Cache Warm Pays: Keepalive Economics for Agentic Workloads
Frontier LLM providers cache a prompt's processed prefix so that a follow-up request sharing it pays ~10% of the input price and skips most of the prefill latency. Agentic workloads systematically destroy this benefit: the agent sends a request, runs a tool or waits for approval for minutes, and by the time the follow-up is sent the cached prefix has been evicted, so the agent pays the full prefill again. A client-side keepalive, replaying the prefix on a timer during the pause, prevents this, and it is individually rational: across Anthropic, OpenAI, Google, and DeepSeek we show that a keepalive holds the prefix warm through gaps where idle baselines are evicted, cutting the post-pause request cost by up to 12.5x. The strategic question is the ping frequency, and it has a clean answer: keepalive cost falls monotonically in the interval, so the economical choice is the largest interval safely under the provider's TTL, about 4 minutes at Anthropic's 5-minute TTL rather than the 30-second convention, and the strategy breaks even against a re-prefill at idle ~tau(w/r - 1) (~46 min for Anthropic, ~36 min for OpenAI and DeepSeek). Because the benefit is real and bounded only by each user's own bill, rational adoption is universal adoption; and since cache residency is priced per read rather than per token-hour, a keepalive-saturated tier gives LRU eviction nothing to rank. We argue this externality will push providers to meter cache residency directly, and one already does. We derive the operator's policy until then.