Context Management
As conversations grow, your agent’s context window fills with messages, tool results, and system prompts. Without management, this leads to token limit errors, degraded performance, and loss of relevant information.
The SDK ships context management that works out of the box. Pick a mode and the SDK wires up an ordered strategy pipeline with tuned defaults.
Quick start
Section titled “Quick start”Pass
context_manager="auto"contextManager: "auto"
from strands import Agent
agent = Agent(context_manager="auto")import { Agent } from '@strands-agents/sdk'
const agent = new Agent({ contextManager: 'auto',})How it works
Section titled “How it works”The
context_managercontextManagerContextManager that owns all
context reduction for the agent.
The ContextManager runs strategies as an ordered pipeline. Each strategy sees the output of the previous one. The SDK always appends an emergency truncation strategy as the final step, which only fires when the window is still overflowing after all other strategies have run.
A stash stores all message content on arrival as JSON,
before any strategy acts. Truncated or summarized content
is preserved and retrievable on demand through the
retrieve_contextretrieve_context
When
context_managercontextManagerconversation_managerconversationManager
Choosing a mode
Section titled “Choosing a mode”| Value | Behavior |
|---|---|
"auto" | Background compression with tuned defaults. No model involvement. |
"agentic" | Model-driven: the model manages its own context. |
| Custom config | Full control over the strategy pipeline, targets, and conditions. |
false | No context management. Overflow errors propagate directly. |
See Built-in Modes
for details on "auto" and "agentic".
See Custom Strategies
to build your own pipeline.
Limitations
Section titled “Limitations”Stateful models. Stateful models manage conversation
state server-side. Setting
context_managercontextManager
In-memory stash. The stash uses in-memory storage by default, which does not persist across process restarts. Configure a durable storage backend when using session management. See Custom Strategies.