Context Compaction: How AI Agents Survive Long Sessions
Compaction strategies — summarization, eviction, and offloading — let agents work past their context limits productively.
28 min · Reviewed 2026
The premise
Long-running AI agents inevitably outgrow their context window. Compaction strategies — recursive summarization, episodic eviction, file-based offload — keep them productive past the wall.
What AI does well here
Recursively summarize older turns to preserve narrative
Evict tool-call noise while preserving outcomes and decisions
Offload artifacts to files and re-load by reference
What AI cannot do
Avoid losing some information at every compaction step
Substitute for genuine long-context model capability
Recover details the agent never explicitly recorded
End-of-lesson check
15 questions · take it digitally for instant feedback at tendril.neural-forge.io/learn/quiz/end-foundations-context-compaction-r7a4-creators
What inherently happens to information each time an AI agent performs context compaction?
Compaction removes only redundant information and leaves no gaps in memory
The agent gains additional storage capacity by converting data to a new format
All previous conversation history remains perfectly intact and accessible
Some information is inevitably lost during the compaction process
In the context of agent memory, what does the term 'eviction' specifically refer to?
Deleting all user messages from the conversation history
Relocating stored memories to a different physical server
Removing tool-call noise while keeping the outcomes and decisions that resulted from those calls
Forcing the agent to forget its original system instructions
Before an agent performs compaction on a long conversation, what three categories of information should it explicitly classify as must-survive?
Previous compaction dates, memory locations, and processing times
All tool definitions, API keys, and system prompts
User preferences, conversation topics, and emotional tone
Current goal, key constraints, and recent error context
What does 'file-based offload' enable an AI agent to do?
Compile code into a standalone executable program
Store artifacts in external files and retrieve them by reference rather than keeping them in active memory
Delete all files on the user's computer to free up space
Transfer conversation history to a different AI agent for processing
Why is it recommended that agents make compaction visible to users rather than performing it silently?
To prevent users from asking too many follow-up questions
Because visible compaction improves the agent's processing speed
To comply with legal requirements around AI transparency
So users can identify if important information was lost and provide corrections
What capability can true long-context models provide that compaction strategies cannot substitute for?
Built-in fact-checking for all historical statements
The ability to run without any internet connection
Faster response times than standard context models
Genuine access to all information without any summarization loss
What aspect of a conversation does recursive summarization primarily aim to preserve?
All emotional expressions and their intensity levels
The exact timestamps of all interactions
Every single word spoken by every participant
The narrative flow and key story elements across the conversation
What happens when an AI agent 'forgets' an earlier instruction that a user provided?
The agent switches to a different personality to compensate
The conversation is automatically terminated for security reasons
The agent automatically asks the user to repeat the instruction
Users typically feel betrayed because they expect the agent to remember everything
An agent is having a 3-hour conversation with a user. What problem will it eventually face without compaction strategies?
It will begin generating responses in a different language
It will automatically terminate the conversation to protect itself
Its responses will become permanently slower regardless of hardware
It will exceed its context window limit and be unable to process new inputs
What type of details cannot be recovered by an AI agent, even with advanced compaction techniques?
Data that exceeds one megabyte in size
Conversations that occurred in a different session
Details that the agent never explicitly recorded in the first place
Information that was deleted more than 24 hours ago
Which of the following is NOT a compaction strategy mentioned in the content?
Recursive summarization
File-based offload
Episodic eviction
Recursive encryption of conversation history
What is the primary purpose of building a compaction prompt around the must-survive classification?
To make the user feel more confident about the agent's abilities
To ensure critical information is explicitly preserved during the compression process
To allow the agent to ignore user instructions
To speed up the overall compaction operation
In the eviction strategy, what specifically gets removed while outcomes are preserved?
All punctuation and formatting from messages
The user's original query text
Tool-call noise, meaning the technical details of how tools were executed
User authentication credentials
If an AI agent uses compaction perfectly but still produces incorrect results, what fundamental limitation is at play?
Compaction was never actually performed correctly
The agent is deliberately trying to produce wrong answers
The user did not provide enough initial information
Compaction inherently loses some information, which may include details needed for accuracy
What distinguishes file-based offload from simple deletion of information?
Offload preserves the information and allows it to be retrieved by reference later
Offload automatically optimizes the file size for faster processing
Offload permanently destroys the information after a set time period
Offload converts text to audio format for accessibility