shrink

package
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jul 4, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package shrink compresses LLM tool descriptions before they are sent to the provider. It implements the tool-description shrink pattern GrayCode tool-description shrink pipeline:

  1. For each tool description, apply the shrink rules: - drop articles ("a", "an", "the") - drop filler words ("just", "really", "basically") - drop pleasantries - dictionary substitutions ("in order to" -> "to")
  2. Skip descriptions that mention security/destructive keywords (auto-clarity: preserve verbatim).
  3. Cap the result to a max length (default 200 chars).
  4. Report aggregate bytes/tokens saved across all tools.

The shrink is applied to descriptions only; tool names and schemas are passed through unchanged so the LLM can still invoke the tool correctly.

This is a low-level utility. Callers (typically the eyrie client) call ShrinkTools() on a []*types.Tool before passing them to the provider. Original tools are not modified.

Index

Constants

View Source
const MaxLen = 200

MaxLen is the default cap on a single description length.

Variables

This section is empty.

Functions

func ShrinkDescription

func ShrinkDescription(desc string) (string, bool)

ShrinkDescription returns the shrunk version of desc. Returns (desc, false) if desc contains safety keywords (caller should keep the original verbatim).

Types

type Result

type Result struct {
	OriginalBytes   int
	CompressedBytes int
	BytesSaved      int
	PercentOff      float64
	ToolsProcessed  int
	ToolsSkipped    int // skipped due to security/destructive keywords
}

Result reports per-call savings.

func ShrinkTools

func ShrinkTools(tools []types.Tool) ([]types.Tool, Result)

ShrinkTools returns a new slice with each tool's description shrunk. Original tools are not modified. The Result reports aggregate savings.

func ShrinkToolsIf

func ShrinkToolsIf(tools []types.Tool, enabled bool) ([]types.Tool, Result)

ShrinkToolsIf returns ShrinkTools result only if enabled is true. Convenience for callers that have a config flag.

Jump to

Keyboard shortcuts

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