Scaling Long-Horizon LLM Agent via Context-Folding
Weiwei Sun, Miao Lu, Zhan Ling, Kang Liu, Yao, Xuesong, Yiming Yang et al. · 2026 · 200 citationsRead the paper
Large language model (LLM) agents are fundamentally constrained by context length on long-horizon tasks. We introduce Context-Folding, a framework that empowers agents to actively manage their working context. An agent can procedurally branch into a sub-trajectory to handle a subtask and then fold it upon completion, collapsing the intermediate steps while retaining a concise summary of the outcome. To make this behavior learnable, we develop an end-to-end reinforcement learning framework FoldGRPO with specific process rewards to encourage effective task decomposition and context management. On complex long-horizon tasks (Deep Research and SWE), our folding agent matches or outperforms the ReAct baselines while using an active context 10$\times$ smaller and significantly outperforms models that rely on summarization-based context management.
What the full text shows
Working prototype- The folding agent achieved pass@1 scores on long-horizon tasks while using an active context 10x smaller than the total token cost of long-context baselines. — 62.0% pass@1 (BrowseComp-Plus) and 58.0% pass@1 (SWE-Bench Verified) (Using Seed-OSS-36B-Instruct with FoldGRPO RL training)
- FoldGRPO significantly improved context compression and task completion compared to standard GRPO. — Over 90% context compression (main trajectory reduced to ~8K tokens while processing >100K total) (Compared to standard GRPO on the folding agent)
- The folding agent outperformed the long-context ReAct agent using the same maximum total token budget. — Pass@1 of 0.620 vs 0.540 (BrowseComp-Plus) and 0.580 vs 0.574 (SWE-Bench Verified) (Maximum total token cost of 327K)
- RL training provided larger performance gains on more difficult task subsets. — Significant improvements in medium and hard instances (Across BrowseComp-Plus and SWE-Bench Verified)
- Setup
- Base model Seed-OSS-36B-Instruct; datasets include BrowseComp-Plus (680 train/150 eval) and SWE-Bench Verified (740 training instances); max active context 32,768 tokens with up to 10 branches.
- How
- Introduced Context-Folding, allowing agents to use 'branch' and 'return' tools to isolate sub-tasks and collapse intermediate steps into summaries. Developed FoldGRPO, an RL framework using process rewards (Unfolded Token Penalty and Out-of-Scope Penalty) to optimize task decomposition and context management.
- Limitations
- Maximum of 10 branches allowed per task · Requires specific RL training (FoldGRPO) to unlock effective folding behavior
Summarized by Gemma 4 from the open-access full text · 26 Nov 2026. Read it