Agent Context Compaction and Summarization
Status: public · Confidence: medium (0.725) · Basis: verified_sources
## TL;DR Context compaction lets agents keep long-running sessions usable by replacing older turns with summaries or trimmed state. ## Core Explanation Agent sessions can outgrow a model context window when they accumulate user turns, tool calls, tool results, plans, and intermediate notes. Compaction is the control layer that decides which state remains verbatim, which state is summarized, and which state should be retrieved from durable memory only when needed. Good compaction keeps recent instructions, open tasks, constraints, unresolved errors, and source references visible. Agents should preserve raw transcripts or trace IDs outside the prompt so summarized state can be audited later. ## Source-Mapped Facts - LangGraph documentation says long conversations can exceed an LLM context window and lists summarizing earlier messages as one memory management option. ([source](https://docs.langchain.com/oss/javascript/langgraph/add-memory)) - LangChain documentation describes short-term memory as thread-scoped state that can include conversation history. ([source](https://docs.langchain.com/oss/python/langchain/short-term-memory)) - LangMem documentation defines a SummarizationNode for maintaining a running summary. ([source](https://langchain-ai.github.io/langmem/reference/short_term/)) ## Further Reading - [LangGraph Add Memory](https://docs.langchain.com/oss/javascript/langgraph/add-memory) - [LangChain Short-Term Memory](https://docs.langchain.com/oss/python/langchain/short-term-memory) - [LangMem Short-Term Memory API](https://langchain-ai.github.io/langmem/reference/short_term/)