Source-linked AI summary

Self-GC: Self-Governing Context for Long-Horizon LLM Agents

Xubin Hao, Hongjin Meng, Xin Yin, Jiawei Zhu, Chenpeng Cao

arXiv:2607.00692v1cs.AI

TL;DR

Long-horizon agents accumulate structured execution context, but token-buffer heuristics and final summaries can lose future-critical evidence and artifacts. Self-GC manages indexed context objects through planner-proposed actions and harness-controlled recovery and commits. It reports improved future-dependency preservation alongside reduced active-context cost in offline evaluations and an online account-level split.

  • Problem

    Long-horizon context methods often prune a linear token buffer or summarize near a limit, despite future steps depending on exact evidence, locators, and editable artifacts.

    Source: Introduction · pp. 1–2
  • Method

    Self-GC indexes context objects, uses a side-channel planner to propose fold, mask, and prune actions, and lets the harness rehearse and commit edits while preserving recoverability.

    Source: Introduction · p. 2, The Self-GC Framework · p. 3, Reflective Planning, Rehearsal, and… · p. 3
  • Results

    84.85% no-impact at 43.95% pruning on the 33-session Hard Set; three backbones reach 91.27% to 94.58% no-impact on the 332-session Production Suite, and production daytime input tokens fall 10% to 15%.

    Source: Introduction · p. 2
  • Takeaways & Limitations

    The results support treating agent context as indexed runtime objects with lifecycle requirements rather than as a disposable text suffix.

    Source: Introduction · p. 2, Conclusion · p. 8

    The online account split is not a fully randomized quality experiment or a matched billed-cost audit including all planner overhead.

    Source: Limitations · p. 7

Abstract

from arXiv · show

Long-horizon LLM agents accumulate tool results, files, plans, and user constraints that are too structured to be treated as a disposable text suffix. Current systems mostly rely on in-run heuristics such as chronological pruning and tool-output masking, or on final self-summary near a context limit. Heuristics are cheap but blind to future dependencies; summaries preserve narrative state but often hide exact evidence, locators, and editable artifacts. We present Self-GC, where GC denotes self-governing context while deliberately echoing garbage collection: the system does not merely reclaim unused tokens, but governs the lifecycle of agent context objects. Self-GC turns user turns, tool spans, and skill state into indexed objects; asks a side-channel planner to propose fold, mask, and prune actions; and lets the harness enforce recoverable sidecars, safe commit boundaries, and cache-aware commit. On a 33-session Hard Set, Self-GC prunes 43.95% of prefix tokens while leaving 84.85% of future continuations unaffected, compared with no-impact rates of 54.55% to 69.70% for heuristic baselines. On a 332-session production-derived suite, three planner backbones reach no-impact rates of 91.27% to 94.58%, while baselines remain at 77.71% to 87.46%. In production, an online account-level split reduces daytime average input tokens by 10% to 15%, with peak reductions near 20%. These results point to context management as runtime lifecycle control over indexed, recoverable objects rather than post hoc text cleanup.

Introduction

Long-horizon agents accumulate execution traces and artifacts beyond dialogue, while linear-buffer pruning and final summaries can discard future-critical evidence. Self-GC recasts context management as lifecycle control over indexed objects, combining a planner with harness safeguards.

Introduction

  • Linear-buffer heuristics use message age, length, and type, while final summaries can obscure exact evidence, locators, and editable artifacts needed later.The paper frames this as a mismatch between token-buffer operations and object-level future dependencies, illustrated in Figure 1.Source: Introduction · pp. 1–2, Figure 1 · p. 1
  • Self-GC indexes user turns, tool spans, and skill state, then uses a side-channel planner to propose fold, mask, or prune actions for those objects.The harness rehearses and validates edits, stores folded payloads in recoverable sidecars, and commits with cache disruption in mind.Source: Introduction · p. 2
  • 84.85% no-impact at 43.95% pruning on the 33-session Hard Set contrasts with heuristic no-impact rates of 54.55% to 69.70%; Production Suite backbones reach 91.27% to 94.58%, and production input tokens fall 10% to 15%.The Hard Set baselines prune more while achieving lower no-impact rates.Source: Introduction · p. 2
  • The paper formulates long-horizon context management as lifecycle control over indexed runtime objects rather than linear message pruning.Context objects differ in whether they can be removed, should retain structural hints, or must remain exactly recoverable.Source: Introduction · p. 2

Related Work

Prior work addresses persistent memory, active-context reduction, and inference cost through distinct approaches. Self-GC focuses on governing the active context as indexed objects while preserving recoverability and testing future-anchor retention.

Agent Memory and Context Management

  • Memory-store methods organize persistent evidence, profiles, episodes, or task memories; Self-GC instead governs the active prompt view during an ongoing run.The paper positions it as complementary to memory-store methods and distinct from message or chunk pruning.Source: Agent Memory and Context Management · p. 2

Efficient Agent Inference and Evaluation

  • Trajectory and context compressors shorten histories, while Self-GC adds harness-enforced recoverability over indexed objects; above the KV layer, it commits when savings justify cache disruption.Its judge evaluates whether retained context preserves unique anchors needed by real continuations, a question the cited interactive benchmarks do not address.Source: Efficient Agent Inference and Evaluation · pp. 2–3

The Self-GC Framework

Self-GC governs the active view between an agent harness and model input construction, operating on indexed context objects. A side-channel planner proposes lifecycle actions, while the harness rehearses, validates, recovers, and commits them under runtime constraints.

The Self-GC Framework

  • Self-GC sits between the agent harness and model input construction, assuming the harness can identify context boundaries, maintain object indices, and project an active view.The full transcript remains available outside that view for audit and recovery.Source: The Self-GC Framework · p. 3

Indexed Context Objects

  • Indexed user-request and tool-span objects give the planner stable targets and let the harness track lifecycle state and link compressed views to byte-exact sidecar payloads.The index separates recovery paths from summary prose while preserving object identity.Source: Indexed Context Objects · p. 3

Actions: Fold, Mask, and Prune

  • Fold moves exact payloads to sidecars with a recovery pointer, mask retains structural hints while eliding middle content, and prune removes obsolete content without recovery guarantees.Generated report bodies may need folding when later turns must quote or revise them exactly.Source: Actions: Fold, Mask, and Prune · p. 3

Reflective Planning, Rehearsal, and Commit

  • A side-channel planner proposes object actions; the harness rehearses edits locally, validates targets and turn boundaries, repairs lineage, persists folded sidecars, and commits accepted plans safely.Rejected plans do not affect the main agent loop; the model judges future value while the harness enforces protocol validity and recoverability.Source: Reflective Planning, Rehearsal, and… · p. 3

Recoverability and Cache-Aware Commit

  • Commits are incremental because changing the active view can disrupt a provider prefix cache; the policy weighs expected reuse savings against cache-break and GC overhead.The reported deployment regression makes immediate commit positive-value above 0.3 expected active-view pruning, an operating policy rather than a universal constant.Source: Recoverability and Cache-Aware Commit · p. 3

Experiments

The evaluation tests whether object-level lifecycle control improves token pruning while preserving downstream task continuity, using production-derived offline suites and an online account-level split. Results compare Self-GC with heuristic policies, planner backbones, and deployed control traffic.

Benchmarks

  • The 332-session Production Suite comes from production-derived traces; the 33-session Hard Set selects high sustained tool-pressure cases and skews toward browser, shell, and web-fetch workflows.These Hard Set sessions emphasize cases where exact URLs, paths, command outputs, and extracted values may be future dependencies; the online split is monitoring evidence, not a fully randomized quality experiment.Source: Benchmarks · p. 4

Metrics

  • Pruning Rate is the mean fraction of prefix tokens removed; No-impact Rate checks whether retained context supports real future turns, and Online Input Tokens measures average main-agent input tokens.The no-impact judge checks availability of exact URLs, paths, row values, task identifiers, editable bodies, and source-backed evidence; reported binary judgments use Wilson 95% confidence intervals.Source: Metrics · pp. 4–5
  • Fold moves exact payloads to sidecars with recovery pointers, mask preserves object boundaries while eliding middle content, and prune removes obsolete spans without recovery guarantees.Source: Figure 3 · p. 5

Main Results

  • 84.85% no-impact at 43.95% pruning on the Hard Set; Production Suite Self-GC reaches 91.27%–94.58% no-impact at 31.04%–33.98% pruning.On the Hard Set, heuristic no-impact rates are 54.55%–69.70%; on the Production Suite, completed heuristic baselines remain below 90% no-impact while pruning 40.19%–47.76%.Source: Table 3 · p. 5, Main Results · pp. 5–6, Table 4 · p. 6

Baselines

  • Four replayable heuristic policies cover oldest-turn chronological folding, tool-output pruning, tool masking followed by pruning, and a hybrid of turn folding and tool pruning.They approximate position-based cleanup, tool-span deletion, two-stage tool policies, and layered hand-written policies without semantic object modeling.Source: Baselines · p. 5

Base Models

  • Qwen3.6-Plus is the default side-channel planner; Qwen3.7-Max and GLM-5.1 test planner-backbone variation, while GPT-5.5 serves only as the offline judge.Source: Base Models · p. 5

Implementation Details

  • Offline experiments use a 30% compression threshold and mandatory last-turn retention; the harness rehearses plans, removes invalid actions, normalizes overlaps, and projects the retained context before evaluation.The evaluator sees the retained prefix, structured plan, impacted-turn diffs, and real future turns; removed-content diffs are judge-only counterfactual evidence.Source: Implementation Details · p. 5

Main Results

  • Self-GC’s daytime deployment group consistently uses fewer average main-agent input tokens than control; A/B calibration estimates no-impact at 92.77% versus 87.46% for oldest-turn-fold.The A/B judge reviewed 20 disagreement cases, preferring Self-GC in 11, tying in seven, and preferring the baseline in two.Source: Main Results · p. 6

Analysis and Discussion

Fixed heuristics can discard unique evidence and artifacts, while Self-GC’s planner backbones exceed 90% no-impact on the Production Suite. Production monitoring also reports lower daytime input-token use under Self-GC.

Failure Modes of Fixed Heuristics

  • Fixed heuristics fail differently: tool pruning is competitive on re-queryable BI sessions, while chronological folding performs better on DOC/CODE workloads with unique artifacts.Audited losses include evidence details, locators, behavioral contracts, verbatim text, and live execution state.Source: Failure Modes of Fixed Heuristics · p. 6
  • Self-GC’s ordered object-action rules prefer tool-level folds for editable or evidence-bearing content and prune obsolete searches only after dependencies clear.The prompt’s hard rules and examples favor fold over mask for large stable bodies that may need idempotent recovery.Source: Failure Modes of Fixed Heuristics · p. 6

Relation to Industrial and Method Baselines

  • DeepSeek-V3.2 strategies and recent methods are treated as policy references or future comparisons, not direct baselines, because their settings differ from this study’s traces.The completed comparison focuses on reproducible heuristics under a shared cut-point replay protocol.Source: Relation to Industrial and Method… · p. 6

Planner Robustness

  • Qwen3.6-Plus, Qwen3.7-Max, and GLM-5.1 each exceed 90% no-impact on the Production Suite, but last-turn edits still require protection.The planners touch the cut turn in 25/330, 15/330, and 12/328 parsed plans, respectively.Source: Planner Robustness · p. 6
  • Figure 4 shows Self-GC shifting toward higher preservation at safer pruning, while Figure 5 reports 10% to 15% daytime input-token reductions, peaking near 20%.The Figure 5 final window includes volatile month-end batch API traffic.Source: Figure 4 · p. 7, Figure 5 · p. 7

Limitations

The evaluation has limits in production interpretation, trace availability, and measurement coverage.

Limitations

  • Online logs report input-token reductions under an operational account split, not a fully randomized quality experiment or matched billed-cost audit including planner overhead.The A/B calibration set is small.Source: Limitations · p. 7
  • Raw production traces contain private user data and cannot be released directly, so reproducibility depends on sanitized fixtures and supporting materials.The proposed package includes prompt templates, per-sample judge outputs, and aggregate-statistic recomputation scripts.Source: Limitations · p. 7
  • Future evaluation should add binary-payload recoverability tests, judge-sensitivity analysis, and richer online quality metrics.Source: Limitations · p. 8

Conclusion

Self-GC treats agent histories as runtime objects with distinct lifecycle requirements and uses harness-controlled edits to preserve recoverability and cache locality.

Conclusion

  • Self-GC combines indexed context objects, a side-channel planner, and harness-controlled rehearsal and commit to reduce active-context cost while preserving future dependencies.The paper concludes that context management should govern recoverable runtime objects rather than rely on heuristic cleanup or final summaries alone.Source: Conclusion · p. 8

Dataset Details

Raw production traces are not directly releasable, so reproduction relies on sanitized materials and scripts.

Dataset Details

  • Raw production traces contain private user data and cannot be released directly; reproduction should use sanitized fixtures, planner outputs, candidate patches, token estimates, prompts, judge outputs, and recomputation scripts.Source: Dataset Details · p. 10

Evaluation Artifacts

The evaluation harness organizes evaluation around four artifacts, including object identifiers and planner output. Its diff-grounded evaluator exposes pruning changes to the evaluator, not the agent’s active view.

Evaluation Artifacts

  • The harness organizes evaluation around four artifacts: object identifiers, planner output, projection replay, and semantic validation.The planner uses conversation:user:n and function:tool:n identifiers; projection replay includes target resolution, normalization, sidecar persistence, lineage repair, and provider-message normalization.Source: Evaluation Artifacts · p. 10
  • The evaluator receives retained context, pruning diffs for impacted turns, and the actual future turns to judge whether the continuation remains supported.The diff is for counterfactual inspection only and is not part of the evaluated agent’s active view.Source: Evaluation Artifacts · p. 10
  • The example session assigns a stable conversation:user:1 identifier to a user turn and shows a tool result reading src/main.py.The example’s tool output includes the program’s main function and a Self-GC startup message.Source: Evaluation Artifacts · p. 10

Prompt Contracts

The appendix specifies planner and judge contracts, implementation details, and failure cases for Self-GC. It also records future directions and reproducibility and evaluation-scope information.

Prompt Contracts

  • Planner safeguards exclude the latest turn, active instructions, live handles, editable bodies, and exact evidence, while matching fold, mask, or prune to content needs.The planner emits a short conversation summary and grouped targets over existing object identifiers; Table 5 summarizes the safeguards.Source: Prompt Contracts · pp. 10–11
  • The judge checks whether concrete future dependencies remain visible or recoverable after projection; narrative coherence alone is insufficient.The A/B judge compares candidates for the same cut point and continuation, choosing the one that better preserves dependencies in retained context and impacted-turn patches.Source: Prompt Contracts · pp. 10–11

Implementation Details

  • Offline evaluation uses shared cut points, token accounting, mandatory last-turn retention, and a GPT-5.5 no-impact judge; the runtime stages plans before safe-boundary commit.The pseudocode forks a snapshot for planning, normalizes targets, applies a projection locally, then merges pending plans, repairs object lineage, and persists folded payloads at a safe turn boundary.Source: Implementation Details · p. 11

Failure Categories and Case Studies

  • The failure taxonomy classifies risk by unsupported future actions; case studies show retained warning bridges and contract locators alongside folded bulky content.In document repair, Self-GC retained a warning needed for localized edits; in data entry, it folded file bodies with recovery pointers while keeping contract locators visible.Source: Failure Categories and Case Studies · p. 11

Architectural Details / Future Work

  • Figures 6 and 7 depict planning, rehearsal, and commit alongside context-object identifiers, lifecycle state, recovery pointers, and active-view projection.Future work includes additional harness ports, lighter task-conditioned policies, and combining runtime GC with hierarchical memory or retrieval stores.Source: Architectural Details · p. 11, Future Work · p. 11, Figure 6 · p. 13

Reproducibility Checklist

  • The reproducibility checklist marks the method outline and distinction between objective results and speculation as present, with background references provided.The checklist instructs authors to answer yes when information appears in the paper or an explicitly referenced technical appendix.Source: Reproducibility Checklist · p. 15

Theoretical Contributions

  • The paper describes itself as a systems and empirical methods contribution that introduces a runtime framework and evaluation protocol rather than formal proofs.The checklist states that the paper makes no theoretical contributions.Source: Theoretical Contributions · p. 15

Datasets / Computational Experiments

  • Primary evaluations use private production-derived traces; raw traces are not publicly available, and the checklist reports missing development sweeps, code release, and formal significance tests.A sanitized reproduction package is planned but not yet released; confidence intervals and a small A/B judge calibration set are reported instead of formal significance tests.Source: Datasets · p. 15, Computational Experiments · p. 15
Loading 2607.00692v1…