Expand description
Conversation history management.
A ConversationManager keeps the history within the model’s context window. When the model
reports a ContextWindowOverflowError, the agent calls ConversationManager::reduce with
the error and retries the call if the history was reduced; when the error persists it leaves
the agent loop. With proactive compression enabled, the agent also calls reduce (without an
error) before a model call whose projected input exceeds the threshold.
The built-in managers are SlidingWindowConversationManager (the default, 40 messages),
SummarizingConversationManager and NullConversationManager.
use strands::Agent;
use strands::conversation_manager::{SlidingWindowConversationManager, SlidingWindowConversationManagerConfig};
use strands::testing::MockModel;
let manager = SlidingWindowConversationManager::new(SlidingWindowConversationManagerConfig {
window_size: Some(20),
..Default::default()
})?;
let agent = Agent::builder()
.model(MockModel::new())
.conversation_manager(manager)
.printer(false)
.build()?;Structs§
- Conversation
Manager Reduce Options - What
ConversationManager::reducegets (ConversationManagerReduceOptions). - Null
Conversation Manager - Leaves the history alone (
NullConversationManager):reducealways returnsfalse, so a context-window overflow leaves the agent loop. Stateful models use it, since the provider keeps the history. - Sliding
Window Conversation Manager - Keeps the most recent messages (
SlidingWindowConversationManager): after every invocation it trims history to the window, and on a context-window overflow it truncates the oldest large tool result or trims the oldest messages. Trimming never starts history on a tool result or separates a tool use from its result. - Sliding
Window Conversation Manager Config - Configuration for
SlidingWindowConversationManager(SlidingWindowConversationManagerConfig). - Summarizing
Conversation Manager - Summarizes the oldest messages when the context overflows (
SummarizingConversationManager), replacing them with one user message that holds the summary. - Summarizing
Conversation Manager Config - Configuration for
SummarizingConversationManager(SummarizingConversationManagerConfig).
Enums§
- Proactive
Compression - When proactive compression runs.
Traits§
- Conversation
Manager - A conversation history strategy (
ConversationManager).