Skip to content

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.

Pass context_manager="auto"contextManager: "auto" and the SDK manages context in the background:

from strands import Agent
agent = Agent(context_manager="auto")

The context_managercontextManager parameter is a first-class agent parameter, not a plugin. It creates a ContextManager 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 tool, registered by default.

When context_managercontextManager is set, any co-provided conversation_managerconversationManager is ignored. The ContextManager owns overflow recovery and proactive compression internally.

ValueBehavior
"auto"Background compression with tuned defaults. No model involvement.
"agentic"Model-driven: the model manages its own context.
Custom configFull control over the strategy pipeline, targets, and conditions.
falseNo context management. Overflow errors propagate directly.

See Built-in Modes for details on "auto" and "agentic". See Custom Strategies to build your own pipeline.

Stateful models. Stateful models manage conversation state server-side. Setting context_managercontextManager with a stateful model raises an error.

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.