Scaling Long-Horizon LLM Agent via Context-Folding

Weiwei Sun, Miao Lu, Zhan Ling, Kang Liu, Xuesong Yao +2 more
10/13/2025
cs.CLcs.LG

No official code found. Best implementation: sunnweiwei/FoldAgent (186 stars, Apache-2.0, last commit 2026-01-26).

Abstract

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.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Scaling Long-Horizon LLM Agent via Context-Folding

18612Shell, PythonOct 9, 20258 months agoApache-2.0

Similar Papers

Cite this paper

@article{sun2025scaling,
  title  = {Scaling Long-Horizon LLM Agent via Context-Folding},
  author = {Weiwei Sun and Miao Lu and Zhan Ling and Kang Liu and Xuesong Yao and Yiming Yang and Jiecao Chen},
  year   = {2025},
  eprint = {2510.11967},
  archivePrefix = {arXiv},
  url    = {http://arxiv.org/abs/2510.11967v1}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2510.11967.svg)](https://codeofpaper.com/paper/2510.11967)

Discussion