TL;DR
Folio is a novel context manager for long-horizon language agents that replaces expensive, lossy model-driven summarization with "programmatic folding." By maintaining a multi-resolution history and providing tools to "reach back" into folded data via stable handles, Folio achieves higher task success rates while being 2.4x cheaper and significantly faster than state-of-the-art baselines.
What Problem Does This Paper Address?
As AI agents tackle increasingly complex, multi-step tasks (like managing a whole software project or analyzing months of sales data), they generate a massive trail of tool outputs and reasoning. Eventually, this history exceeds the LLM's "context window."
The standard solution is compaction: having the model summarize its past actions to save space. However, this approach has three major flaws:
- It's expensive and slow: Every time you compact, you pay for a model to reread and rewrite history.
- It's lossy: Summaries often omit details that might become crucial ten steps later.
- It breaks the cache: Rewriting history forces the provider to re-index the prompt, losing the benefits of prompt caching.
The authors of Folio ask: What if we didn't have to rewrite history at all?
Methods
Folio introduces Context Folding. Instead of summarizing, it maintains history at three linked levels of resolution simultaneously:
- L1 (Turn Notes): Short, model-written notes about the outcome of a turn.
- L2 (Event Manifest): A runtime-generated one-line summary of every tool call (e.g., "t3.12 | export_table | 900 rows").
- L3 (Source Records): The full, raw logs of every interaction.
The "Fold" and "Recover" Cycle
When the context gets too full, Folio's runtime performs a programmatic fold. It doesn't call an LLM; it simply swaps out high-resolution L3 data for lower-resolution L1 or L2 views for older turns. This is deterministic and takes milliseconds.
Crucially, the fold leaves behind stable handles (like t3.12). If the agent realizes it needs the full data from a folded turn, it uses specialized recovery tools:
scan: To read specific pages or search through folded text.ctx: To run code (Python/Shell) over the full raw files without bringing them back into the context window.dossier: A persistent "scratchpad" where the agent saves important findings that survive across multiple folds.
Economic Triggering
Folio uses a "landing-priced" trigger based on the economics of prompt caching. It calculates whether the cost of carrying "excess" context (paying for cached reads) outweighs the one-time cost of "rebuilding" the context at a smaller size.
Datasets
The authors evaluated Folio using LOCA-bench, a benchmark specifically designed for long-horizon tasks where context grows over time. They constructed 5 "chains" of 15 tasks each (75 tasks total) across environments like course scheduling, inventory analysis, and A/B test analysis.
Key Insights and Ideas
- Monotone Demotion: Once a line of history is sent to the model at a certain resolution, Folio never "upgrades" it back to a richer level in the main context. This ensures the prefix of the prompt remains byte-identical, maximizing the hit rate for prompt caching.
- Separating Identity from Resolution: By using stable handles, the identity of a tool result remains constant even if its representation in the window changes from a 1,000-line table to a one-line manifest entry.
- Computation over Retrieval: The
ctxtool is a game-changer. Instead of the agent trying to "remember" or "retrieve" 900 rows to count them, it simply tells the runtime: "Runwc -lon handlet3.12and tell me the result."
Key Results
Folio was tested against heavyweights like Claude Code, Codex, and SoL-Pi, all powered by DeepSeek-V4-Pro.
- Higher Success: Folio solved 66/75 tasks, compared to 54 for the standard summarization baseline and 49–59 for other state-of-the-art agents.
- Massive Speedup: The median fold takes just 0.6 seconds, whereas model-written compaction takes 101 seconds. Overall, Folio tasks finished in roughly half the time of competitors.
- Cost Efficiency: Folio reduced normalized token costs by 2.4x compared to the summarization baseline.
- Robustness: Even when the context window was artificially shrunk from 1M to 128K tokens, Folio still outperformed all 1M-window baselines.
Limitations and Future Work
- Model-Written State: L1 notes and dossier entries are still written by the model. If the model hallucinates a note or forgets to save a finding to the dossier, Folio can't magically fix it.
- Fixed Landing Budget: The current system uses a pre-configured "landing budget" ($L$) for how much context to keep after a fold. The authors suggest that dynamically choosing $L$ per task could be a fruitful area for future research.
- Security of
ctx: While powerful, allowing an agent to run arbitrary shell/Python commands over history files requires a robust isolation and permission model, which was not the focus of this paper.
For those building production-grade agents, Folio suggests that the secret to long-term memory isn't better compression—it's better indexing and the ability to "look back" only when necessary.
Summary updated