compaction

package
v1.39.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//go:embed prompts/compaction-system.txt
	SystemPrompt string

	//go:embed prompts/compaction-user.txt
	UserPrompt string
)

Functions

func EstimateMessageTokens

func EstimateMessageTokens(msg *chat.Message) int64

EstimateMessageTokens returns a rough token-count estimate for a single chat message based on its text length. This is intentionally conservative (overestimates) so that proactive compaction fires before we hit the limit.

The estimate accounts for message content, multi-content text parts, reasoning content, tool call arguments, and a small per-message overhead for role/metadata tokens.

func ShouldCompact

func ShouldCompact(inputTokens, outputTokens, addedTokens, contextLimit int64) bool

ShouldCompact reports whether a session's context usage has crossed the compaction threshold. It returns true when the total token count (input + output + addedTokens) exceeds [contextThreshold] (90%) of contextLimit.

Types

This section is empty.

Jump to

Keyboard shortcuts

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