RECAP: Training Long-horizon LLM Agents with Context Compaction
Abstract
Context compaction enables large language model agents to tackle long-horizon tasks within limited context budgets by replacing interaction histories with compressed summaries. However, learning effective compaction jointly with the agent policy remains challenging, as summaries affect task success over many subsequent interactions. We introduce RECAP, a reinforcement learning (RL) framework based on the principle that a summary should preserve the behavior induced by the original interaction history. We formalize this principle with a behavior distortion objective that measures the divergence between the agent's subsequent behavior under compressed and original contexts. We show that the gradient of the distortion objective decomposes into two complementary learning signals: distortion-based reward for summary generation and self-distillation for subsequent actions. Experiments on Qwen3.5-4B show that RECAP consistently outperforms the task-reward-only RL baselines on both environments, leading to an absolute improvement of 4.6% and 4.3% on BrowseComp-plus and SWE-bench Verified, respectively. Ablations further highlight the value of jointly supervising summary generation and post-compaction behavior for RECAP.
Create a lesson
Metadata
- Categories
- cs.CL, cs.AI
Related papers
Uni-Mem: Learning a Long-Horizon Agentic Memory Manager with Unified Online Policy Optimization
Shared title terminologycs.CLZhiqian Xia, Jielong Tang, Ling-An Zeng et al.
LAMB: Latent Multi-Hypothesis Beliefs for Long-Horizon Large Language Agents
Shared title terminologycs.CLPeien Ding, Hui Li, Yuhan Liu et al.
MERIT: Experience-Guided Memory for Long-Horizon Persona-Specific Persuasive Dialogue
Shared title terminologycs.CLRohan Kirti, Akash Ghosh, Pratik Amrit et al.
ContextFact: Remembering Facts in Context for Long-Term Conversational Agents
Shared title terminologycs.CLJiayu Huang, Yichao Cai, Xinyu Li et al.
Don't Stop Long-Context Continual Pre-Training Too Early: An Empirical Scaling Law
Shared title terminologycs.CLZiqing Qiao, Xiaoyue Xu, Sikui Zhang et al.
What Makes Good Data for Training Coding Agents? A Systematic Study on SWE-Gym
Shared title terminologycs.CLYikai Zhang, Mai Xu, Yunbei Zhang et al.