window

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 4, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTokenCounterRequired = errors.New("contextkit/window: Budget.MaxTokens needs Config.CountTokens")

ErrTokenCounterRequired reports a MaxTokens budget without CountTokens: guessing tokens from characters could overrun the model's window.

Functions

This section is empty.

Types

type Compressor

type Compressor struct {
	// contains filtered or unexported fields
}

Compressor keeps the newest whole turns that fit the budget and replaces everything older with one summary message. The budget covers system messages and the kept conversation, in characters, tokens, or both; the summary is not counted, and a Summarizer receives the budget to size it.

Compress is incremental: feed it its previous output plus the new messages and only the newly dropped messages are summarized, together with the previous summary, instead of the whole history again.

func New

func New(cfg Config) *Compressor

func (*Compressor) Compress

func (c *Compressor) Compress(ctx context.Context, req contextkit.Request) (*contextkit.Result, error)

type Config

type Config struct {
	Budget contextkit.Budget
	// Profile defaults to contextkit.ProfileFromEnv.
	Profile contextkit.Profile
	// MinRecent is the number of trailing messages always kept, even over
	// budget; at least 1. The kept window then extends back to the start of
	// its turn.
	MinRecent    int
	MaxToolChars int
	// CountTokens prices messages for Budget.MaxTokens and is called only when
	// that limit is set. It sees tool messages after projection and must count
	// a message's images.
	CountTokens contextkit.TokenCounter
	Summarizer  contextkit.Summarizer
}

Jump to

Keyboard shortcuts

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