Expand description
Conversation history management for ailoop.
Owns the message vector that drives every ChatRequest and
enforces the token-budget contract: ContextManager tracks the
running history, applies a CompactionStrategy when the wired
Tokenizer reports the budget is exceeded, and persists the pin
mask that keeps system-style anchors and live ToolCall ↔ ToolResult
pairs intact across compactions.
Most application code does not construct a ContextManager directly
— the ailoop façade wires one inside
Conversation with a sensible default
budget. Reach for this crate when you need a custom strategy
(SummarizeStrategy vs TruncateStrategy), a non-default
tokenizer (e.g. ailoop_anthropic::OnlineCalibratedTokenizer),
direct access to compact_if_needed from
advanced::run_chat, or your own
HistoryStore backend for persistence.
§Mini-index
ContextManager+ContextManagerBuilder— the history container and its configuration entry point.CompactionStrategy— trait implemented by reduction algorithms; ships withTruncateStrategyandSummarizeStrategy.CompactionOutput,CompactionReport,CompactionError,FromMessagesError— the surrounding vocabulary.HistoryStore— async persistence trait.InMemoryHistoryStoreandJsonFileHistoryStorecover tests and single-file durable storage; implement the trait for Redis, Postgres, etc.ConversationSnapshot— versioned wire format forHistoryStorepayloads. Validated at deserialize time so a malformed file fails loudly rather than panicking later.Tokenizer/CharTokenizer— re-exported fromailoop_coresoContextManagerBuilder::tokenizercallers can stay on this crate’s import surface.
Re-exports§
pub use compaction::CompactionOutput;pub use compaction::CompactionStrategy;pub use compaction::DEFAULT_SUMMARIZER_PROMPT;pub use compaction::SummarizeStrategy;pub use compaction::TruncateStrategy;pub use context_manager::CompactionReport;pub use context_manager::ContextManager;pub use context_manager::ContextManagerBuilder;pub use errors::CompactionError;pub use errors::FromMessagesError;pub use history_store::HistoryStore;pub use history_store::InMemoryHistoryStore;pub use history_store::JsonFileHistoryStore;pub use history_store::JsonFileHistoryStoreError;pub use snapshot::ConversationSnapshot;
Modules§
- compaction
CompactionStrategytrait and the two built-in implementations. SeeTruncateStrategy(drop the prefix) andSummarizeStrategy(replace the prefix with a model-generated summary).- context_
manager ContextManager+ContextManagerBuilder+ the report typecompact_if_neededreturns.- errors
- Failure surfaces of compaction and snapshot validation.
- history_
store HistoryStoretrait +InMemoryHistoryStore/JsonFileHistoryStorebackends.- snapshot
ConversationSnapshot— versioned wire format used byHistoryStorebackends.
Structs§
- Char
Tokenizer - Fallback
Tokenizerthat approximates tokens astext.len() / 4.
Traits§
- Tokenizer
- Counts tokens in text and full messages.