contextlimit

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2026 License: AGPL-3.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const StepToolResultTruncateBytes = 512

StepToolResultTruncateBytes is the content-size threshold above which an old tool-result message is replaced with a byte-count summary during step-level / mid-task pruning.

Variables

View Source
var (
	// PruneTier matches internal/agent/tools' pre-unification tool-output
	// pruning (exec stdout/stderr, etc.): the same head/tail split contextlimit
	// itself already defaults to.
	PruneTier = Tier{
		MaxBytes:  textprune.DefaultMaxBytes,
		MaxLines:  textprune.DefaultMaxLines,
		HeadBytes: toolOutputHeadBytes,
		TailBytes: toolOutputTailBytes,
		HeadLines: toolOutputHeadLines,
		TailLines: toolOutputTailLines,
		Marker:    textprune.DefaultMarker,
	}

	// GatewayResultTier matches internal/conversation/flow's gateway prune for
	// tool-result content.
	GatewayResultTier = Tier{
		MaxBytes:  textprune.DefaultMaxBytes,
		MaxLines:  textprune.DefaultMaxLines,
		HeadBytes: 6 * 1024,
		TailBytes: 2 * 1024,
		HeadLines: 180,
		TailLines: 50,
		Marker:    textprune.DefaultMarker,
	}

	// GatewayArgsTier matches internal/conversation/flow's gateway prune for
	// tool-call arguments.
	GatewayArgsTier = Tier{
		MaxBytes:  textprune.DefaultMaxBytes,
		MaxLines:  textprune.DefaultMaxLines,
		HeadBytes: 4 * 1024,
		TailBytes: 2 * 1024,
		HeadLines: 180,
		TailLines: 50,
		Marker:    textprune.DefaultMarker,
	}
)

Functions

func EncodedExceeds

func EncodedExceeds(value any, limit ToolOutputLimit) bool

func LimitError

func LimitError(err error, label string, limit ToolOutputLimit) error

func LimitString

func LimitString(text, label string, limit ToolOutputLimit) string

func LimitToolOutput

func LimitToolOutput(output any, label string, limit ToolOutputLimit) any

func MarshalString

func MarshalString(value any) string

func TruncateStepToolResult

func TruncateStepToolResult(msg sdk.Message, thresholdBytes int) (out sdk.Message, ok bool)

TruncateStepToolResult replaces each sdk.ToolResultPart in msg whose own encoded size exceeds thresholdBytes (falling back to StepToolResultTruncateBytes when thresholdBytes <= 0) with a "[tool result pruned: N bytes]" summary. Parallel-call batches share one tool message, so sizing is per part: small siblings survive verbatim, and every other field of the part — IsError above all — is preserved so a failed result never reads as success. ok reports whether msg was changed.

Types

type Tier

type Tier struct {
	MaxBytes  int
	MaxLines  int
	HeadBytes int
	TailBytes int
	HeadLines int
	TailLines int
	Marker    string
}

Tier is a named layered truncation policy: MaxBytes/MaxLines are the outer ceiling that decides whether truncation engages at all; HeadBytes/TailBytes and HeadLines/TailLines are the retained head/tail split once it does.

func (Tier) LimitString

func (t Tier) LimitString(s, label string) string

LimitString truncates s to this tier's head/tail budget, UTF-8 safely, once s exceeds the tier's ceiling.

type ToolOutputLimit

type ToolOutputLimit struct {
	MaxBytes int
	MaxLines int
}

func NormalizedLimit

func NormalizedLimit(limit ToolOutputLimit) ToolOutputLimit

Jump to

Keyboard shortcuts

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