compact

package
v0.1.1-alpha Latest Latest
Warning

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

Go to latest
Published: Apr 24, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Compactor

type Compactor struct {
	sleipnir.BaseMiddleware
	// contains filtered or unexported fields
}

Compactor is a ContextRewriter that summarizes old messages when the context window exceeds the threshold. It skips sub-agents (they have isolated histories).

func NewCompactor

func NewCompactor(cfg Config) *Compactor

NewCompactor constructs a Compactor with the given Config.

func (*Compactor) RewriteBeforeLLMCall

func (c *Compactor) RewriteBeforeLLMCall(ctx context.Context, req *sleipnir.LLMRequest) error

RewriteBeforeLLMCall compacts the message history when the estimated token count exceeds the configured threshold. Sub-agent contexts are skipped.

type Config

type Config struct {
	// Provider to use for summarization. Typically a cheap/fast model.
	Provider anyllm.Provider
	Model    string
	// Threshold fraction of estimated context window at which to compact.
	// 0 → defaults to 0.75.
	Threshold float64
	// ContextWindow is the estimated total context size in tokens. Default: 100_000.
	ContextWindow int
}

Config configures the Compactor middleware.

Jump to

Keyboard shortcuts

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