compaction

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2026 License: MIT Imports: 11 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewPrune

func NewPrune(cfg PruneConfig) (compaction.Service, error)

NewPrune registers compaction/prune-tool-results: Trim verbose tool results without calling a model.

Best practices:

  • Cheap and lossless enough to run before compaction/summary in the same chain.

func NewSummary

func NewSummary(cfg SummaryConfig, deps SummaryDeps) (compaction.Service, error)

NewSummary registers compaction/summary: Replace older messages with an LLM-written summary.

func NewTokenLimit

func NewTokenLimit(cfg TokenLimitConfig, deps TokenLimitDeps) (compaction.Service, error)

NewTokenLimit registers compaction/token-limit: Trigger inner compaction services once the context crosses a token threshold.

Best practices:

  • A decorator, not a strategy: it decides when, the services dep decides how.
  • The estimate is max(character estimate, reported usage), so it errs toward compacting early.

Types

type PruneConfig

type PruneConfig struct {
	// MaxToolResultBytes is per-result truncation limit.
	MaxToolResultBytes int `json:"maxToolResultBytes"`
}

type SummaryConfig

type SummaryConfig struct {
	// MinMessages does nothing until the history reaches this many messages.
	MinMessages int `json:"minMessages"`
	// KeepRecent is trailing messages left verbatim; a forced compaction with fewer messages than this is a no-op.
	KeepRecent int `json:"keepRecent"`
	// SummaryModel is model used for the summary; defaults to the agent's model.
	SummaryModel string `json:"summaryModel"`
	// SummaryPrompt overrides the built-in summarisation instruction.
	SummaryPrompt string                  `json:"summaryPrompt"`
	Retry         *compaction.RetryConfig `json:"retry,omitempty"`
}

type SummaryDeps

type SummaryDeps struct {
	LLM agentkit.LLMProvider `json:"llm"`
}

type TokenLimitConfig

type TokenLimitConfig struct {
	// MaxTokens is absolute trigger; takes precedence over ContextWindow.
	MaxTokens int `json:"maxTokens"`
	// ContextWindow is model context size; the trigger becomes ContextWindow × TriggerRatio.
	ContextWindow int `json:"contextWindow"`
	// TriggerRatio is fraction of ContextWindow that trips compaction, default 0.7 — leaving room for the reply plus the next tool result.
	TriggerRatio float64 `json:"triggerRatio"`
	// CharsPerToken calibrates the fallback estimate used before the provider reports usage; default 4 (English prose), lower it for CJK.
	CharsPerToken int `json:"charsPerToken"`
}

type TokenLimitDeps

type TokenLimitDeps struct {
	// Services run only once the threshold is crossed, with Force set.
	Services []compaction.Service `json:"services"`
}

Jump to

Keyboard shortcuts

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