Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func NewContextCompressor ¶
func NewContextCompressor(model blades.ModelProvider, opts ...Option) blades.ContextCompressor
NewContextCompressor returns a ContextCompressor that compresses old messages using the provided ModelProvider when the token count exceeds the configured limit. Recent messages are always kept verbatim.
When a Session is present in the context, compression state (rolling summary text and compressed message offset) is persisted across runs via session.State(). This avoids re-processing already-summarised messages on every invocation.
Compression proceeds as follows:
- Read offset and rolling summary from session.State() (if a session exists).
- Build a working view: [summaryMsg (if any)] + messages[offset:].
- If total tokens exceed MaxTokens, take the next BatchSize messages after the current offset, extend the rolling summary with them, and advance the offset. Repeat until under budget or no more messages can be compressed.
- Persist the updated offset and summary content back to session.State().
Types ¶
type Option ¶
type Option func(*contextCompressor)
Option configures a summary ContextCompressor.
func WithBatchSize ¶
WithBatchSize sets the number of messages to summarize per compression pass. Defaults to 20.
func WithKeepRecent ¶
WithKeepRecent sets the number of most-recent messages always kept verbatim. Defaults to 10.
func WithMaxTokens ¶
WithMaxTokens sets the token budget that triggers compression. A value of 0 disables compression (no-op).
func WithTokenCounter ¶
func WithTokenCounter(counter blades.TokenCounter) Option
WithTokenCounter sets the TokenCounter used to estimate token usage. Defaults to a character-based counter (1 token ≈ 4 chars).