Documentation
¶
Overview ¶
Package whittle carves agent tool outputs down to what matters — and never cuts what doesn't come back.
Whittle is a content-aware compressor for the text an AI agent reads: tool outputs, file reads, logs, JSON, terminal streams. It routes each input to a type-specific strategy and holds one hard line: structural compression is LOSSLESS or CLEARLY MARKED, code never reaches a lossy model, and any anomaly fails open to the original bytes.
The deterministic strategies (JSON columnar reshaping, log selection with omission markers, terminal CR-overwrite collapse, ANSI stripping) work with no dependencies. The optional ML prose path (LLMLingua-2, see model/) activates only when Options.ModelURL (or WHITTLE_MODEL_URL) points at a running model sidecar.
eng := whittle.New(whittle.Options{})
res := eng.Compress(ctx, toolOutput)
if res.Action == "compressed" {
use(res.Output) // res.SkipReason explains any skip
}
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var SidecarFS embed.FS
SidecarFS carries the Python model sidecar inside the binary so that `go install .../cmd/whittle@latest` is a complete installation: `whittle setup` materializes these files to ~/.whittle/model and builds a venv there.
Functions ¶
func EstimateTokens ¶
EstimateTokens is whittle's calibrated token estimator (MAE ~8% vs tiktoken o200k_base) — the same accounting the engine's accept gates use.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine is a reusable, concurrency-safe compressor.
func New ¶
New builds an Engine from opts.
Example ¶
package main
import (
"context"
"fmt"
"strings"
"github.com/firstops-dev/whittle"
)
func main() {
eng := whittle.New(whittle.Options{MinTokens: 0})
toolOutput := "ERROR boot failed\n" + strings.Repeat("2026 INFO tick handler ok\n", 80)
res := eng.Compress(context.Background(), toolOutput)
fmt.Println(res.Action, res.Detected, strings.Contains(res.Output, "ERROR boot failed"))
}
Output: compressed log true
type Options ¶
type Options struct {
// ModelURL enables the ML prose path (an LLMLingua sidecar, see model/).
// Empty = prose and doc-read content pass through untouched.
ModelURL string
// MinTokens skips inputs shorter than this (default 64; compression isn't
// worth it below that). Use -1 to keep the default; 0 disables the floor.
MinTokens int
// MaxChars is the global safety ceiling; larger inputs skip before
// classification (default 256 KiB).
MaxChars int
// ProseMaxChars caps only the ML prose path (default 100000 — a latency
// budget sized for GPU/MPS inference, not a correctness bound; CPU-bound
// machines should lower it, see compress/gate.go).
ProseMaxChars int
// Logger receives pipeline diagnostics (nil = silent).
Logger compress.Logger
}
Options configures an Engine. The zero value is production-safe: deterministic compressors only, default gates.
Directories
¶
| Path | Synopsis |
|---|---|
|
Command bench is whittle's reproducible benchmark harness: it runs the checked-in corpus through the engine and verifies ROUTING, ACTION, and REDUCTION against baseline.json — plus fixture byte-integrity (SHA-256), so the numbers in REPORT.md are regenerable, honest artifacts.
|
Command bench is whittle's reproducible benchmark harness: it runs the checked-in corpus through the engine and verifies ROUTING, ACTION, and REDUCTION against baseline.json — plus fixture byte-integrity (SHA-256), so the numbers in REPORT.md are regenerable, honest artifacts. |
|
cmd
|
|
|
whittle
command
Command whittle is the CLI: compress files or stdin, or run the HTTP service.
|
Command whittle is the CLI: compress files or stdin, or run the HTTP service. |
|
Package compress is the content-aware tool-output compressor library: a gate decides whether content is safe to compress, a router classifies it, and a pipeline dispatches to specialized compressors.
|
Package compress is the content-aware tool-output compressor library: a gate decides whether content is safe to compress, a router classifies it, and a pipeline dispatches to specialized compressors. |
|
compressors
Package compressors holds the concrete Compressor implementations and wires the default per-type chains.
|
Package compressors holds the concrete Compressor implementations and wires the default per-type chains. |
|
Package router is whittle's opt-in model router: it sits between Claude Code and the Anthropic API, inspects each request, and routes it to the cheapest capable model tier per a user-authored policy.
|
Package router is whittle's opt-in model router: it sits between Claude Code and the Anthropic API, inspects each request, and routes it to the cheapest capable model tier per a user-authored policy. |
|
ml
Package ml is the router's opt-in smart-mode surface: a thin HTTP client to the model sidecar, implementing router.Classifier.
|
Package ml is the router's opt-in smart-mode surface: a thin HTTP client to the model sidecar, implementing router.Classifier. |
|
Package server is whittle's HTTP front door.
|
Package server is whittle's HTTP front door. |
