history
History manager — orchestrates context window management across tiers.
The [HistoryManager] is the main integration point. It:
- Applies a [
ContextStrategy] to trim history within budget - Optionally injects long-term memories from a [
LongTermMemory] backend - Optionally summarizes evicted messages via a [
Summarizer] - Tracks token usage and provides diagnostics
Type Aliases
Section titled “Type Aliases”SummarizerFuture
Section titled “SummarizerFuture”type SummarizerFuture = Pin<Box<dyn Future + Send>>;Traits
Section titled “Traits”Summarizer
Section titled “Summarizer”Trait for summarizing evicted conversation messages.
Implementations can use an LLM or extractive methods to compress a sequence of messages into a concise summary.
Required / Provided Methods
fn summarize(&self, messages: &[serde_json::Value]) -> SummarizerFutureSummarize the given messages into a single text string.
Structs
Section titled “Structs”ExtractiveSnippets
Section titled “ExtractiveSnippets”Extractive summarizer — no LLM calls, just extracts key content.
Takes the first and last user messages plus any tool results, joining them into a brief “Previously:” block.
Fields
| Field | Type | Description |
|---|---|---|
max_chars | usize | Maximum character length of the summary. |
HistoryManagerConfig
Section titled “HistoryManagerConfig”Configuration for the [HistoryManager].
Fields
| Field | Type | Description |
|---|---|---|
strategy | ContextStrategyKind | Which strategy to use for trimming history. |
enable_summarization | bool | Whether to generate summaries of evicted messages. |
enable_long_term_memory | bool | Whether to query long-term memory for relevant context. |
recall_top_k | usize | Number of long-term memories to inject per turn. |
memory_token_budget | u32 | Maximum tokens to allocate for injected long-term memories. |
HistoryManager
Section titled “HistoryManager”Central manager for LLM context window management.
Call prepare_messages before each LLM invocation
to get a trimmed, budget-aware message list. Call
on_turn_complete after each turn to update
summaries and store memories.
Methods
fn new(config: HistoryManagerConfig) -> SelfCreate a new HistoryManager with the given configuration.
with_summarizer
Section titled “with_summarizer”fn with_summarizer(self, summarizer: Arc<dyn Summarizer>) -> SelfSet the summarizer implementation.
with_memory
Section titled “with_memory”fn with_memory(self, memory: Arc<dyn LongTermMemory>) -> SelfSet the long-term memory backend.
with_summaries
Section titled “with_summaries”fn with_summaries(self, summaries: Vec<String>) -> SelfSeed the manager with previously persisted conversation summaries.
prepare_messages
Section titled “prepare_messages”async fn prepare_messages(&self, budget: &ContextBudget, system_message: Option<&str>, history: &[serde_json::Value], current_turn: &[serde_json::Value], memory_filters: &MemoryFilters) -> Vec<serde_json::Value>Prepare messages for the next LLM invocation.
This is the main entry point. It:
- Optionally retrieves relevant long-term memories
- Constructs the system message (with memories + summaries)
- Applies the context strategy to trim history within budget
Returns the message list ready to be sent to the LLM.
on_turn_complete
Section titled “on_turn_complete”async fn on_turn_complete(&mut self, evicted_messages: &[serde_json::Value], agent_id: &str, user_id: Option<&str>, conversation_id: Option<&str>)Notify the manager that a turn has completed.
If summarization is enabled, this may generate a summary of evicted messages and optionally store it in long-term memory.
summaries
Section titled “summaries”fn summaries(&self) -> &[String]Get accumulated summaries (for diagnostics).
strategy_name
Section titled “strategy_name”fn strategy_name(&self) -> &''static strGet the strategy name (for diagnostics).