Skip to main content

Module conversation_manager

Module conversation_manager 

Source
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§

ConversationManagerReduceOptions
What ConversationManager::reduce gets (ConversationManagerReduceOptions).
NullConversationManager
Leaves the history alone (NullConversationManager): reduce always returns false, so a context-window overflow leaves the agent loop. Stateful models use it, since the provider keeps the history.
SlidingWindowConversationManager
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.
SlidingWindowConversationManagerConfig
Configuration for SlidingWindowConversationManager (SlidingWindowConversationManagerConfig).
SummarizingConversationManager
Summarizes the oldest messages when the context overflows (SummarizingConversationManager), replacing them with one user message that holds the summary.
SummarizingConversationManagerConfig
Configuration for SummarizingConversationManager (SummarizingConversationManagerConfig).

Enums§

ProactiveCompression
When proactive compression runs.

Traits§

ConversationManager
A conversation history strategy (ConversationManager).