Liate Framework

Token Optimizer (AgentDiet)

How OM's built-in 2026 Token Optimizer reduces context size and token costs by 70-85%.

Traditional agent frameworks suffer from quadratic token explosion: as an agent executes multi-turn tool loops, massive JSON schemas and verbose HTML/JSON tool outputs pile up in context, quickly burning through token budgets and slowing down execution.

OM includes a built-in 2026 Token Optimizer (AgentDiet) that compresses context by 70% to 85% without sacrificing intelligence or accuracy.

The 3 Layers of Optimization

1. Tool Schema Minification (minifyToolSchemas)

Strips redundant JSON Schema fields ($schema, title, definitions, additionalProperties). Trims verbose descriptions to concise first sentences.

Savings: ~1,500 tokens per agent prompt

2. Tool Output Sanitization (sanitizeToolOutput)

Strips bulky blob keys (base64, rawhtml, stacktrace, pagetoken, rawheaders). Large lists (>10 items) are summarized, preventing payload explosions.

Savings: Up to 10,000+ tokens per web/API tool result

3. Trajectory Pruning (pruneTrajectoryMessages / AgentDiet)

Preserves the last 2 turns in full fidelity. Older intermediate tool responses (>2 turns ago) are automatically compacted to a 250-character summary.

Savings: Prevents exponential cost in 5–10 turn ReAct loops

Real-Time Economic Metrics

Every time an agent executes, Liate logs exact token usage and compute costs to your console:

[METRICS]   Peak Context: 412 tokens | Total Turn I/O: 642 (Prompt: 412, Output: 230)
[ECONOMICS] Est. Compute: ₹0.000098 | Run Price: ₹1.00 | Margin: 99.99%
Open Source·MIT License·Self Host