lc_memory/context_window/mod.rs
1// lc-memory/src/context_window/mod.rs
2//! Context Window for long context management.
3//!
4//! Manages conversation context by fitting messages within a token limit,
5//! using either truncation or LLM-based summarization strategies.
6//!
7//! # Core Concepts
8//!
9//! - **ContextWindow**: Fits messages within a max token budget.
10//! - **Strategy::Truncate**: Drops oldest messages, preserving system messages.
11//! - **Strategy::Summarize**: Uses an LLM to compress old messages into a summary.
12//!
13//! # Example
14//!
15//! ```ignore
16//! use lc_memory::{ContextWindow, Strategy};
17//! use lc_core::token_counter::TiktokenCounter;
18//!
19//! // Truncation strategy
20//! let cw = ContextWindow::new(4096);
21//! let fitted = cw.fit(messages).await?;
22//!
23//! // Summarization strategy
24//! let cw = ContextWindow::with_strategy(4096, Strategy::summarize(llm));
25//! let fitted = cw.fit(messages).await?;
26//! ```
27
28pub mod manager;
29pub mod trimmer;
30
31pub use manager::ContextWindow;
32pub use trimmer::Strategy;
33
34#[cfg(test)]
35mod tests;