Skip to main content

Crate ailoop_context

Crate ailoop_context 

Source
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

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
CompactionStrategy trait and the two built-in implementations. See TruncateStrategy (drop the prefix) and SummarizeStrategy (replace the prefix with a model-generated summary).
context_manager
ContextManager + ContextManagerBuilder + the report type compact_if_needed returns.
errors
Failure surfaces of compaction and snapshot validation.
history_store
HistoryStore trait + InMemoryHistoryStore / JsonFileHistoryStore backends.
snapshot
ConversationSnapshot — versioned wire format used by HistoryStore backends.

Structs§

CharTokenizer
Fallback Tokenizer that approximates tokens as text.len() / 4.

Traits§

Tokenizer
Counts tokens in text and full messages.