Documentation
¶
Overview ¶
Package promptcompression shrinks the request prompt before it reaches the model: standalone and fenced JSON is minified, ANSI escape sequences are stripped, and redundant whitespace is collapsed. All transforms are deterministic, so repeated turns re-compress history to identical bytes and provider prompt-cache prefixes remain stable. The plugin always fails open: any decode, transform, or encode problem passes the original request through untouched.
Index ¶
- Constants
- Variables
- type Data
- type Plugin
- func (p *Plugin) Execute(ctx context.Context, in appplugins.ExecInput) (*appplugins.Result, error)
- func (p *Plugin) MandatoryStages() []policy.Stage
- func (p *Plugin) MutatesMetadata() bool
- func (p *Plugin) MutatesRequestBody() bool
- func (p *Plugin) MutatesResponseBody() bool
- func (p *Plugin) Name() string
- func (p *Plugin) SupportedModes() []policy.Mode
- func (p *Plugin) SupportedProtocols() []appplugins.Protocol
- func (p *Plugin) SupportedStages() []policy.Stage
- func (p *Plugin) ValidateConfig(settings map[string]any) error
- type Settings
Constants ¶
const PluginName = "prompt_compression"
Variables ¶
var ( ErrNoTransforms = errors.New("prompt_compression: at least one transform must be enabled") ErrNegativeMin = errors.New("prompt_compression: min_length must not be negative") ErrEmptyRole = errors.New("prompt_compression: target_roles contains an empty role") ErrBadBlankLines = errors.New("prompt_compression: max_consecutive_blank_lines must be between 1 and 1000") ErrBadMaxBody = errors.New("prompt_compression: max_body_bytes must not be negative") )
Functions ¶
This section is empty.
Types ¶
type Data ¶
type Data struct {
Stage string `json:"stage,omitempty"`
Mode string `json:"mode,omitempty"`
Decision string `json:"decision,omitempty"`
Transforms string `json:"transforms,omitempty"`
BytesIn int `json:"bytes_in,omitempty"`
BytesOut int `json:"bytes_out,omitempty"`
BytesSaved int `json:"bytes_saved,omitempty"`
Ratio float64 `json:"ratio,omitempty"`
}
Data is the per-invocation telemetry payload recorded on the plugin span.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
func (*Plugin) Execute ¶
func (p *Plugin) Execute(ctx context.Context, in appplugins.ExecInput) (*appplugins.Result, error)
func (*Plugin) MandatoryStages ¶
func (*Plugin) MutatesMetadata ¶
func (*Plugin) MutatesRequestBody ¶
func (*Plugin) MutatesResponseBody ¶
func (*Plugin) SupportedModes ¶
func (*Plugin) SupportedProtocols ¶
func (p *Plugin) SupportedProtocols() []appplugins.Protocol
func (*Plugin) SupportedStages ¶
type Settings ¶
type Settings struct {
// CompressJSON minifies standalone JSON message content, fenced “`json
// blocks, and tool-call arguments (whitespace-only, fully lossless).
// Defaults to true.
CompressJSON bool
// NormalizeWhitespace trims trailing spaces per line (preserving Markdown
// two-space hard line breaks) and collapses long runs of blank lines.
// Defaults to true.
NormalizeWhitespace bool
// StripANSI removes ANSI escape (color/cursor) sequences, common in captured
// terminal and CI logs. Defaults to true.
StripANSI bool
// MaxConsecutiveBlankLines caps runs of blank lines when NormalizeWhitespace
// is on. Defaults to 1; values outside [1, 1000] are rejected.
MaxConsecutiveBlankLines int
// MinLength skips messages whose content is shorter than this many bytes, so
// tiny stable messages are never rewritten (avoids cache churn for no
// gain). Defaults to 256; an explicit 0 compresses everything.
MinLength int
// MaxBodyBytes skips the whole pipeline for request bodies larger than this
// many bytes, bounding per-request CPU cost. Defaults to 1 MiB; an explicit
// 0 disables the cap.
MaxBodyBytes int
// TargetRoles restricts compression to messages with these roles (e.g.
// "tool", "user"). Empty means all roles, including the system prompt.
TargetRoles []string
// contains filtered or unexported fields
}
Settings is the resolved configuration for the prompt compression plugin. Every transform is lossless or near-lossless and deterministic, so the same input always compresses to the same bytes — which keeps provider prompt-cache prefixes stable across turns.