Documentation
¶
Index ¶
- func EstimateTokens(text string) int
- type CompressionResult
- type CompressionStats
- type CompressionSummary
- type Config
- type LLMProvider
- type Manager
- func (m *Manager) AutoCompress(sessionID string, messages []Message) ([]Message, bool, error)
- func (m *Manager) Compress(level string) (*CompressionResult, error)
- func (m *Manager) CompressSession(sessionID string, messages []Message, preserveRecent int) (*CompressionSummary, []Message, error)
- func (m *Manager) CompressWithLLM(ctx context.Context, messages []Message, llmProvider LLMProvider) (*CompressionSummary, []Message, error)
- func (m *Manager) GetSession(sessionID string) *Session
- func (m *Manager) GetStats() *CompressionStats
- func (m *Manager) LoadSession(sessionID string) error
- func (m *Manager) Preview(level string) (*PreviewResult, error)
- func (m *Manager) SaveSession(session *Session) error
- type Message
- type PreviewResult
- type Session
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func EstimateTokens ¶
EstimateTokens estimates token count using a multi-strategy approach. Uses cl100k_base heuristic for better accuracy across languages.
Types ¶
type CompressionResult ¶
CompressionResult contains compression result information
type CompressionStats ¶
type CompressionStats struct {
TotalSessions int `json:"total_sessions"`
CompressedCount int `json:"compressed_count"`
TotalTokensSaved int `json:"total_tokens_saved"`
AvgCompression float64 `json:"avg_compression_ratio"`
}
CompressionStats provides compression statistics
type CompressionSummary ¶
type CompressionSummary struct {
OriginalCount int `json:"original_count"`
CompressedCount int `json:"compressed_count"`
TokensSaved int `json:"tokens_saved"`
Summary string `json:"summary"`
CompressedAt int64 `json:"compressed_at"`
}
CompressionSummary is a summary of compressed messages
type Config ¶
type Config struct {
Enabled bool `yaml:"enabled"`
MaxTokens int `yaml:"max_tokens"` // Max tokens before compression
TargetTokens int `yaml:"target_tokens"` // Target tokens after compression
MinMessages int `yaml:"min_messages"` // Min messages to keep in summary
PreserveRecent int `yaml:"preserve_recent"` // Keep recent N messages
}
Config holds compression configuration
type LLMProvider ¶
LLMProvider interface for LLM-based summarization
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager handles session compression
func NewManager ¶
NewManager creates a new compression manager
func (*Manager) AutoCompress ¶
AutoCompress automatically compresses if over limit
func (*Manager) Compress ¶
func (m *Manager) Compress(level string) (*CompressionResult, error)
Compress applies compression to active session
func (*Manager) CompressSession ¶
func (m *Manager) CompressSession(sessionID string, messages []Message, preserveRecent int) (*CompressionSummary, []Message, error)
CompressSession compresses a session to fit within token limit
func (*Manager) CompressWithLLM ¶
func (m *Manager) CompressWithLLM(ctx context.Context, messages []Message, llmProvider LLMProvider) (*CompressionSummary, []Message, error)
CompressWithLLM uses an LLM to generate a better summary
func (*Manager) GetSession ¶
GetSession returns a stored session
func (*Manager) GetStats ¶
func (m *Manager) GetStats() *CompressionStats
GetStats returns compression statistics
func (*Manager) LoadSession ¶
LoadSession loads a session from disk
func (*Manager) Preview ¶
func (m *Manager) Preview(level string) (*PreviewResult, error)
Preview shows compression preview without applying changes
func (*Manager) SaveSession ¶
SaveSession saves a session to disk
type Message ¶
type Message struct {
Role string `json:"role"`
Content string `json:"content"`
Timestamp int64 `json:"timestamp"`
Tokens int `json:"tokens,omitempty"`
}
Message represents a chat message
type PreviewResult ¶
type PreviewResult struct {
CurrentMessages int
AfterMessages int
TokensSaved int
TokenReduction float64
CostSavings float64
}
PreviewResult contains compression preview information
type Session ¶
type Session struct {
ID string `json:"id"`
Messages []Message `json:"messages"`
Summary *CompressionSummary `json:"compression_summary,omitempty"`
}
Session represents a chat session