Skip to main content

Module compress

Module compress 

Source
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
  • phase_detector: Conversation phase detection
  • dependency: Message dependency tracking
  • semantic: Semantic compression using AI summarization
  • priority: Dynamic priority scoring for messages
  • cache: Compression cache for performance optimization
  • focus_point: AI-driven focus point management
  • focus_extractor: AI-based focus extraction and classification
  • focus_manager: Focus tracking and relevance calculation
  • coherence: Semantic coherence detection
  • progressive: Progressive compression strategy
  • complexity: Complexity analysis for adaptive compression
  • hierarchical: Hierarchical summarization strategies

Structs§

AiCompressor
AI-based compressor using a Provider.
CacheConfig
Compression cache configuration.
CacheEntry
Cache entry for a compressed message.
CacheStats
Statistics for the compression cache.
CachedComplexity
Cached complexity level
CachedFocusPrediction
Cached focus prediction
CachedPriorityScore
Cached priority score with validity tracking
CircuitBreakerState
State for circuit breaker to prevent infinite retry loops.
ClassificationResult
分类结果
CoherenceDetector
Coherence detector for conversation segments.
ComplexityAnalyzer
Analyzes conversation complexity
ComplexityConfig
Complexity analyzer configuration
CompressionBias
Compression bias - controls what to prioritize during compression.
CompressionCache
Compression cache implementation.
CompressionConfig
Configuration for context compression.
CompressionHistoryEntry
Compression history entry for session metadata.
CompressionOutcome
Result of compression with metadata.
CompressionPipeline
Compression pipeline that orchestrates all modules.
CompressionResult
Result of a compression operation.
CompressionThresholds
Thresholds for content compression.
ConversationFocus
Represents the current focus of the conversation.
ConversationSummary
Summary of a conversation segment.
DependencyBuilder
Builder for dependency graphs.
DependencyGraph
Graph of message dependencies for preserving conversation coherence.
ExtendedCacheConfig
扩展缓存配置
ExtendedCacheStats
扩展缓存统计
ExtendedCompressionCache
扩展压缩缓存:支持多种类型的缓存
FocusConfig
聚焦点配置
FocusExtractor
AI 聚焦点提取器
FocusFeedback
焦点反馈记录
FocusManager
聚焦点管理器
FocusPoint
聚焦点 - 由 AI 动态提取的核心关注点
FocusTracker
Focus tracker that monitors conversation flow.
FocusTrackerConfig
Focus tracker configuration
HardcodeConfig
Unified configuration for all hardcoded values in compression system.
HierarchicalConfig
Hierarchical summarizer configuration
HierarchicalSummarizer
Hierarchical summarizer
IntegratedLongContextProcessor
Integrated long context processor that orchestrates all modules.
Issue
Record of an issue and its resolution.
KeyInfo
Key information extracted from a message.
MessageDependency
Dependency relationship between ToolUse and ToolResult.
MessageRange
消息范围
OptimizedCompressor
Optimized compressor with all enhancements including focus tracking.
PhaseDetector
Detector for conversation phase.
PhaseWeights
Weight configuration for scoring based on conversation phase.
PriorityFactors
Factors that contribute to message priority.
PriorityScore
Priority score for a message (0.0 to 1.0).
PriorityScorer
Dynamic priority scorer.
PriorityWeights
Weights for different priority factors.
ProcessedResult
Result of processing long context.
ProcessorConfig
Configuration for the integrated processor.
ProgressiveCompressor
Progressive compression controller.
ProgressiveConfig
Configuration for progressive compression.
ScoredMessage
Message with its preservation score.
Scorer
Scorer for message preservation decisions.
SemanticCompressor
Semantic compressor that uses AI to summarize messages.
SummarizedSegment
A segment of conversation history that has been summarized.
Summarizer
Summarizer for large content.
ToolCompressor
Compressor for tool results.
ToolUsage
Record of tool usage in a conversation.
TopicTransition
Records when the conversation topic changed.

Enums§

AiCompressionMode
Mode for AI-assisted compression.
ComplexityLevel
Conversation complexity level
CompressionStage
Progressive compression stages.
CompressionStrategy
Strategy for compressing conversation history.
ConversationPhase
Conversation phase detected from message history. Determines which weights to apply during scoring.
FocusFeedbackType
焦点反馈类型
FocusStatus
聚焦点状态
FocusType
焦点类型分类
KeywordType
Keyword type for custom keyword additions (legacy compatibility).
SemanticStrategy
Strategy for semantic compression.
SummaryLevel
Summarization level
ThresholdLevel
Threshold level for compression warnings.
ValidationError
Validation errors for compression.

Constants§

AUTOCOMPACT_BUFFER_TOKENS
Token buffers for threshold levels (from Claude Code).
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).
ERROR_THRESHOLD_BUFFER_TOKENS
MANUAL_COMPACT_BUFFER_TOKENS
MAX_CONSECUTIVE_FAILURES
Maximum consecutive compression failures before stopping retries. Claude Code: “1,279 sessions had 50+ consecutive failures, wasting ~250K API calls/day”
MIN_MESSAGES_TO_KEEP
Minimum messages to keep after compression. Increased to preserve more recent context for continuity
TIME_BASED_MC_CLEARED_MESSAGE
Message to replace cleared tool result content (from Claude Code).
TIME_BASED_MC_GAP_THRESHOLD_MINUTES
Time-based microcompact threshold (minutes since last assistant message). When gap exceeds this, server cache has expired - clear old tool results.
WARNING_THRESHOLD_BUFFER_TOKENS

Traits§

Compressor
Compressor trait for different implementations.

Functions§

build_summary_prompt
Build a prompt for summarization.
compress_messages
Compress messages synchronously.
compress_messages_with_ai
Compress messages with AI assistance (async version).
compress_messages_with_full_ai
Compress messages with full AI support (async version).
compress_with_bias
Compress with bias-based scoring.
compress_with_pipeline
Legacy compression function (backward compatible).
estimate_tokens
Count tokens for a message using tiktoken (accurate).
estimate_total_tokens
Estimate total tokens for a message list.
example_optimized_compression
Example usage showing all optimizations with focus tracking.
format_tokens
Format token count for display.
score_by_rules
Rule-based scoring for a message (public for pipeline use).
score_messages_only
Score messages without compressing (analysis only).
should_compress
Check if compression should be triggered.