Reduce unnecessary errors by 57%: Prioritize clearing obstacles for the agent to access logs.

Reduce unnecessary errors by 57%: Prioritize clearing obstacles for the agent to access logs.

3 weeks ago
duguying
18 views
Source: GitHub

By adding a local compression layer to the encoding agent, we were able to reduce the input size for investigating an SRE incident from 55,957 tokens down to 24,340. Crucially, the exact same FATAL error message remained unchanged.

Related tags

#GitHub#Trending#Headroom#AI Agent#上下文压缩

Saving on Processing Costs: 57% Token Reduction - Headroom: Agent Reads Log Files

This document is based on the README of the GitHub project headroomlabs-ai/headroom.

Summary: By adding a local compression layer to an agent, we were able to reduce the input token count from 55,957 to 24,340 while maintaining the exact same FATAL error message. The project gained 474 stars and now has a total of 77,289 stars.


A key aspect of an agent’s cost structure that is often overlooked is the number of tokens actually used for “thinking.” Most of these tokens are consumed by the input – commands, logs, code snippets retrieved, and RAG retrieval blocks. Headroom addresses this directly.

The project achieved top ranking on the Trendshift Daily chart, with 77,289 stars in total and 474 new stars per day. Its core functionality can be summarized as: compressing input data (commands, logs, files, and conversation history) before it enters an LLM, ensuring that the output remains consistent while significantly reducing token usage.

Compression Happens Locally

A key design choice of Headroom is to perform compression on your own machine, rather than sending prompts and file content elsewhere for processing. This is particularly important for teams working with private codebases.

Headroom offers four different ways to integrate:

  • Library: Using <code>compress(messages)</code> in Python and <code>await compress(messages, { model })</code> in TypeScript, directly within the application.
  • Proxy: Using <code>headroom proxy --port 8787</code>, allowing zero-code changes and supporting any language.
  • Agent Wrapping: Using <code>headroom wrap claude|codex|grok|copilot|cursor|aider|opencode|cline|continue|goose|openhands|kimi|zcode</code> to seamlessly integrate with existing agents, using a single command. The <code>headroom unwrap &lt;tool&gt;</code> command allows for easy removal of the tool integration.
  • MCP Server: Exposing three tools: <code>headroom_compress</code>, <code>headroom_retrieve</code>, and <code>headroom_stats</code>.

In addition, two other notable features are worth highlighting: cross-agent memory (shared storage for Claude, Codex, Gemini, and Grok with automatic de-duplication), and <code>headroom learn</code> which identifies unsuccessful sessions and writes corrections to <code>CLAUDE.local.md</code>, <code>CLAUDE.md</code>, <code>AGENTS.md</code>, <code>GEMINI.md</code>, or <code>GROK.md</code>.

Official Numbers: How Much Savings, What’s the Cost?

The README provides a set of reproducible benchmarks using <code>benchmarks/index_proof_table.py</code> with a seed value of 20260902 and based on four real MCP service output formats:

Scenario Before Compression After Compression Savings
Code Search (100 results) 17,199 13,597 21%
SRE Incident Debugging 55,957 24,340 57%
Codebase Exploration 58,801 33,895 42%
GitHub Issue Triage 46,067 32,429 30%

The pattern is clear: the savings depend on the degree of repetition. JSON arrays and log lines can be compressed by over 90% using <code>bench_latency.py</code>, while free-form text and already concise outputs are difficult to compress significantly. The authors also point out that short conversations, narrative text, and high-density content provide minimal savings, with blocks shorter than <code>min_input_words</code> being returned unchanged.

The overhead of compression itself is minimal, at 0.21 ms for a 10K token JSON search result (p50), and 1.4 ms for 100K tokens – this is negligible in the context of agent latency.

Accuracy was measured using <code>python -m headroom.evals suite --tier 1</code>, with GSM8K showing no difference (0.870 to 0.870), TruthfulQA increasing from 0.530 to 0.560, SQuAD v2 maintaining 97% accuracy at 19% compression, and BFCL maintaining 97% accuracy at 32% compression. Importantly, the authors have added annotations to the TruthfulQA results: With N=100, the ±0.03 value falls within the confidence interval, so this is considered “no statistically significant difference” rather than a performance improvement. This proactive reduction technique is not commonly found in READMEs.

Save on Output Costs Too

Saving on input tokens is only half the battle – output token costs remain high. On models like Opus, output tokens are five times more expensive than input tokens, and a significant portion of this cost comes from boilerplate content such as “Okay, let me…” introductions, verbatim code repetition, and lengthy reasoning required to process files.

Headroom reduces these costs by:

  • Verbosity Steering: Adding a prompt at the end of the system prompt instructing the LLM to be “concise and avoid repeating context,” ensuring that the prompt cache remains effective.
  • Effort Routing: Reducing the computational budget for tasks like “just return the tool’s output” by re-allocating it when new problems or errors arise. This works with Anthropic’s <code>/v1/messages</code> and OpenAI-compatible <code>/v1/chat/completions</code> and <code>/v1/responses</code>.

The savings on output are estimated, as no one knows exactly how much an LLM would normally generate. Headroom provides an estimate of 31.7% (95% CI 27.7%…35.7%) which can be measured by leaving 10% of sessions untouched as a control group (exporting HEADROOM_OUTPUT_HOLDOUT=0.1), after which the “estimated” value in the dashboard will change to “measured”.

Compatibility and Limitations

Headroom is compatible with: Claude Code, Codex, Grok CLI, Aider, Copilot CLI, VS Code Copilot, OpenClaw, OpenCode, Cline, Continue, Goose, OpenHands, Mistral Vibe, Oh My Pi, Kimi CLI, ZCode. Cursor requires manual configuration of the proxy address, and Cortex Code only supports the library mode. For frameworks, Headroom supports Anthropic/OpenAI SDK wrapping, Vercel AI SDK middleware, LiteLLM callback, LangChain, Agno, and ASGI middleware.

The README also clearly outlines when not to use Headroom: when using a single vendor’s native compression and without needing cross-agent memory; or when running in an environment that cannot support local process execution sandboxes. Compression is reversible: the original data can be retrieved within the TTL configured for CCR (Cache-Control Rewrite).

The project address is https://github.com/headroomlabs-ai/headroom

More News

Want to see more quality content?

Browse all news