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.
Figures & tables
Figure 1: Overview of 1. 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.
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.
Success
Time (min/task)
System
/75
per chain
mean
median
Flag.
Claude Code
59
11.8 ± 0.8
18.5
13.7
9
Codex
57
11.4 ± 1.7
20.2
15.4
27
SoL-Pi
49
0 9.8 ± 1.3
21.0
17.9
24
Piki-Classic
54
10.8 ± 1.3
16.3
13.7
11
1 (128K)
60
12.0 ± 1.2
16.4
0 7.8
9
Table 1: LOCA-bench, 5 chains × 15 tasks, DeepSeek-V4-Pro for every system. Per chain: mean ± s.d. of successes out of 15. Flag.: runs flagged by the benchmark’s contamination scan.
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.
Figure 4: Successes per LOCA-bench environment (out of 5 seeds). Rows are sorted by the mean of Claude Code, Codex, and SoL-Pi, hardest first.
1
Piki-
Per task
1M
128K
Classic
Input tokens (M)
4.01
2.72
14.12
cached
3.69
2.46
13.29
uncached
0.32
0.27
0.83
Output tokens (M)
0.07
0.10
0.10
Cache hit rate
92.0%
90.2%
94.1%
Table 2: Usage per task (means over 75 tasks). Normalized cost is h+30u+90o in cached-read token equivalents; for Piki-Classic it includes its summary requests.
Variant
n
Succ.
Cost
Folds
Min
A 1
75
66
19.75
85
10.2
B − dossier
75
65
19.73
85
10.7
− L1 notes
75
63
19.43
80
0 9.5
A 1
15
13
18.07
16
0 7.8
B − dossier
15
13
20.89
18
12.5
C − scan , ctx
15
0 8 †
18.65
18
21.7
Table 3: Ablations (1M window, L=50 K). Top: all 75 tasks. Bottom: the first chain, on which C and D were run. Cost: normalized tokens per task (M); Min: minutes per task. Each of B–D removes one more component than the row above. † Two timeouts and one agent error.
Figure 5: Landing-budget sweep on the fifth chain (15 tasks; mean of an ascending and a descending run, one run at L=10 K). Recoveries are scan and ctx calls that reach content removed by the last fold. In the shaded region the raw area hits its 60K cap, so the effective budget is 78–90K (hollow markers).
Figure 6: One 1 session (fifth chain, 1M window, 432 requests). Top: input tokens of each request and the landing point S ; red dots mark the 17 folds. Bottom: carried excess relative to the fold price; a fold occurs when it reaches 1.
1 fold
Classic
1M ( n=85 )
128K ( n=236 )
( n=24 )
Model calls
0
0
24
Latency
613 ms
346 ms
101 s
Context before
242K
121K
908K
Context after
64K
39K
58K
Compression
7.3 ×
7.0 ×
–
Table 4: Folds of the main 1 runs and compactions of Piki-Classic. Latency, context sizes, and ratios are medians. Compression is the folded source history over the rendered outline.
Long-horizon LLM agents act on an append-only interaction history that is re-sent to the model at every step, so the context and its cost grow with steps until the sessions exceed the context window. Existing methods manage the context through context requirement prediction, relying on additional model calls, heuristic rules, or trained policies. However, these predictive approaches introduce runtime overhead, invalidate prefix caches, and permanently discard content with no guarantee of recovery. To overcome these limitations, we introduce ReFold: a training-free rendering layer that preserves the underlying interaction history while compressing only the model's rendered context. It removes two kinds of inter-turn redundancy without an auxiliary predictor: content an earlier turn already displayed, replaced by a stub, and turns the agent itself reports finished, folded into a one-line note. Both operators use chunked rendering, rewriting the cached prefix once every few steps rather than at every step. Every removal is strictly reversible, a wrong removal costs one restore from the history rather than permanent content loss. Because it operates at the rendering layer, ReFold is plug-and-play across standard ReAct-style harnesses. Evaluations across five long-horizon benchmarks and two frontier LLMs demonstrate that ReFold reduces token consumption by up to 2.5x and halves the KV-cache memory per session without degrading task success rates. Under capped context budgets, it avoids up to 92% of forced compactions. Under concurrent serving workloads, it reduces request queuing delays by up to 100%, accelerating inference by up to 1.7x, while cutting inference costs by up to 3.4x.
LLM agents increasingly take on long-running tasks whose history grows far beyond a single model context window. Existing approaches compress earlier interactions or extract selected information into fixed memory representations, committing to what to preserve before future needs are known. We present Scroll, a context manager that treats each agent session as an executable Session Environment. The environment is backed by an append-only Event Log and a sandboxed, persistent Python kernel. The kernel maintains a typed namespace across model calls, allowing tool outputs, retrieved history, and derived state to be bound to variables rather than serialized into the prompt at each call. Model-written code searches, materializes, and transforms session state through exec; only explicitly printed projections enter the model's working view for the next call. Context management thus becomes a programming task that inherits the improving coding abilities of LLMs, while the Event Log preserves lossless historical ground truth. As the working view approaches its budget, stale spans are evicted but remain recoverable: an eviction index keeps compact landmarks tied to exact Event Log addresses, so that the agent navigates directly to evicted regions instead of searching the full log. With Qwen3.8-Max as the backbone, Scroll achieves 94.8% on LongMemEval_S; 73.1% on BEAM_10M, surpassing the best published memory system by 5.1 points; and 86.7% on LOCA_256K, exceeding the best published long-horizon agent by 37.4 points.
Long-horizon LLM agents accumulate reasoning traces, actions, and tool observations that can eventually exceed a model's fixed context window. Existing compaction methods address this limitation by discarding, summarizing, or retrieving earlier information, but they may remove task-critical details or fail to recover them reliably. We propose ARC (Addressable Recall Compaction), a context-management framework that separates archival storage from active-context presentation. ARC stores tool observations in an append-only, ID-addressable log and replaces older observations with compact citations when compaction is required. The agent can subsequently use these identifiers to request stored content without re-executing the corresponding tools or depending solely on similarity-based retrieval. We evaluate ARC using Qwen3-8B with a 16k context window and Qwen3-32B with a 32k context window. On the Needle-in-a-Haystack evaluation, ARC achieves an average exact-answer accuracy of 99.40%, compared with 88.12% for the best-performing baseline in our evaluation. ARC also reduces estimated serving time and HBM traffic under our hardware-cost model. On the LongBench-v2 Hard subset, ARC obtains an average accuracy of 29.97%, compared with 28.25% for the best-performing baseline. These results indicate that explicit, address-based recall can improve information retention and serving efficiency relative to the evaluated context-management baselines under the tested settings.
Thang Dang, Yuma Ichikawa, Sakina Fatima +1
Fujitsu Research of America · Fujitsu Limited Japan · RIKEN Center for AIP