Expand description
Context compression for conversation history.
This module implements intelligent compression of conversation history to reduce token usage while preserving important information.
§Module Structure
- config: Compression configuration and bias settings
- types: Compression strategy, result, and segment types
- compressor: AI compressor and compression functions
Structs§
- AiCompressor
- AI-based compressor using a Provider.
- Compression
Bias - Compression bias - controls what to prioritize during compression.
- Compression
Config - Configuration for context compression.
- Compression
History Entry - Compression history entry for session metadata.
- Compression
Result - Result of a compression operation.
- Summarized
Segment - A segment of conversation history that has been summarized.
Enums§
- Compression
Strategy - Strategy for compressing conversation history.
Constants§
- DEFAULT_
COMPRESSION_ THRESHOLD - Compression trigger threshold (percentage of context window). Lowered to 0.5 to compress earlier for long conversations (128K context -> 64K threshold)
- DEFAULT_
COMPRESSOR_ MODEL - Default model for summarization.
- DEFAULT_
TARGET_ RATIO - Target ratio after compression (keep this fraction of tokens).
- MIN_
MESSAGES_ TO_ KEEP - Minimum messages to keep after compression. Increased to preserve more recent context for continuity
Traits§
- Compressor
- Compressor trait for different implementations.
Functions§
- build_
summary_ prompt - Build a prompt for summarization.
- compress_
messages - Compress messages synchronously.
- compress_
with_ bias - Compress with bias-based scoring.
- estimate_
tokens - Estimate token count for a message.
- estimate_
total_ tokens - Estimate total tokens for a message list.
- format_
tokens - Format token count for display.
- should_
compress - Check if compression should be triggered.