Folio: Recoverable Multi-Resolution Context Folding for Long-Horizon Language Agents

Yubo Ruan, Tao Peng, Jiao Zhang, Chuanguo Ma, Lei Xu, Han Zhou, Wenwu Wang, Xiafei Lv, Xingjie Zhou, Guiju Fan, Hao Wang, Fenghui Zhang, Mao Miao, Shuo LiarXiv 2026

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:

  1. It's expensive and slow: Every time you compact, you pay for a model to reread and rewrite history.
  2. It's lossy: Summaries often omit details that might become crucial ten steps later.
  3. 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.
Figure 1: Overview of FOLIO. Record: the runtime turns tool events into a three-level indexed history. Fold: the cost-aware trigger selects views of this history to build the active context. Recover: the handle in the outline (t3.12) is passed to scan for a bounded read or to ctx to compute over the full text, and the result is kept in the dossier.

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 ctx tool is a game-changer. Instead of the agent trying to "remember" or "retrieve" 900 rows to count them, it simply tells the runtime: "Run wc -l on handle t3.12 and tell me the result."
Figure 2: Folding and recovery on one example. (a) Turn t3 exists as a turn note (L1), the manifest row of call t3.12 (L2), and the 900-row table it returned (L3). Within the layout budget L, the fold shows t1 briefly, t2 with its full note, and t3 with the row of t3.12; the open turn t4 keeps a raw head and tail. (b) Through the same handle, scan checks one value and ctx counts every row; the finding and its source go to the dossier, which the next fold carries.

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.
Figure 3: (a) Cumulative successes along the 15-task session, averaged over the five chains; the dotted line solves every task. (b) Distribution of working time per task over all 75 tasks.

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

Abstract

Long-horizon language agents accumulate tool results and replies until the history no longer fits the context window. Current agents shrink this history by having a model summarize it, so each compaction rereads and rewrites the history it replaces, and cache-aware triggers decide when to compact while taking the size of the result as given. We present Folio, a context manager that records, folds, and recovers history through one set of handles. While the agent runs, Folio records three linked levels: a short turn note the model writes as part of its ordinary reply (L1), an event manifest of every call written by the runtime (L2), and the captured source records (L3). Because these views already exist, the runtime folds the context programmatically, selecting coarser views for older turns. The fold prints the handles that index L2 and L3, so recovery tools that read bounded pages, compute over full text in files, and keep findings in a persistent dossier reach the evidence the agent needs with little added input. The fold trigger prices an explicit landing point that includes the retained budget. On 75 LOCA-bench tasks with DeepSeek-V4-Pro behind every system, Folio solves 66 tasks against 54 for the same runtime with model-written compaction and 49-59 for Claude Code, Codex, and SoL-Pi, in about half their working time, at 2.4 times lower cost than that runtime; each fold takes a median of 0.6 seconds.
BibTeX
@misc{ruan2026folio,
  author = {Yubo Ruan and Tao Peng and Jiao Zhang and Chuanguo Ma and Lei Xu and Han Zhou and Wenwu Wang and Xiafei Lv and Xingjie Zhou and Guiju Fan and Hao Wang and Fenghui Zhang and Mao Miao and Shuo Li},
  title = {{Folio: Recoverable Multi-Resolution Context Folding for Long-Horizon Language Agents}},
  year = {2026},
  eprint = {2611.16627},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2611.16627},
}
Figure