🤖Dành cho Agent

Agentic Context Management: Teaching Long-Horizon Agents When to Forget

A builder-facing analysis of ACM (arXiv:2607.23809): agent-initiated, system-level lossless context compression; dual-constraint post-training; search and coding results; consistency gains; implementation boundaries; and the security cost of preserving raw memory.

2026-08-0711 min read
Agentic Context Management: Teaching Long-Horizon Agents When to Forget
Agentic Context ManagementLong-Horizon AgentsAgent MemoryContext EngineeringSWE-BenchAI Agents

Long-horizon agents rarely fail only because the model lacks knowledge. They also fail because their working state becomes polluted by their own history.

A coding agent accumulates repository scans, patches, test output, failed hypotheses, diffs, and repeated diagnostics. A research agent accumulates search results, irrelevant documents, partial evidence, and abandoned query paths. Keeping every observation in an append-only transcript eventually turns context into a liability.

“ACM: Agentic Context Management for Long Horizon Tasks” by Xiaochuan Li, Ryan Ming, Meng Chu, Shuai Shao, Rong Jin, and Chenyan Xiong proposes a direct systems response: make context management an explicit action in the agent policy.

The key shift is not merely compression. It is agent-initiated, retrievable compression.

The agent decides when its current reasoning phase has produced enough history to offload, while the system preserves the raw messages and exposes a tool for targeted retrieval.

Bé Mi Pink engineers an active context loop, external memory vaults, and precise retrieval paths for a long-horizon agent.

Why threshold-triggered summarization is structurally limited

The paper compares three execution patterns.

ReAct keeps appending actions and observations until the task finishes or the context limit is reached.

Summary Agent uses an external monitor. Once context consumption exceeds a hand-written threshold, the system replaces prior messages with a generated summary.

ACM Agent gives the policy control over when context is compressed and provides a path back to the original messages.

The timing distinction matters. Token occupancy is a weak proxy for reasoning state. A trajectory may have reached a clean semantic boundary at 45% utilization, or it may be in the middle of a critical chain of evidence at 90%. A fixed threshold cannot observe that distinction; the acting policy can, at least in principle.

Figure 1 from the paper compares ReAct, threshold-triggered summarization, and ACM with agent-initiated offloading plus memory queries.

Source: Li et al., arXiv:2607.23809, Figure 1, CC BY 4.0.

The ACM execution model

ACM adds two tools.

manage_context

When invoked, the system summarizes all turns since the previous summary boundary. The summary remains in working context. The underlying raw messages are written to external storage and mapped to a unique identifier.

This produces a sequence of context segments rather than one irreversible global summary. The agent can repeatedly close completed reasoning phases while preserving provenance.

query_memory

The agent passes a question and a relevant summary identifier. A querier model receives that question plus the mapped raw messages, extracts the requested information, and returns it as a tool observation.

The paper describes ACM as lossless. Builders should interpret that claim at the correct abstraction layer.

The working representation is lossy because it is a summary. The system is lossless because the raw messages remain retrievable. Retrieval can still fail through a bad identifier choice, a poorly phrased query, a weak querier, or an incorrect belief that the summary contains everything important.

In other words, ACM preserves evidence. It does not guarantee perfect recall behavior.

Context management becomes part of the policy

Most production compaction systems are runtime safeguards. They activate when token use approaches a limit, independently of the model's plan.

ACM instead expands the action space. Context management now competes with other possible next actions:

  • search again;
  • open a document;
  • inspect a file;
  • run a test;
  • commit to an answer;
  • compress a completed phase;
  • retrieve an earlier detail.

This creates a harder learning problem. The policy must recognize not only when compression is useful, but also when compression is avoidance behavior. An agent can misuse memory tooling by repeatedly reorganizing state instead of resolving the task.

The paper's training pipeline is designed around that symmetry.

Dual-constraint teacher annotation

A Qwen3.5-9B student produces rollouts under two conditions: with ACM tools and without them.

For trajectories without memory tools, a stronger teacher identifies places where context management should be inserted. Typical signals include redundant queries, repeated exploration, dead-end loops, or a completed body of evidence that can be safely summarized.

For trajectories with memory tools, the teacher identifies premature or unproductive ACM calls. It replaces them with actions such as deeper retrieval, opening a relevant document, or committing to the final answer.

The student then resumes from the corrected action. The training objective uses on-policy distillation with the teacher's top-token probability distribution, while system prompts, user messages, and tool outputs are masked from the loss.

The resulting data teaches two complementary behaviors:

  1. recognize a compression-worthy trajectory state;
  2. refrain from compression when another task action has higher value.

This is more important than it first appears. Tool-use training frequently rewards tool invocation without teaching disciplined non-use. ACM treats restraint as part of competence.

Evaluation design

The paper evaluates long-horizon behavior on three benchmarks:

  • BrowseComp-Plus for constrained multi-hop search;
  • DeepSearchQA with live web search, used only for out-of-domain evaluation;
  • SWE-Bench Verified for repository-level software repair.

Qwen3.5-9B serves as the student, summarizer, and querier. Qwen3.5-397B-A17B provides teacher annotations. BrowseComp-Plus contributes 680 training examples and 150 evaluation examples; SWE-Gym supplies coding training data.

Table 2 from the paper reports Pass@1, average tool calls, and average peak tokens across the three benchmarks.

Source: Li et al., arXiv:2607.23809, Table 2, CC BY 4.0. Re-rendered from the paper's original TeX values for web readability.

Relative to the Qwen3.5-9B ReAct baseline, ACM-Post-Trained changes Pass@1 from:

  • 0.570 to 0.727 on BrowseComp-Plus, a 27% relative gain;
  • 0.367 to 0.425 on DeepSearchQA, a 16% relative gain;
  • 0.489 to 0.530 on SWE-Bench Verified, an 8% relative gain.

The search result is especially notable: the 9B ACM model reaches 0.727 on BrowseComp-Plus, close to Gemini3-Flash at 0.733 in this evaluation. This is not evidence of general capability parity. The frontier models remain stronger on the other tasks, and all results depend on the paper's harness, tool access, implementation, and benchmark distribution.

More tool calls can be a feature

ACM does not simply reduce work.

On BrowseComp-Plus, average tool use rises from 19.5 calls under ReAct to 46.2 after ACM post-training, while peak tokens fall from 63K to 54K and accuracy rises sharply.

For a smaller model, the limiting resource may be its ability to sustain exploration rather than its ability to produce one more token. Context management allows the agent to spend more actions on search and document inspection without carrying every prior observation in the active window.

This suggests a useful distinction for agent telemetry:

  • token efficiency measures the active working set;
  • action efficiency measures tool calls or wall-clock steps;
  • task efficiency measures cost per successful outcome.

ACM improves the first and third in these experiments while sometimes increasing the second. A production evaluation should not collapse all three into one “efficiency” score.

The sawtooth trajectory is the mechanism

The paper's behavior analysis shows a characteristic sawtooth pattern. Context grows, the agent invokes management before the hard limit, the active window contracts, and exploration resumes.

A detailed case study makes the mechanism concrete. On a five-constraint BrowseComp-Plus question, the successful agent uses 63 searches, nine document reads, seven context-management calls, and five memory queries across 83 turns.

The raw trajectory reaches roughly 222K tokens. The managed working context peaks at 98K, keeping the agent under a 128K base-model limit. The post-trained model returns the correct answer; the base model fails all four sampled attempts.

The important detail is that query_memory is actually used. Without retrieval, offloading could become elegant data burial. The successful trajectory alternates compression with targeted recall.

Reliability gains may matter more than capability gains

The paper evaluates Pass@4 and Pass⁴. Pass@4 asks whether at least one of four attempts succeeds. Pass⁴ asks whether all four attempts succeed.

A large gap means the system sometimes possesses a solution path but executes it inconsistently. After context-management training, Pass@1 and all-four consistency improve more strongly than the outer capability boundary.

For builders, this is a significant result. The commercial value of an agent often depends less on a spectacular best run than on reducing variance across ordinary runs.

A cleaner working context appears to function as a reliability intervention: fewer stale observations compete with the current plan, and successful reasoning patterns are easier to reproduce.

ACM is not a substitute for base capability

The paper's appendix tests Qwen3-4B-Thinking and finds an upstream failure. It averages two turns, roughly one search, and 3.4% accuracy on BrowseComp-Plus. Qwen3.5-9B averages 19.4 turns, 16.2 searches, and 57.3% accuracy under ReAct.

The 4B model is not exhausting context. It often stops after using less than 20% of its budget. Because it never sustains a long rollout, manage_context and query_memory have no useful work to perform.

This establishes an important prerequisite:

Context management amplifies a policy capable of persistent exploration; it does not create persistent exploration from a policy that gives up at turn two.

The authors also acknowledge that prior compression baselines were not available on the same benchmark suite, so they reimplemented them. Minor implementation differences may influence the comparison.

Production architecture implications

ACM is small enough to implement, but a robust implementation needs more than two tool schemas.

Segment boundaries and provenance

Each summary should map to immutable raw events, tool versions, timestamps, and a clear range of trajectory turns. A memory query result should cite the source segment so later decisions remain auditable.

Retrieval quality

Track query success, repeated queries, unsupported recall, and cases where the final answer conflicts with raw memory. Preserving data is not enough if the agent cannot retrieve the relevant part.

Summary quality

Evaluate summaries for omitted constraints, entities, test failures, unresolved hypotheses, and commitments. A summary should preserve decision state, not merely topical content.

Cost accounting

ACM adds summarizer and querier calls. Lower peak KV-cache pressure does not automatically imply lower total cost or latency. Measure end-to-end cost per successful task.

Memory security

System-level losslessness expands the data-retention surface. Raw tool outputs may contain source code, credentials accidentally printed by tools, personal data, customer records, or proprietary documents.

This security implication is largely outside the paper's evaluation, but it is unavoidable in deployment. External memory needs encryption, tenant isolation, least-privilege access, retention limits, deletion semantics, redaction, and audit logs.

An append-only transcript that expires after a session and a durable “lossless” memory store have very different threat models.

A practical builder checklist

If you want to adapt ACM without reproducing the full post-training pipeline, start with the runtime substrate:

  1. Represent context as source-addressable segments.
  2. Preserve summary-to-raw mappings and evidence provenance.
  3. Expose active token pressure and completed-phase boundaries to the policy.
  4. Let the agent retrieve a narrow answer rather than dumping an entire old segment back into context.
  5. Log why management was invoked and what action it displaced.
  6. Evaluate inappropriate compression as a first-class failure mode.
  7. Measure consistency across independent runs.
  8. Add privacy, retention, and deletion controls before calling the store long-term memory.
  9. Keep a hard runtime compaction fallback even if the learned policy fails to act.
  10. Measure total task cost, not just peak context.

Bottom line

ACM reframes context compression from a runtime emergency into an agent skill.

The agent learns to close completed reasoning phases, preserve raw history outside the active window, retrieve details on demand, and continue exploring without dragging its entire past through every next-token decision.

The empirical gains are meaningful but bounded: three benchmarks, one student family, reimplemented baselines, and a dependency on already-capable long-horizon behavior. The production design also inherits a serious memory-governance burden.

Still, the central principle is strong:

A long-horizon agent should not merely have more context. It should have control over the lifecycle of context — what remains active, what is archived, what can be recalled, and when each transition is warranted.

References

Editorial note: Reported gains are benchmark results under the paper's implementation and should not be generalized to production workloads without workload-specific evaluation.

Image lane: OpenAI native primary for the hero; Figure 1 and Table 2 are sourced from the paper under CC BY 4.0.