Compress tool outputs, logs, files, and RAG chunks before they reach the LLM. 20% fewer tokens for coding agents, 60-95% fewer tokens for JSON, same answers. Library, proxy, MCP server.
Python agentaianthropicclaude-codecompressioncontext-engineeringcontext-windowcursorfastapilangchainllmmcpopenaiprompt-engineeringproxypythonragtoken-optimizationtokenstypescript
Merge pull request #458 from chopratejas/fix-litellm-azure-dashboard-compression-issues-454-455
Tejas Chopra71348f407f5d
diff --cc headroom/dashboard/templates/dashboard.htmlindex 5bb8b4c41,18e0346d5..6a73c4634--- a/headroom/dashboard/templates/dashboard.html+++ b/headroom/dashboard/templates/dashboard.html@@@ -1786,74 -1773,34 +1773,50 @@@return (this.stats.tokens?.proxy_compression_saved || 0) / total * 100;},- get rtkShareOfTotal() {+ get cliFilteringLabel() {+ const raw = this.stats.savings?.by_layer?.cli_filtering?.label+ || this.stats.context_tool?.label+ || this.stats.context_tool?.configured+ || 'Context Tool';+ if (String(raw).toLowerCase() === 'lean-ctx') return 'Lean-ctx';+ return String(raw);+ },++ get cliFilteringSaved() {+ return this.stats.tokens?.cli_filtering_saved+ ?? this.stats.tokens?.cli_tokens_avoided+ ?? this.stats.tokens?.rtk_saved+ ?? 0;+ },++ get cliFilteringShareOfTotal() {const total = this.compressionTotalBefore;if (total <= 0) return 0;- return (this.stats.tokens?.rtk_saved || 0) / total * 100;+ return this.cliFilteringSaved / total * 100;},- // --- Compression Confidence ----- get confidenceLevel() {- const saved = this.stats.tokens?.proxy_compression_saved || 0;- if (saved === 0) return 'none';- const signals = this.stats.waste_signals || {};- const totalWaste = Object.values(signals).reduce((a, b) => a + b, 0);- if (totalWaste === 0) return 'unknown';- const wasteRatio = totalWaste / saved;- if (wasteRatio >= 0.7) return 'high';- if (wasteRatio >= 0.3) return 'medium';- return 'low';+ // --- Headline savings percent ---+ //+ // Active ratio (saved / attempted) is the right metric when we have+ // a working denominator. Some backend-routed paths don't yet+ // populate `proxy_attempted_tokens` consistently — in that case+ // the active number reads 0% even when compression is happening,+ // so fall back to the whole-request ratio (`proxy_savings_percent`)+ // instead of showing a misleading zero. Issue #455.+ get headlineSavingsPercent() {+ const attempted = this.stats.tokens?.proxy_attempted_tokens || 0;+ const active = this.stats.tokens?.active_savings_percent || 0;+ if (attempted > 0 && active > 0) return active;+ return this.stats.tokens?.proxy_savings_percent || 0;},- get confidenceColor() {- const c = { high: 'bg-emerald-400', medium: 'bg-yellow-400', low: 'bg-red-400', none: 'bg-gray-500', unknown: 'bg-gray-500' };- return c[this.confidenceLevel];- },-- get confidenceTextColor() {- const c = { high: 'text-emerald-400', medium: 'text-yellow-400', low: 'text-red-400', none: 'text-gray-500', unknown: 'text-gray-500' };- return c[this.confidenceLevel];- },-- get confidenceLabel() {- const l = { high: 'High', medium: 'Medium', low: 'Low', none: '-', unknown: '-' };- return l[this.confidenceLevel];- },-- get confidenceDetail() {- const saved = this.stats.tokens?.proxy_compression_saved || 0;- if (saved === 0) return 'No compression yet';- const signals = this.stats.waste_signals || {};- const totalWaste = Object.values(signals).reduce((a, b) => a + b, 0);- if (totalWaste === 0) return 'No waste signals detected';- const pct = Math.round((totalWaste / saved) * 100);- return pct + '% of removed tokens were identified waste';- },-- getRequestConfidenceColor(req) {- if (!req.waste_signals || req.tokens_saved === 0) return 'bg-gray-500';- const totalWaste = Object.values(req.waste_signals).reduce((a, b) => a + b, 0);- const ratio = totalWaste / req.tokens_saved;- if (ratio >= 0.7) return 'bg-emerald-400';- if (ratio >= 0.3) return 'bg-yellow-400';- return 'bg-red-400';+ get headlineSavingsTitle() {+ const attempted = this.stats.tokens?.proxy_attempted_tokens || 0;+ const active = this.stats.tokens?.active_savings_percent || 0;+ if (attempted > 0 && active > 0) {+ return 'Of compressible tokens attempted';+ }+ return 'Of whole pre-compression request (attempted-tokens metric unavailable)';},// --- Expandable Rows ---