Context compaction is the process of summarising or pruning conversation history so a long-running AI session can continue inside a fixed token window. It is useful for continuity, but it can also remove standing instructions, making it a security-sensitive operation in agentic systems.
What Context Compaction Does
Context compaction is a control-plane operation for long-running AI sessions. It reduces older dialogue into a shorter working memory so the session can stay within a fixed token window, preserve continuity, and keep important task state available. In practice, it trades completeness for survivability, which is why it needs governance in agentic workflows.
Why Context Compaction Matters in Long-Running Sessions
The main value of compaction is that it lets an agent continue after the raw conversation would otherwise exceed the model’s context limit. That is useful for assistants that maintain plans, tool state, or multi-step workflows over time. The downside is that anything not carried forward, especially policies, constraints, or prior decisions, may vanish from the active prompt even though the user still expects it to apply.
Because the summary becomes the new operating memory, the compaction step is not neutral. It can change what the model “remembers” to be true, which means the quality of the summary directly affects task safety, instruction fidelity, and the integrity of follow-on actions.
How Compaction Can Change Security Behaviour
Compaction can silently remove standing instructions that were meant to constrain the session, such as approval rules, refusal boundaries, tool-use limits, or escalation requirements. If those constraints are not preserved, the agent may continue with an incomplete policy picture and behave as though the missing instructions never existed.
In agentic systems, that is especially sensitive because compaction may sit between the user, the model, and downstream tools. A summariser that drops a restriction can unintentionally widen the agent’s effective authority, particularly when the session depends on prior context to remember what it is and is not allowed to do.
What Good Compaction Preserves
Useful compaction preserves the facts that change future decisions: task objective, unresolved questions, explicit constraints, tool state, safety boundaries, and any commitments the session still needs to honour. It should reduce repetition without erasing meaning, and it should distinguish between background detail and active instructions.
Lossy compression becomes risky when the summary retains only the narrative flow but not the governing rules. A compacted history that is concise but semantically incomplete can create a false sense of continuity, because the session appears coherent while the policy state has been degraded.
Compaction, Memory, and Trust Boundaries
Context compaction is not the same as durable memory. It is a temporary representation of what the session needs right now, not a reliable archive of everything that was said. That distinction matters when systems use compaction as input to planning, delegation, or tool execution, because the compacted text becomes a trust boundary between prior conversation and current action.
In secure designs, the compaction step should be treated like any other transformation that can alter control state. If the summary is generated by the model itself, or by a separate service, the organisation needs to understand what can be lost, who can influence the summarisation, and how omitted instructions are recovered.
Risk and Threat Considerations
Context compaction can create security exposure when it drops constraints, approvals, or safety instructions from the active session. In agentic systems, that can lead to policy drift, unauthorised tool use, or continued execution under a truncated instruction set that no longer reflects the original intent.
Failure mechanism: The session summary becomes the only memory the model reliably uses, but the summariser omits a standing restriction, so later turns operate without the missing control state.
Impact: The agent may take actions outside its intended bounds, follow stale assumptions, or continue a workflow without the guardrails that were supposed to remain in force.
Standards & Framework Alignment
This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.
OWASP Agentic AI Top 10 addresses the attack and risk surface, while NIST AI RMF and NIST SP 800-53 Rev 5 set the governance and control requirements practitioners need to meet.
| Framework | Control / Reference | Relevance |
|---|---|---|
| OWASP Agentic AI Top 10 | ASI06 — Memory & Context Poisoning | Context compaction can alter agent memory and retained instructions. |
| Recommendation — Preserve critical instructions and state across summarisation to reduce memory poisoning risk. | ||
| NIST AI RMF | GOVERN — Govern | This term concerns governance over how AI systems retain and use context. |
| Recommendation — Define governance rules for what compaction must preserve and who approves changes to session memory. | ||
| NIST SP 800-53 Rev 5 | AC-6 — Least Privilege | Compaction can affect how much authority remains visible in an ongoing agent session. |
| AU-3 — Content of Audit Records | Compaction may remove or retain records needed to explain later actions. | |
| SI-4 — System Monitoring | Monitoring is needed to detect when summarisation drops important constraints or changes behaviour. | |
| Recommendation — Limit retained session authority to the minimum needed for the current task. Retain enough history to reconstruct why the agent acted. Monitor compacted sessions for policy drift and unexpected tool-use changes. | ||
Practitioner Guidance
Why practitioners should care: Compaction is a governance point, not just a performance trick. If your workflow relies on persistent instructions, ownership, or approval state, you need a deliberate rule for what must survive every summarisation pass.
What to watch for: Treat any summary that removes constraints, names, approvals, or tool permissions as suspect. The safest compaction output is one that makes the active obligations explicit, rather than assuming the model will reconstruct them from prior turns.
Practitioner takeaway: Design compaction so that it preserves security-relevant state first and compresses everything else second.
Related resources from NHI Mgmt Group
Deepen Your Knowledge
Free weekly newsletter
Subscribe to the NHI & AI Identity Journal
The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.
Bonus 33% off our NHI Course when you subscribe.
Reviewed and updated by the NHIMG editorial team on October 31, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org