Context layer
v0.9BetaContext Compression
Reducing token usage while preserving model understanding.
- Rust
- Python
from legion_compress import compress
ctx = compress(session.history,
mode="bounded", max_drift=0.02)
print(ctx.ratio) # ~50x on long-horizon traces
model.generate(ctx.tokens)
- Version
- v0.9
- Status
- Beta
- License
- Open specification
- Implementations
- Rust · Python
- Stack layer
- Context
What the spec defines
The guarantees, not the vibes.
Context Compression is our protocol for reducing token usage while preserving model understanding — lossless where structure allows it, and measurably bounded where it doesn't. It's how we reach 50x context efficiency on long-horizon tasks without losing the thread.
The protocol grew out of measurement, not intuition. Our field study found the median production request spends under a fifth of its tokens on content that influences the output; compression targets the rest, and the ablation probes that found the waste are the same machinery that verifies drift stays inside the bound you set.
Bounded-loss is the design decision that makes the protocol honest: instead of promising losslessness it can't keep, every mode declares its maximum semantic drift and the verification suite holds it there. You choose the trade; the protocol enforces it.
The Rust core does the heavy lifting, with Python bindings for training and evaluation pipelines. The spec is in beta at v0.9 alongside the published compression paper and its evaluation suite.
Proven in production