TL;DR
Long-horizon LLM agents struggle with expanding context windows, but compressing history ("context folding") via reinforcement learning (RL) typically causes training collapse because the agent's summaries alter its own future observations. FoldAct solves this by decoupling summary and action losses, enforcing full-context consistency, and using selective turn training. This stabilizes the training process while delivering a 5.19× training speedup.
What Problem Does This Paper Address?
When Large Language Model (LLM) agents tackle complex, multi-step tasks—like navigating the web or executing multi-hop retrieval-augmented generation (RAG)—their interaction histories grow rapidly. This causes severe computational bottlenecks during training and inference.
To manage this, recent methods use "context folding," where the agent generates summary actions to compress its own history. However, existing RL frameworks treat these summaries just like standard actions (e.g., tool calls). The authors identify a fundamental flaw in this assumption: summaries directly reconstruct the agent's future observation space.
This creates a policy-dependent, non-stationary observation distribution, leading to three major challenges:
- Gradient Dilution (C1): Summary tokens make up a small fraction of the total trajectory, meaning their training signals get drowned out by standard action tokens.
- Self-Conditioning & Training Collapse (C2): If a policy update makes the summary slightly worse, the agent misses critical information in subsequent turns. This causes reward degradation, which further ruins the policy, creating a vicious cycle of training collapse.
- High Training Costs (C3): Because every turn features a unique, dynamically compressed context, standard optimizations like KV-cache reuse fail, making training incredibly slow.
Methods
FoldAct introduces three core innovations to stabilize and accelerate context folding:
- Separated Loss Computation (C1): Instead of computing a unified gradient, FoldAct uses token masking to separate summary tokens from action tokens, calculating independent PPO losses for each. It introduces summary-specific rewards: a Hallucination Penalty (penalizing summaries generated when no new info is available) and an Information Retention Reward (rewarding summaries that preserve critical information leading to task success).
- Full Context Consistency Loss (C2): To break the self-conditioning loop, the framework minimizes the KL divergence between the policy distribution conditioned on the compressed context and the policy distribution conditioned on the full, uncompressed history (stored offline). This anchors the agent's behavior so that compression doesn't cause severe distribution shifts.
- Selective Segment Training (C3): Rather than calculating losses at every single turn—which requires expensive forward passes over variable-length contexts—FoldAct randomly samples a subset of trajectory turns for training based on a dropout probability ($p_{drop}$), dramatically cutting down computational overhead.
Datasets
The authors evaluated FoldAct across two distinct long-horizon scenarios:
- Local RAG: Evaluated on HotpotQA and PopQA using
Qwen-2.5-7B-Instructas the base model. - Web Search: Evaluated on four dynamic web navigation benchmarks: WebWalker, GAIA, BrowseComp, and XBench-DeepSearch.
Key Insights and Ideas
- Summaries are Observation Architects: In long-horizon tasks, text generation isn't uniform. Summary tokens act as the "architects" of the agent's future state space, meaning they require distinct credit assignment strategies compared to standard actions.
- The Danger of Blindness: Standard RL assumes a stationary environment. In context folding, the environment is stationary, but the agent's perception of it is highly non-stationary. A single bad policy update can permanently "blind" the agent for the rest of the trajectory.
- Consistency Over Execution: You don't need to run the full context during rollouts to maintain accuracy. You only need to force the model's compressed-context representations to match its full-context representations during the training phase.
Key Results
- Elimination of Training Collapse: Without consistency loss, the actor KL loss becomes highly unstable, leading to catastrophic training collapse around step 173 where the model begins generating massive, repetitive token sequences. FoldAct maintains perfect stability throughout training.
- Substantial Speedups & Memory Savings: Full context training easily triggers Out-of-Memory (OOM) errors (>441 GB peak memory). FoldAct with selective segment training ($p=0.5$) and consistency loss achieves a 5.19× speedup while keeping memory usage manageable.
- State-of-the-Art Performance: On HotpotQA, FoldAct achieved an Exact Match (EM) score of 29.5, significantly outperforming the best baseline (ASearcher at 22.7). On WebWalker, FoldAct-7B scored 46.1, outperforming the much larger 32B ASearcher-Web-QwQ model.
Limitations and Future Work
While selective segment training drastically reduces costs, introducing the full context consistency loss requires an extra forward pass over the uncompressed history. As shown in the paper's cost analysis, this reduces the raw speedup from a potential 49.6× (without consistency loss) down to 5.19×. Future work could focus on optimizing this consistency check, perhaps by using distilled reference models or lighter alignment mechanisms to bypass full-history forward passes entirely.
Summary updated