mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-07-26 09:52:11 +03:00
* chore(release): v3.7.9 — gemini-cli cloud code separation * chore(provider): Update Jina AI model catalog (#1874) Integrated into release/v3.7.9 * docs: update CHANGELOG for PR 1874 and retroactive credits * fix: resolve stream defaults and codex prompt mapping (#1873, #1872) * chore(compression): start caveman compression update * feat(compression): expand caveman compression and analytics pipeline Add caveman intensity levels, output mode instructions, validation, and preview diffs across the compression pipeline. Extend MCP and dashboard settings to support auto-trigger mode, system prompt preservation, MCP description compression, and caveman rule metadata. Record richer compression analytics with receipt fields, validation fallbacks, output mode data, and add the related database migration. Improve preservation handling for code, URLs, markdown, math, and other protected content while adding broad unit, integration, and golden-set coverage for caveman parity and compression behavior. * feat(compression): expose rule intensities and track usd savings Add estimated USD savings to compression analytics so saved tokens can be reported in cost terms alongside existing token metrics. Expose caveman rule intensity metadata for settings consumers and add a settings API route alias for rule lookup. Also preserve system prompts when aggressive compression falls back to lite mode. * feat(compression): RTK compression roadmap (#1889) * chore(rtk): initialize compression roadmap branch * feat(compression): add RTK engine and compression combos Introduce RTK command-aware tool-output compression alongside stacked RTK -> Caveman pipelines for mixed prompt contexts. Add engine registration, declarative RTK filter packs, language-aware Caveman rule loading, compression combo persistence and assignments, analytics grouped by engine/combo, and new MCP/API endpoints for configuration, previews, filters, and combo management. Expose the new capabilities in the dashboard with dedicated Context & Cache pages for Caveman, RTK, and compression combos, and update docs, i18n strings, migrations, and tests to cover the expanded compression surface. * feat(compression): expand RTK DSL, filter catalog, and recovery APIs Add RTK parity features across the compression pipeline, dashboard, and management APIs. This expands the built-in filter catalog, adds trust-gated custom filter loading, inline filter verification, code stripping, smarter detection, and optional redacted raw-output retention for authenticated recovery. Also extend Caveman with file-based multilingual rule packs, localized output-mode instructions, stricter preview/config schemas, engine registry metadata, analytics fields, and broad unit test coverage for RTK, rule loading, and stacked compression behavior. * fix(auth): protect oauth routes and health reset operations Require authenticated dashboard access for OAuth endpoints that can create or import provider connections when login enforcement is enabled. Move `/api/monitoring/health` to the readonly public route list so safe methods remain public while DELETE now returns 401 for anonymous requests. Also update Next.js native `.node` handling to avoid webpack parse failures from external packages such as ngrok and keytar, and add coverage for the new auth behavior. * build(compression): ship RTK rule and filter assets with app bundles Include compression JSON assets in Next output tracing, prepublish copies, and pack artifact policy checks so standalone and packaged builds can load RTK filters and caveman rule packs at runtime. Also harden compression runtime behavior by resolving alternate asset directories, scoping rule cache entries by source path, carrying RTK raw output pointers through stacked runs, degrading oversized preview diffs, and applying combo language/output mode defaults during chat routing. Add coverage for packaging rules, provider-scoped model parsing, smart truncate edge cases, raw output retention, and combo-driven compression behavior. * docs(workflows): update local repo paths to OmniRoute Replace outdated `/home/diegosouzapw/dev/proxys/9router` references with the current `OmniRoute` directory across deploy, release, and version bump workflow guides so local command examples match the renamed repository layout * feat(compression): complete RTK parity coverage * test(build): align next config assertions --------- Co-authored-by: diegosouzapw <diego.souza.pw@gmail.com> * feat(compression): expand caveman parity and MCP metadata compression Compress MCP registry and list metadata descriptions for tools, prompts, resources, and resource templates while keeping tool-response bodies unchanged. Expose those savings in compression status as `mcp_metadata_estimate` metadata rather than provider usage. Add Caveman rule-pack support for custom regex flags and match-specific replacement maps, update English rules for upstream parity, and tighten article and pleasantry handling. Also process RTK multipart text blocks independently so mixed media content compresses safely without duplicating output. * feat(compression): unify config validation and persist MCP savings Centralize compression config schemas across settings, preview, RTK, and combo APIs to enforce consistent validation for stacked pipelines and engine-specific options. Expand caveman and stacked compression behavior by applying default combos at runtime, surfacing validation and fallback metadata, and exposing aggressive and ultra adapter schemas for configuration UI and tests. Persist MCP description compression snapshots into analytics without counting them as provider usage, and extend the dashboard with the new RTK controls and localized labels. * fix(auth): require dashboard management auth for compression preview Block preview requests unless they come from a valid management session token so protected settings cannot be probed through the preview API. Add unit coverage for unauthenticated requests, invalid bearer tokens, and successful authenticated preview execution. * fix(compression): preserve stacked defaults and secure metadata routes Only apply saved default compression combos when they contain a stacked pipeline so seeded Caveman-only defaults do not replace the builtin stacked behavior. Also require management auth for compression language pack and rules metadata endpoints, and defer usage receipt attachment until compression analytics writes have completed to keep analytics records consistent. * fix(compression): align seeded standard savings combo with stacked default Update the seeded default compression combo to use the RTK then Caveman pipeline in both fresh installs and upgraded databases. Add a targeted migration and runtime guard that only rewrites the legacy seeded record when its original metadata and single-step pipeline still match, preserving user-customized default combos. Refresh docs and tests to reflect the stacked default and expanded RTK filter catalog. * docs(compression): document RTK+Caveman stacked savings ranges Refresh the compression docs and README to describe the default stacked pipeline in terms of eligible-context savings instead of the older generic token-saving range. Add upstream RTK and Caveman benchmark references, explain the multiplicative savings math behind the stacked default, and update feature summaries plus package metadata to match the revised positioning. * feat(image-gen): add NanoGPT image generation provider (#1899) Integrated into release/v3.7.9 * fix(codex): sanitize raw responses input (#1895) Integrated into release/v3.7.9 * Fix combo provider breaker profile handling (#1891) Integrated into release/v3.7.9 * fix(combos): align strategy contracts (#1892) Integrated into release/v3.7.9 * feat(proxy): move proxy configuration to dedicated System → Proxy page (#1907) Integrated into release/v3.7.9 * feat: add K/M/B/T cost shortener to prevent UI overflow (#1902) Integrated into release/v3.7.9 * feat(providers): implement bulk paste for extra API keys (#1916) Integrated into release/v3.7.9 * fix(migrations): treat duplicate-column ALTER as no-op (#1886) Integrated into release/v3.7.9 * fix(analytics): robust model pricing resolution, dark mode charts and SQL aggregation fixes (#1896) Integrated into release/v3.7.9 (migration renumbered to 044) * fix(oauth): per-connection mutex for rotating refresh tokens (#1885) Integrated into release/v3.7.9 * fix: resolve 3 bugs — Codex tool normalization (#1914), image gen proxy (#1904), zero-arg MCP tools (#1898) - fix(codex): flatten Chat Completions tool format to Responses format in normalizeCodexTools. Prevents 'Missing required parameter: tools[0].name' upstream errors when clients send {type:'function', function:{name,...}} instead of {type:'function', name,...}. - fix(proxy): add proxy-aware execution context to image generation route. Image requests now correctly use proxy settings from the connection's ProxyRegistry assignment, matching the pattern used by chat pipeline. - fix(translator): inject properties:{} into zero-argument MCP tool schemas during Anthropic→OpenAI translation. OpenAI strict mode requires explicit properties even for empty object schemas. Closes #1914, Closes #1904, Closes #1898 * chore(release): v3.7.9 — all changes in ONE commit * fix: allow local ollama provider connections (#1893) * fix(copilot): emit compatible reasoning text deltas (#1919) Integrated into release/v3.7.9 * fix(api-manager): show validation errors inline in modals, not behind backdrop (#1920) Integrated into release/v3.7.9 * docs: update changelog and pr body with merged prs * fix(providers): route agentrouter through anthropic endpoint headers Update the AgentRouter provider registry to use the Claude-compatible messages API and required Anthropic-style authentication headers. This bypasses unauthorized_client_error responses and exposes the supported model list through passthrough configuration. Also update the changelog and release PR notes to document the fix for #1921 * feat(logs): show compression tokens in request log UI (#1923) * docs: add PR #1923 to changelog --------- Co-authored-by: diegosouzapw <diego.souza.pw@gmail.com> Co-authored-by: backryun <bakryun0718@proton.me> Co-authored-by: Aculeasis <42580940+Aculeasis@users.noreply.github.com> Co-authored-by: Raxxoor <manker_lol@hotmail.com> Co-authored-by: Randi <55005611+rdself@users.noreply.github.com> Co-authored-by: Paijo <14921983+oyi77@users.noreply.github.com> Co-authored-by: Tubagus <54710482+0xtbug@users.noreply.github.com> Co-authored-by: smartenok-ops <smartenok@gmail.com> Co-authored-by: Gi99lin <74502520+Gi99lin@users.noreply.github.com> Co-authored-by: ivan-mezentsev <ivan@mezentsev.me> Co-authored-by: Andrew Munsell <andrew@wizardapps.net>
277 lines
11 KiB
Markdown
277 lines
11 KiB
Markdown
# 🗜️ Prompt Compression Guide — OmniRoute
|
|
|
|
> Save 15-95% on eligible context automatically. For a quick overview, see the [README Compression section](../README.md#%EF%B8%8F-prompt-compression--save-15-95-eligible-tokens-automatically).
|
|
|
|
## Overview
|
|
|
|
OmniRoute implements a modular prompt compression pipeline that runs **proactively** before requests hit upstream providers. This means your token savings happen transparently — no changes needed to your workflow.
|
|
|
|
```
|
|
Client Request
|
|
→ Compression Strategy Selector
|
|
→ Combo override? → Use combo setting
|
|
→ Auto-trigger threshold? → Use auto mode
|
|
→ Default mode? → Use global setting
|
|
→ Off? → Skip compression
|
|
→ Selected Compression Mode
|
|
→ Off: No compression
|
|
→ Lite: Safe whitespace/formatting cleanup (~15%)
|
|
→ Standard: Caveman-speak filler removal (~30%)
|
|
→ Aggressive: History aging + summarization (~50%)
|
|
→ Ultra: Heuristic pruning + code-block thinning (~75%)
|
|
→ RTK: Command-aware terminal/tool-output filtering (60-90% upstream range)
|
|
→ Stacked: Ordered multi-engine pipeline, usually RTK then Caveman (78-95% eligible range)
|
|
→ Compressed Request → Provider
|
|
```
|
|
|
|
---
|
|
|
|
## Compression Modes
|
|
|
|
### Off
|
|
|
|
No compression applied. All messages pass through unchanged.
|
|
|
|
### Lite Mode (~15% savings, <1ms latency)
|
|
|
|
The safest mode — zero semantic change, only formatting cleanup:
|
|
|
|
| Technique | Description |
|
|
| ------------------------ | ------------------------------------------------- |
|
|
| `collapseWhitespace` | Merge consecutive blank lines and trailing spaces |
|
|
| `dedupSystemPrompt` | Remove duplicate system messages |
|
|
| `compressToolResults` | Compress verbose tool/function outputs |
|
|
| `removeRedundantContent` | Strip repeated instructions |
|
|
| `replaceImageUrls` | Shorten base64 image data URIs |
|
|
|
|
**Best for:** Always-on usage, safety-critical workflows.
|
|
|
|
### Standard Mode (~30% savings)
|
|
|
|
Inspired by [Caveman](https://github.com/JuliusBrussee/caveman) — removes filler words and verbose phrasing while preserving meaning:
|
|
|
|
- Removes filler words ("please", "I think", "basically", "actually")
|
|
- Condenses verbose phrases ("in order to" → "to", "as a result of" → "because")
|
|
- Strips polite hedging ("Would you mind...", "If you could possibly...")
|
|
- 30+ regex rules tuned for coding prompts
|
|
|
|
**Best for:** Daily coding workflows, cost-conscious teams.
|
|
|
|
### Aggressive Mode (~50% savings)
|
|
|
|
Smart history management for long sessions:
|
|
|
|
- **Message Aging** — older messages get progressively compressed
|
|
- **Tool Result Summarization** — long tool outputs replaced with summaries
|
|
- **Structural Integrity Guards** — ensures `tool_use` + `tool_result` pairs stay consistent
|
|
- **Context Window Awareness** — respects per-model token limits
|
|
|
|
**Best for:** Extended debugging sessions, large codebases.
|
|
|
|
### Ultra Mode (~75% savings)
|
|
|
|
Maximum compression for token-critical scenarios:
|
|
|
|
- **Heuristic Pruning** — removes messages below relevance threshold
|
|
- **Code Block Thinning** — compresses repetitive code examples
|
|
- **Binary Search Truncation** — finds optimal cut point for context window
|
|
- All Aggressive mode features included
|
|
|
|
**Best for:** When you're hitting context limits repeatedly.
|
|
|
|
### RTK Mode (60-90% upstream range)
|
|
|
|
RTK mode is optimized for verbose tool outputs that appear in coding-agent sessions:
|
|
|
|
- Detects command/output classes such as `git status`, `git diff`, `git log`, test runners,
|
|
TypeScript/Vite/Webpack builds, ESLint/Biome/Prettier, npm audit/installs, Docker logs, infra
|
|
output, and generic shell output
|
|
- Applies JSON filter packs from `open-sse/services/compression/engines/rtk/filters/`
|
|
- Ships 49 built-in filters with inline verify samples
|
|
- Removes ANSI control sequences, progress bars, repeated lines, and non-actionable noise
|
|
- Preserves failures, errors, warnings, changed files, summaries, and the tail of long output
|
|
- Supports trust-gated project filters, global filters, and optional redacted raw-output recovery
|
|
|
|
**Best for:** Agent sessions with shell, build, test, git, grep, and file-output transcripts.
|
|
|
|
### Stacked Mode (78-95% eligible range)
|
|
|
|
Stacked mode runs multiple compression engines in a deterministic order. The default pipeline is:
|
|
|
|
```txt
|
|
RTK -> Caveman
|
|
```
|
|
|
|
That order keeps terminal/tool output compact first, then applies Caveman semantic condensation to
|
|
the remaining natural-language prompt. Stacked pipelines can be configured globally or through
|
|
compression combos assigned to routing combos.
|
|
|
|
**Best for:** Mixed context with large tool logs plus human instructions or assistant summaries.
|
|
|
|
---
|
|
|
|
## Upstream Savings Math
|
|
|
|
OmniRoute documents compression savings from two sources: upstream project benchmarks and
|
|
OmniRoute's own engine composition.
|
|
|
|
| Source | Upstream README number used here |
|
|
| ------- | --------------------------------------------------------------------------------------------------------------------- |
|
|
| Caveman | `~75%` fewer output tokens, `65%` benchmark average output savings, `22-87%` range, and `~46%` input compression tool |
|
|
| RTK | `60-90%` command-output savings; sample session `~118,000 -> ~23,900` tokens, or `79.7%` saved (`~80%`) |
|
|
|
|
For overlapping tool/context payloads, the default OmniRoute combo stacks the engines:
|
|
|
|
```txt
|
|
RTK -> Caveman
|
|
```
|
|
|
|
The combined savings are multiplicative, not additive:
|
|
|
|
```txt
|
|
combined = 1 - (1 - RTK savings) * (1 - Caveman input savings)
|
|
average = 1 - (1 - 0.80) * (1 - 0.46) = 89.2%
|
|
range = 1 - (1 - 0.60..0.90) * (1 - 0.46) = 78.4-94.6%
|
|
```
|
|
|
|
That `78-95%` number applies when both RTK and Caveman can reduce the same input/context payload.
|
|
Caveman response output mode is separate: when enabled, use Caveman's own output savings (`65%`
|
|
average, `~75%` headline, `22-87%` range). Total billing savings depend on your prompt/output mix.
|
|
|
|
---
|
|
|
|
## Token Savings Visualization
|
|
|
|
```
|
|
Without compression: 47K tokens sent to LLM
|
|
With Lite: 40K tokens sent (15% saved — safe, always-on)
|
|
With Standard: 33K tokens sent (30% saved — caveman-speak rules)
|
|
With Aggressive: 24K tokens sent (50% saved — aging + summarization)
|
|
With Ultra: 12K tokens sent (75% saved — heuristic pruning)
|
|
With RTK: 19K-5K tokens sent (60-90% saved on command/tool output)
|
|
With Stacked: 10K-2.5K tokens sent (78-95% eligible RTK+Caveman range)
|
|
```
|
|
|
|
---
|
|
|
|
## Configuration
|
|
|
|
### Dashboard
|
|
|
|
Navigate to `Dashboard → Context & Cache`:
|
|
|
|
- **Caveman** — mode selection, language packs, preview, and global defaults
|
|
- **RTK** — command-filter preview, RTK safety settings, and filter catalog
|
|
- **Compression Combos** — named engine pipelines assigned to routing combos
|
|
- **Auto-Trigger Threshold** — automatically engage compression when token count exceeds threshold
|
|
|
|
### Per-Combo Override
|
|
|
|
In `Dashboard → Context & Cache → Compression Combos`, assign a compression combo to a routing
|
|
combo:
|
|
|
|
```txt
|
|
Combo: "free-forever"
|
|
Compression Combo: "coding-agent-stack"
|
|
Pipeline: RTK -> Caveman
|
|
Targets:
|
|
1. gc/gemini-3-flash
|
|
2. if/kimi-k2-thinking
|
|
```
|
|
|
|
This lets you use stacked compression on free/coding providers while keeping lite mode on paid
|
|
subscriptions.
|
|
|
|
### API
|
|
|
|
```bash
|
|
# Get compression settings
|
|
curl http://localhost:20128/api/settings/compression
|
|
|
|
# Update compression settings
|
|
curl -X PUT http://localhost:20128/api/settings/compression \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"defaultMode":"stacked","autoTriggerMode":"stacked","autoTriggerTokens":32000}'
|
|
|
|
# Preview a specific RTK/stacked payload
|
|
curl -X POST http://localhost:20128/api/compression/preview \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"mode":"rtk","messages":[{"role":"tool","content":"npm test output here"}]}'
|
|
|
|
# List RTK filter packs
|
|
curl http://localhost:20128/api/context/rtk/filters
|
|
|
|
# Test RTK directly with optional command metadata
|
|
curl -X POST http://localhost:20128/api/context/rtk/test \
|
|
-H "Content-Type: application/json" \
|
|
-d '{"command":"npm test","text":"FAIL tests/example.test.ts\nError: boom"}'
|
|
```
|
|
|
|
---
|
|
|
|
## What Gets Protected
|
|
|
|
The compression engine **always preserves:**
|
|
|
|
- ✅ Code blocks (fenced and inline)
|
|
- ✅ URLs and file paths
|
|
- ✅ JSON structures and structured data
|
|
- ✅ Identifiers and protected technical tokens
|
|
- ✅ Mathematical expressions
|
|
- ✅ Tool/function call definitions
|
|
- ✅ System prompts (in lite mode)
|
|
|
|
RTK raw-output recovery redacts common API keys, bearer tokens, Slack tokens, AWS access keys,
|
|
passwords, tokens, and secrets before anything is persisted.
|
|
|
|
---
|
|
|
|
## Compression Stats
|
|
|
|
Every compressed request includes stats in the server logs:
|
|
|
|
```json
|
|
{
|
|
"originalTokens": 47200,
|
|
"compressedTokens": 40120,
|
|
"savingsPercent": 15.0,
|
|
"techniquesUsed": ["collapseWhitespace", "dedupSystemPrompt"],
|
|
"mode": "lite",
|
|
"engine": "caveman",
|
|
"compressionComboId": "coding-agent-stack",
|
|
"durationMs": 0.8,
|
|
"rtkRawOutputPointers": []
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## Phase Roadmap
|
|
|
|
| Phase | Modes | Status |
|
|
| ------- | ------------------------------------ | ---------- |
|
|
| Phase 1 | Off, Lite | ✅ Shipped |
|
|
| Phase 2 | Standard, Aggressive, Ultra | ✅ Shipped |
|
|
| Phase 3 | RTK, Stacked, Compression Combos | ✅ Shipped |
|
|
| Phase 4 | Per-model adaptive, ML-based pruning | 🗓️ Planned |
|
|
|
|
---
|
|
|
|
## Acknowledgments
|
|
|
|
Standard mode compression rules are inspired by **[Caveman](https://github.com/JuliusBrussee/caveman)** by **[JuliusBrussee](https://github.com/JuliusBrussee)** (⭐ 51K+) — the viral "why use many token when few token do trick" project. Caveman reports `~75%` fewer output tokens, `65%` benchmark average output savings, a `22-87%` output range, and a `~46%` input-compression tool.
|
|
|
|
RTK mode is inspired by **[RTK - Rust Token Killer](https://github.com/rtk-ai/rtk)** by **[RTK AI](https://github.com/rtk-ai)** — the high-performance command-output compression project for terminal, build, test, git, and tool-output filtering. RTK reports `60-90%` savings, with its README sample session showing `~80%` saved.
|
|
|
|
---
|
|
|
|
## See Also
|
|
|
|
- [Environment Config](ENVIRONMENT.md) — Compression environment variables
|
|
- [Architecture Guide](ARCHITECTURE.md) — Compression pipeline internals
|
|
- [User Guide](USER_GUIDE.md) — Getting started with compression
|
|
- [RTK Compression](RTK_COMPRESSION.md) — RTK filters, trust model, verify gate, raw-output recovery
|
|
- [Compression Engines](COMPRESSION_ENGINES.md) — Caveman, RTK, stacked, APIs, MCP, dashboard
|
|
- [Compression Rules Format](COMPRESSION_RULES_FORMAT.md) — JSON rule-pack format
|
|
- [Compression Language Packs](COMPRESSION_LANGUAGE_PACKS.md) — Language-specific Caveman rules
|