TL;DR
CADOC (Cache-Aware Dynamic Object Context) is an online algorithm that slashes the input costs of long-horizon LLM agents by approximately 40% without sacrificing task performance. It achieves this by replacing bulky history objects with compact retrieval "Cards" and using an economic model to schedule these edits so they don't constantly break the prefix cache.
What Problem Does This Paper Address?
For AI agents working on long-horizon tasks—like coding a whole feature or managing complex server logs—the conversation history (context) is a massive bottleneck. Every time the agent takes a step, it typically resends the entire history to the LLM. This is expensive, slow, and eventually hits context window limits.
Modern LLM providers use "prefix caching" to save money: if the beginning of your prompt matches a previous one, you only pay a fraction of the cost for those tokens. However, this creates a catch-22. If you try to compress old parts of the history to save tokens, you change the prefix, which breaks the cache for everything that follows. The authors demonstrate that immediate compression can actually increase total cost by 3.67%, even while removing over 50% of the tokens, because the savings from fewer tokens are wiped out by the cost of cache misses.
Methods
CADOC introduces a two-part solution for context management:
- Reversible Object Offloading: Instead of lossy summarization, CADOC identifies structured objects (like code blocks, tool outputs, or logs) and replaces them with a tiny "Card"—essentially a retrieval receipt. The original data is stored in a "Working Memory" and can be retrieved exactly on-demand if the agent needs it later.
- Cache-Aware Batch Scheduling: This is the core innovation. Instead of replacing objects as soon as they appear, CADOC waits and batches them. It uses a scheduling rule derived from the Economic Order Quantity (EOQ) model—a classic concept from supply chain management. It balances the "waiting cost" (paying for raw tokens in every request while you wait) against the "reconstruction cost" (the one-time fee to re-cache the prefix after you finally insert the Cards).
Crucially, this scheduler is "online" and "LLM-free." It doesn't need to predict future workloads or use expensive LLM calls to decide when to compress; it makes decisions based solely on currently observable token counts and cache pricing.
Datasets
The researchers evaluated CADOC using several rigorous benchmarks designed for long-horizon execution:
- Terminal-Bench 2.1: Real-world command-line tasks requiring multi-step reasoning.
- LongMemEval-V2: A benchmark specifically testing long-term memory retrieval capabilities.
- SWE-bench: A challenging benchmark for software engineering tasks, such as resolving actual GitHub issues in large codebases.
- Hermes Compression Evaluation (HCE): A set of frozen agent histories used to test different scheduling policies in a controlled "replay" environment.
Key Insights and Ideas
- The Cache-Compression Paradox: Shortening prompts isn't enough; you must consider the timing of edits. Aggressive compression can be more expensive than no compression if it constantly disrupts prefix reuse.
- Batching as Amortization: By waiting to commit a batch of Cards, the agent only "breaks the cache" once for multiple objects, sharing the reconstruction overhead across them.
- The "Hot Tail" Strategy: CADOC keeps a small window of recent history (the "hot tail") raw and uncompressed. This ensures the agent has immediate access to the most relevant recent context without any retrieval overhead.
- Optimal Batching is Observable: You don't need a crystal ball. The optimal time to commit a batch can be determined by balancing observable costs: the cumulative cost of carrying raw tokens vs. the cost of a cache miss.
Key Results
- Substantial Cost Reduction: Across all benchmarks, CADOC consistently achieved the lowest aggregate input costs. It reduced costs by 34% to 47% compared to a full-context baseline.
- Performance Parity: Despite heavy compression, task performance remained nearly identical to using the full, uncompressed context. For example, on SWE-bench, CADOC solved 29/50 tasks compared to 31/50 for the full-context version.
- Robust Adaptation: Unlike fixed-interval methods, CADOC automatically adjusts. As the "hot tail" size increases, it naturally favors larger batches to amortize the higher reconstruction costs, outperforming fixed-batch baselines at every setting.
Limitations and Future Work
- Structured vs. Unstructured Data: CADOC is optimized for structured objects (logs, code, tables). It does not currently address how to compress raw dialogue history without losing information.
- Cache Policy Assumptions: The economic model assumes standard prefix-caching behavior. If a provider uses a radically different caching architecture, the EOQ parameters might need adjustment.
- Future Directions: The authors suggest that combining CADOC's cache-aware scheduling with lossy summarization for dialogue could lead to even more efficient "infinite context" agents.
Summary updated