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 provides several layers of context management that you can use independently or together.
Automatic context management
Section titled “Automatic context management”For most agents with multi-turn conversations, you don’t need to configure conversation management and context offloading separately. Pass context_manager="auto" (Python) or contextManager: "auto" (TypeScript) and the SDK wires up both with tuned defaults:
from strands import Agent
agent = Agent(context_manager="auto")import { Agent } from '@strands-agents/sdk'
const agent = new Agent({ contextManager: 'auto',})What it sets up
Section titled “What it sets up”This composes two components whose defaults scored highest across ContextBench evaluations relative to other Strands Agent configurations:
- SummarizingConversationManager (summary ratio of 0.3, compression threshold of 0.85): proactively summarizes older messages before the context window fills, preserving key information while freeing space for new turns.
- ContextOffloader plugin (max result tokens of 1,500, preview tokens of 750): intercepts large tool results at execution time, stores them externally, and keeps a truncated preview in context. Registers a
retrieve_offloaded_contenttool so the agent can fetch full content on demand.
For full details on each component, see Conversation Management and Context Offloader.
Combining with explicit configuration
Section titled “Combining with explicit configuration”Your own settings take precedence when you need fine-grained control:
- Custom conversation manager: If you also pass
conversation_manager/conversationManager, your manager replaces the auto-composedSummarizingConversationManager. The SDK still adds theContextOffloaderplugin. - Existing ContextOffloader: If your
pluginslist already contains aContextOffloaderinstance, no duplicate is added. Your configuration is preserved.
from strands import Agentfrom strands.agent.conversation_manager import ( SlidingWindowConversationManager,)
# Your conversation manager is used;# ContextOffloader is still added automaticallyagent = Agent( context_manager="auto", conversation_manager=SlidingWindowConversationManager( window_size=30, ),)import { Agent, SlidingWindowConversationManager,} from '@strands-agents/sdk'
// Your conversation manager is used;// ContextOffloader is still added automaticallyconst agent = new Agent({ contextManager: 'auto', conversationManager: new SlidingWindowConversationManager({ windowSize: 30, }),})Limitations
Section titled “Limitations”Stateful models: Stateful models manage conversation state server-side. Setting context_manager="auto" with a stateful model raises a ValueError (Python) or Error (TypeScript).
The auto-composed offloader uses in-memory storage that does not persist across process restarts. If your agent uses session management and needs durable offloaded content, configure an explicit ContextOffloader with FileStorage or S3Storage. See Storage Backends.