summary

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 4 Imported by: 0

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:

  1. Read offset and rolling summary from session.State() (if a session exists).
  2. Build a working view: [summaryMsg (if any)] + messages[offset:].
  3. 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.
  4. 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

func WithBatchSize(n int) Option

WithBatchSize sets the number of messages to summarize per compression pass. Defaults to 20.

func WithKeepRecent

func WithKeepRecent(n int) Option

WithKeepRecent sets the number of most-recent messages always kept verbatim. Defaults to 10.

func WithMaxTokens

func WithMaxTokens(tokens int64) Option

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).

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL