Context infrastructure · Open source

TokenOpt

A sufficiency-gated context compiler for LLM agents—built to reduce token load without removing the evidence required for the next decision.

TokenOpt compact architecture A vertical pipeline compiles an agent transcript through typed parsing and context transforms. A sufficiency oracle emits compiled context or restores evidence through a separate feedback lane. Sufficiency-gated compilation Agent transcript messages · tool calls · evidence Typed intermediate representation roles · provenance · dependencies Context transforms mask · dedupe · compact · allocate Sufficiency oracle approve or restore evidence Compiled context evidence recovery
30–70%final-turn token reduction in the documented synthetic old-tool-output masking benchmark
3delivery surfaces: HTTP server, CLI, and native/client integrations
2multi-agent controls: global budget allocation and cross-agent deduplication
1explicit sufficiency gate before optimized context is emitted

System architecture

Compile context instead of truncating it.

TokenOpt treats context as a structured build artifact. A typed IR enables deterministic transforms, the oracle evaluates whether retained evidence is sufficient, and cold-store references keep removed material recoverable.

TokenOpt context compilation architecture A five-stage primary flow moves conversation input through typed parsing, transformation, sufficiency checking, and compiled output. A separate feedback lane restores evidence when context is insufficient, while a lower output bus distributes compiled artifacts. Primary compilation path Conversation input messages · tools · outputs Parser + typed IR roles · provenance · links Context transforms mask · dedupe · allocate Sufficiency oracle approve or restore Compiled context smallest sufficient set Evidence recovery lane insufficient → restore referenced evidence Compiled artifact outputs Integration surfaces CLI · HTTP · SDKs Optimized messages ready for model input Statistics + audit trail savings · decisions Cold-store references recoverable evidence

Engineering choices

Designed for control and inspection.

The architecture separates representation, optimization, verification, and delivery so teams can tune savings while retaining visibility into what changed.

01

Evidence-aware transforms

Transforms operate over typed conversational structure rather than unstructured text slicing.

02

Multi-agent economics

A shared budget and cross-agent deduplication prevent each specialist from paying for the same context.

03

Recoverable compression

Cold-store references preserve a route back to removed content when later reasoning requires it.

Technology foundation

Built for speed, reach, and native integration.

A Rust optimization core is exposed through service, command-line, language-client, and native-binding surfaces so teams can adopt the compiler where their agents already run.

RustHigh-performance compiler core
PythonClient and native integration
TypeScriptTyped JavaScript client
HTTP APILanguage-neutral service access
ctxc CLILocal compilation workflows
Native bindingsPython and Node runtimes

Solution fit

Compiling context beats truncating it.

Most context strategies cut cost by deleting the oldest turns and hoping nothing important was in them. TokenOpt reduces by value rather than position, verifies sufficiency before it emits, and keeps a route back to whatever it removed.

Use case

Sessions that outgrow the window

Recency truncation discards the oldest turns regardless of what they contained. TokenOpt masks stale tool output while preserving the evidence the next decision depends on — a 30–70% final-turn reduction in the documented benchmark.

Use case

Agent teams paying twice for the same context

A shared global budget allocates spend across specialists and cross-agent deduplication removes repeated history, so a five-agent team does not buy the same transcript five times over.

Use case

Reductions that have to be defensible

Every compilation emits statistics and cold-store references alongside the messages, so a team can show exactly what was removed and recover it when later reasoning calls for it.

CapabilityTypical market approachTokenOpt
Reduction strategyFixed-window truncation or “keep the last N messages”, which discards evidence by position.A typed intermediate representation drives evidence-aware transforms that reduce by value, not recency.
Safety of the cutThe reduction is applied blind; the agent discovers the missing evidence only when it answers wrongly.An explicit sufficiency gate evaluates retained evidence and blocks emission until the next decision is supportable.
Recovering removed contentRemoved turns are gone for the remainder of the session.Cold-store references keep a route back to removed material whenever later reasoning needs it.
Multi-agent economicsEach agent optimizes in isolation and re-pays for shared history.Global budget allocation plus cross-agent deduplication across the whole specialist team.
VisibilitySavings are inferred after the fact from the invoice.Per-compilation statistics and references are returned with the optimized messages.
Adoption pathFramework-locked, so adopting it means rewriting the agent loop.One Rust core exposed through an HTTP service, the ctxc CLI, TypeScript and Python clients, and native bindings.

Comparison note: the market column describes the default behaviour of widely used context-window strategies — recency truncation and fixed summarization — rather than any named vendor product. The 30–70% figure is TokenOpt’s documented synthetic benchmark for masking old tool outputs; realized savings depend on transcript shape and policy configuration.

Need to improve agent context economics?

Discuss architecture, measurement, and production adoption.

Book a conversation →