Documentation
Features
Compression
Laghav strips filler words, preambles, duplicate lines, and verbose code comments using 8 specialized rules — reducing token usage by an average of 61% without sacrificing response quality.
The 8 compression rules
| Rule name | What it strips | Avg saving |
|---|---|---|
filler | Politeness hedges ('Hey I wanted to ask you...', 'Could you possibly...') | 10–20% |
preamble | Verbose intro sentences before the actual question | 8–15% |
dedup | Repeated identical or near-identical sentences | 5–30% |
intent | Redundant explanation of what the user wants | 5–12% |
whitespace | Extra blank lines, trailing spaces, redundant newlines | 2–8% |
log_slicer | INFO/DEBUG log spam — keeps only ERROR, WARN + 2-line context | 70–98% |
code_comment | JSDoc, Python docstrings, inline comments (preserves signatures & logic) | 15–40% |
json_slim | Redundant JSON keys, default null values, empty arrays | 20–50% |
Aggressiveness control
The max_aggressiveness parameter (0.0–1.0) controls how aggressively rules apply. Higher values save more tokens but may reduce quality score. The quality scorer always checks the result before sending.
aggressiveness.py
# Light — only strip obvious filler and whitespace (preserves more context)response = client.complete(messages=messages,model="auto",laghav_options={"max_aggressiveness": 0.2})# Default — balanced compressionresponse = client.complete(messages=messages,model="auto",laghav_options={"max_aggressiveness": 0.5})# Aggressive — maximum token reduction (good for log analysis, JSON payloads)response = client.complete(messages=messages,model="auto",laghav_options={"max_aggressiveness": 0.9})
Content type hints
Laghav auto-detects content type. You can override with the playground API or via content_type in the playground endpoint:
| Content type | Preferred rules | Use case |
|---|---|---|
auto | All rules, ranked by signal | Default — Laghav detects type |
code | code_comment, whitespace, dedup | Source code, function context |
log | log_slicer, whitespace, dedup | Log files, agent traces |
json | json_slim, whitespace, dedup | API payloads, config files |
text | filler, preamble, intent, whitespace | Natural language prompts |
Skipping specific rules
skip_rules.py
# Skip intent stripping — useful if intent IS the important partresponse = client.complete(messages=messages,model="auto",laghav_options={"skip_rules": ["intent", "preamble"]})
Real example
Before (63 tokens)
Hey I just wanted to ask you if you could possibly help me understand the main causes of the revenue drop that happened last quarter. I think it would be really helpful if you could explain it clearly.
After (24 tokens)
Explain main causes of last quarter's revenue drop.
62% compression94/100 quality
ℹOpen source compression core
The 8 compression rules are open source at
github.com/laghav-ai/compress (MIT license). Install standalone with pip install laghav-compress for local compression without a Laghav account.