ZICQ
中 Log in / Sign up
Newsroom Agentic #RECAP #Context Compaction #Long-Horizon Agents #Reinforcement Learning #Self-Distillation

RECAP: Behavior-Preserving Context Compaction for Long-Horizon LLM Agents

Avatar of Mr.Xu

By Mr.Xu Compiled & Reviewed by Editorial

Published:

中文阅读 (Chinese) English Version
Co-reading Select any sentence in the article to highlight, annotate, or copy a quote card. Join discussion ↓

Summary:RECAP reframes context compaction as a policy-learning problem rather than a standalone summarization task. Its behavior-distortion objective compares the actions induced by an original interaction history with those induced by the compacted context. The resulting gradient is decomposed into a distortion-based reward for summary generation and self-distillation for post-compaction actions, giving the summarizer a more direct learning signal than delayed task success alone. Using Qwen3.5-4B, REC


Core mechanism: compress history without changing decisions

RECAP's central claim is that a summary should preserve not the wording of the original interaction history, but the behavior that history induces in the agent. Let H_t denote the full history before compaction, s_t the generated summary, and πθ the agent policy. The behavior distortion can be understood schematically as D(H_t, s_t) = Div(πθ(·|H_t), πθ(·|s_t)). The precise divergence, action space, and sampling procedure require confirmation from the full paper.

This distinction matters for long-horizon agents. A semantically plausible summary may still omit an exact error message, file path, tool argument, or previously attempted fix, causing the policy to change its next action. Conversely, a short summary can be operationally better if it retains the state required for the next decision. RECAP therefore optimizes behavioral continuity rather than text-level similarity between the summary and the source history.

Conceptually, the objective can be written as L ≈ L_task + λL_dist: the first term retains the original task reward, while the second penalizes divergence between behavior under full and compacted contexts. This is an explanatory formulation rather than a verbatim equation from the paper abstract.

Gradient decomposition: train both summarization and actions

RECAP reports that the gradient of the behavior-distortion objective decomposes into two complementary learning signals.

The first is a distortion-based reward for summary generation. When the full-history and compacted-history branches diverge in their subsequent actions, that divergence is propagated back to the summarizer. The summary is thus rewarded for preserving information that influences future decisions rather than merely producing a plausible narrative. This addresses the severe credit-assignment problem of task-only reinforcement learning, where a bad summary can affect many later steps and receives only weak attribution from a sparse terminal reward.

The second signal is self-distillation for subsequent actions. The full-context branch provides a teacher target, while the compacted-context branch learns to reproduce that behavior. The model therefore learns both how to summarize and how to act effectively after compaction. Ablations support the need to supervise both components jointly, although the abstract does not provide per-signal gains, ablation configurations, or variance estimates.

This design treats context management as part of policy optimization. Rather than compressing history with a separate summarizer and then optimizing the downstream agent in isolation, RECAP places memory and action learning inside a shared objective.

Engineering trade-offs and measured results

For a Transformer-based agent service, KV-cache storage can be approximated as 2 × L × n_layer × n_kv × d_head × b, where L is the context length, n_kv is the number of KV heads, and b is the storage size per element. Reducing history from L to Lc should reduce the dominant cache component roughly in proportion to Lc/L, although fixed prompts, tool definitions, the summary itself, and cache-management overhead remain.

Shorter contexts can also reduce prefill cost. The dominant term of dense self-attention grows approximately quadratically with sequence length, and tool-using agents repeatedly extend their trajectories after each interaction. Early compaction may therefore lower both memory pressure and end-to-end latency. Summary generation, however, introduces an additional forward pass, so an aggressive compaction schedule can erase part of those savings.

Training becomes more expensive because RECAP requires both full-context and compacted-context branches. The full branch supplies teacher behavior, the compact branch exposes compression errors, and the summarizer must be optimized through their mismatch. Without an equal-compute comparison, it remains unclear whether the reported task gains compensate for the additional rollouts, forward passes, trajectory storage, and GPU memory.

Behavior preservation is not the same as factual correctness. A teacher policy may itself be wrong; self-distillation can faithfully preserve that error. Low distortion at the current step also does not guarantee preservation across every future trajectory branch. Rare but decisive details may still disappear, which is why production systems should retain structured state, raw logs, or rollback capability alongside generated summaries.

Benchmark interpretation

Using Qwen3.5-4B, the paper reports absolute improvements of 4.6% on BrowseComp-plus and 4.3% on SWE-bench Verified over reinforcement learning baselines trained with task rewards alone. In conventional benchmark terminology, these correspond to gains of 4.6 and 4.3 percentage points, although the original absolute scores and aggregation method are not given. Ablations further support jointly supervising summary generation and post-compaction behavior.

The results indicate that behavior distortion supplies a useful signal beyond terminal task reward, but they do not yet establish production-level gains. The abstract omits baseline scores, random seeds, confidence intervals, statistical significance, the compaction trigger, the compression ratio, and whether both methods receive equal rollout, token, and GPU budgets.

Four questions remain essential. Are the gains stable across runs or within random variance? Do they arise from better summaries or merely from stronger policy fitting under additional supervision? Does the method remain advantageous after accounting for its higher training cost? Could training trajectories, task templates, or generated summaries overlap with the evaluation sets?

The experiments also cover only one 4B-scale backbone. Generalization to larger models, different tool protocols, and non-Qwen families remains untested. Although browsing and software repair both impose long action chains, the abstract does not reveal whether compaction is triggered at every step, at a fixed context threshold, or autonomously by the model.

Deployment guidance for developers

RECAP should not be deployed directly in high-risk production settings without independent reproduction, but its mechanism translates into a concrete engineering protocol.

  1. Separate structured task state from narrative summaries. Preserve the objective, hard constraints, executed commands, exact paths and identifiers, unresolved errors, and next hypotheses in fields that are not left entirely to free-form compression.
  2. Construct dual-branch trajectories offline. Retain a full-context teacher branch, generate a compacted student branch, and log action-distribution divergence, critical-action agreement, and failure attribution alongside the terminal task reward.
  3. Run only the compact branch online. The full history need not remain in the serving path, but original trajectories or recoverable snapshots should be retained for auditing decision drift.
  4. Tune summary length and distortion weight jointly. A small λ allows task reward to dominate again; an excessively large value can preserve excessive text. Plot task success, compression ratio, Token cost, and latency rather than optimizing one metric in isolation.
  5. Start with shadow-mode A/B tests. Let RECAP and the existing memory policy propose actions in parallel without executing extra actions, then align model versions, tool outputs, and task budgets before comparing long-horizon success and error propagation.
  6. Add rollback and access controls. Restore the original context whenever a summary changes a critical action, and apply separate retention and access policies to raw logs, tool outputs, and summaries.

RECAP's main contribution is to frame context compaction as a policy-consistency problem and connect memory quality to action quality through a trainable distortion signal. If the full paper confirms the behavior metric, equal-compute baselines, and cross-model results, the framework could become a strong alternative to fixed truncation or independently trained summarizers in long-horizon agent training pipelines.


Source: ArXiv NLP/LLM (cs.CL) (2026-11-25)

— END —

Tags: #RECAP #Context Compaction #Long-Horizon Agents #Reinforcement Learning #Self-Distillation

Editorial & Fact-Checking Note: This article is compiled from primary research, official release documentation, and source papers by the ZICQ Newsroom pipeline with automated entity verification and human editorial review. If you notice any technical inaccuracy, please submit a correction via our corrections policy or email our editorial desk directly.

What's your take on this story?
🚀 Explore & Submit Works

Community Comments

Loading live comments and annotations…