Scaling Long-Horizon LLM Agent via Context-Folding
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 10times
smaller and significantly outperforms models that rely on summarization-based
context management.
68f0409136f8b025381e189e
Weiwei Sun
68f0409136f8b025381e189f
Miao Lu
68f0409136f8b025381e18a0
Zhan Ling
68f0409136f8b025381e18a1
Kang Liu
68f0409136f8b025381e18a2
Xuesong Yao
68f0409136f8b025381e18a3
Yiming Yang
68f0409136f8b025381e18a4
Jiecao Chen
Scaling Long-Horizon LLM Agent via Context-Folding
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 10times
smaller and significantly outperforms models that rely on summarization-based
context management.
Context-Folding, an end-to-end reinforcement learning framework, enables LLM agents to manage context effectively by branching into subtasks and folding them, outperforming baselines on long-horizon tasks with reduced context size.
Context-Folding reinforcement learning FoldGRPO task decomposition context management Deep Research SWE ReAct baselines summarization-based context management