Headroom: compress the logs and documents your agent reads before they reach the model, cutting tokens by up to 95%Headroom:把智能体读到的日志与文档先压缩再喂给模型,token 最高省 95%
A context window clogged with tool output is a daily pain when you write code. Headroom is a context compression layer (about 75,000 stars, Apache-2.0): it compresses logs, tool output, RAG chunks, files and conversation history before they reach the model. Officially that means roughly 20% fewer tokens for coding work and 60%–95% fewer for JSON-like content, while critical lines (such as a FATAL log entry) survive byte for byte. Compression runs entirely on your machine.
上下文被工具输出塞满,是写代码时的日常痛点。Headroom 是一层「上下文压缩层」(约 7.5 万星、Apache-2.0 许可):在日志、工具输出、RAG 片段、文件与会话历史进入模型之前先压缩,官方称编码场景平均少约 20% token,JSON 类内容最高可省 60%–95%,而关键行(比如日志里的 FATAL)逐字节保留。压缩全在本机完成。

Why you need it为什么需要它
The expensive part of an agent is usually not the model but the noise you feed it: a failing test log, a JSON blob tens of thousands of tokens long, a pile of retrieved documents — the vast majority of which contributes nothing to the final answer.
Headroom's idea is to make compression an infrastructure layer before the model: tool output, logs, files, RAG chunks and session history are filtered before being sent, so answer quality stays roughly the same while your bill and window usage both drop.
The official README makes it concrete: a 10,144-token log dump compressed to 1,260 tokens, with the FATAL line preserved exactly.
智能体真正贵的往往不是模型本身,而是喂进去的噪音:一次测试失败的日志、一份几万 token 的 JSON、一堆检索回来的长文档,其中绝大多数内容对最终答案没有贡献。
Headroom 的思路是把「压缩」做成模型之前的一层基础设施:工具输出、日志、文件、RAG 片段、会话历史先过滤再送模型,答案质量基本不变,账单和窗口占用一起下降。
官方 README 给的例子很直观:一份 10,144 token 的日志转储被压到 1,260 token,而里面那行 FATAL 原样保留。
How it works它怎么工作
It offers three ways in: wrapping the command line (handing tool output to it for compression), using it as a library in code (from headroom import compress), and plugging into mainstream coding agents.
Compression runs on your own machine and never uploads prompts or file contents. For structured text such as logs it groups by line type, dedupes and truncates, while rules guarantee that "lines you cannot lose" are always kept.
There is also headroom learn: it mines failed sessions and writes corrections back into your configuration so the same class of mistake is less likely next time.
它提供三种用法:包装命令行(把工具输出交给它压缩)、作为库在代码里调用(from headroom import compress)、以及接入主流编码智能体。
压缩逻辑跑在你自己的机器上,不上传提示词或文件内容;对日志这类结构化文本,它按行类型分组、去重、截断,同时用规则保证「不能丢的行」一定保留。
还有一个 headroom learn 功能:从失败会话里挖掘问题并把纠正写回配置,让下次少犯同类错误。
Getting started怎么用起来
Install: the PyPI package is headroom-ai, with a same-named npm package. Once installed, run a check command first to see how much it saves in your real workload.
On x86/x86_64 machines some ONNX-backed features require AVX2 CPU support; older servers or some Docker/QEMU environments may not qualify, and the README devotes a section to this.
When should you skip it? If you only use a single vendor's built-in compaction and do not need a unified cross-tool compression layer, there is no point adding another layer.
安装:PyPI 包名 headroom-ai,npm 也有同名包;装好后先跑一条检查命令,看看在你的真实场景里能省多少。
x86/x86_64 机器上部分基于 ONNX 的能力需要 CPU 支持 AVX2,老服务器或部分 Docker/QEMU 环境可能不满足,README 专门列了这一节提醒。
什么时候不该用?如果你只用单一厂商自带的上下文压缩、也不需要跨工具的统一压缩层,就没必要再叠一层。
Download instructions下载说明
The download button provides the official PyPI source distribution (sdist) headroom-ai 0.40.0, including the full Python implementation, evaluation scripts and docs. Unzip it and follow the README's 60-second quickstart.
下载按钮提供 PyPI 官方源码分发(sdist)headroom-ai 0.40.0,含完整 Python 实现、评测脚本与文档,解压后按 README 的 60 秒上手流程安装即可。
Use reminder使用提醒
This article is compiled from public sources and ships with the matching resource. Product features and pricing are subject to the official page. Resources are for learning and exchange only — please respect the original license.
本文整理自公开资料并附上配套资源;涉及产品的功能与价格以官方页面为准。资源仅供学习交流,请遵循来源许可。
⬇ Download · 点击下载:headroom-ai 0.40.0 PyPI 官方源码包(3.16MB)
来自 PyPI 官方源 headroom-ai 0.40.0 源码分发(Apache-2.0 许可);上游仓库为 GitHub headroomlabs-ai/headroom。
阅读与点赞数据保存在你的浏览器本地,欢迎留下你的想法。
今日正能量学一点,用一点;今天种下的种子,会长成明天的能力。去免费下载专区 →广告
评论 文明发言,让讨论更有价值