Skip to content

history

History manager — orchestrates context window management across tiers.

The [HistoryManager] is the main integration point. It:

  1. Applies a [ContextStrategy] to trim history within budget
  2. Optionally injects long-term memories from a [LongTermMemory] backend
  3. Optionally summarizes evicted messages via a [Summarizer]
  4. Tracks token usage and provides diagnostics
type SummarizerFuture = Pin<Box<dyn Future + Send>>;

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]) -> SummarizerFuture

Summarize the given messages into a single text string.

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

FieldTypeDescription
max_charsusizeMaximum character length of the summary.

Configuration for the [HistoryManager].

Fields

FieldTypeDescription
strategyContextStrategyKindWhich strategy to use for trimming history.
enable_summarizationboolWhether to generate summaries of evicted messages.
enable_long_term_memoryboolWhether to query long-term memory for relevant context.
recall_top_kusizeNumber of long-term memories to inject per turn.
memory_token_budgetu32Maximum tokens to allocate for injected long-term memories.

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) -> Self

Create a new HistoryManager with the given configuration.

fn with_summarizer(self, summarizer: Arc<dyn Summarizer>) -> Self

Set the summarizer implementation.

fn with_memory(self, memory: Arc<dyn LongTermMemory>) -> Self

Set the long-term memory backend.

fn with_summaries(self, summaries: Vec<String>) -> Self

Seed the manager with previously persisted conversation summaries.

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:

  1. Optionally retrieves relevant long-term memories
  2. Constructs the system message (with memories + summaries)
  3. Applies the context strategy to trim history within budget

Returns the message list ready to be sent to the LLM.

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.

fn summaries(&self) -> &[String]

Get accumulated summaries (for diagnostics).

fn strategy_name(&self) -> &''static str

Get the strategy name (for diagnostics).