ranxianglei / billion-context

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

ranxianglei / billion-context

billion-context English | 中文 Context-compression plugin — billion-context is all you need. small context windows (100K is enough) · 5× fewer tokens · month-long single sessions (billions of tokens) · high compression quality npm install -g billion-context —prefix=~/.local

上下文压缩插件 — billion-context 是你所需要的一切。小上下文窗口(100K 足矣)· 代币减少 5 倍 · 长达一个月的单次会话(数十亿代币)· 高质量压缩 npm install -g billion-context —prefix=~/.local

Cache health at a glance: a healthy session keeps a 95–97% prefix-cache hit rate — compression itself costs ≤2%. Sustained lower? Check attribution with /acp or /acp-cache (see FAQ); usual causes, in order: upstream cache TTL expiry · model switch · a bili bug (please report) · other/unknown.

缓存健康状况一目了然:健康的会话保持 95–97% 的前缀缓存命中率 — 压缩本身的成本 ≤2%。如果持续偏低?请使用 /acp 或 /acp-cache 检查归因(参见常见问题解答);常见原因按顺序排列:上游缓存 TTL 过期 · 模型切换 · bili 错误(请报告)· 其他/未知。

Community QQ Group: 1056132097 (full) 1108730198 (full) 1129868472 (open) 📄 Paper / Preprint Model-Driven Incremental Hierarchical Compression: Training-Free Multi-Generational Context Management for Long-Lived Coding Agents (English, v0.2)

社区 QQ 群:1056132097(已满)1108730198(已满)1129868472(开放)📄 论文 / 预印本《模型驱动的增量分层压缩:面向长寿命编码代理的免训练多代上下文管理》(英文,v0.2)

📝 The paper itself is open-sourced under the MIT License as part of the codebase (paper/). It is a living document — anyone may edit it; improvements are welcome via pull request. A production-scale longitudinal study: 4.5 months, three hosts, 174,327 model calls, 18.76B cumulative input tokens (~24.7B across all hosts), zero window violations on 204,800-token models, marathon sessions of 8,584–12,049 calls.

📝 该论文本身作为代码库(paper/)的一部分在 MIT 许可下开源。这是一份动态文档 — 任何人都可以编辑;欢迎通过 pull request 提交改进。一项生产规模的纵向研究:4.5 个月,三个主机,174,327 次模型调用,187.6 亿累计输入代币(所有主机总计约 247 亿),在 204,800 代币模型上零窗口违规,马拉松式会话达 8,584–12,049 次调用。

📊 Independent Third-Party Benchmarks 1,500-Item Cross-Benchmark Evaluation (LongMemEval-S · ContextBench · MemoryAgentBench) (中文版) — head-to-head comparison of billion-context (v0.1.202) against full context and 3 RAG arms (bm25, embedding, embedding-rerank) with DeepSeek V4.1 Flash, Qwen3-Embedding-8B, Qwen3-Reranker-4B, and Pi Agent: #1 on ContextBench (0.3097 Utilized F1, -58.3% cost vs full), +16.6% over best RAG on LongMemEval-S (79.20% vs 62.60%, -71.1% independent-session cost vs full), and 100% survival on 1.48M-token MemoryAgentBench TTL (30× steady-state compression where full fails 199/199).

📊 独立第三方基准测试 1,500 项交叉基准评估(LongMemEval-S · ContextBench · MemoryAgentBench)(中文版)— billion-context (v0.1.202) 与全上下文及 3 种 RAG 方案(bm25、embedding、embedding-rerank)的正面比较,使用 DeepSeek V4.1 Flash、Qwen3-Embedding-8B、Qwen3-Reranker-4B 和 Pi Agent:在 ContextBench 上排名第一(0.3097 Utilized F1,成本比全上下文降低 58.3%),在 LongMemEval-S 上比最佳 RAG 高出 16.6%(79.20% 对 62.60%,独立会话成本比全上下文降低 71.1%),并在 1.48M 代币的 MemoryAgentBench TTL 测试中实现 100% 生存(在全上下文 199/199 失败的情况下实现 30 倍稳态压缩)。

billion-context sits between any agent and its model API, rewriting Anthropic/OpenAI streams with acp-kernel compression. The model decides when and what to compress into high-fidelity summaries — not a hard truncation limit.

billion-context 位于任何代理及其模型 API 之间,通过 acp-kernel 压缩重写 Anthropic/OpenAI 流。由模型决定何时以及将什么内容压缩为高保真摘要 — 而非硬性的截断限制。

Why Long coding sessions blow up context. Each provider charges per token, and once you pass the context window the session degrades or dies. billion-context compresses consumed conversation into layered summaries so you can run a single session for days — billions of tokens through one context window. Unlike a host’s built-in summarizer, compression here is incremental, reversible, and prefix-cache friendly: summaries are written in small ranges, can be decompressed on demand, and the cache prefix stays intact.

为什么长编码会话会撑爆上下文。每个提供商都按代币收费,一旦超过上下文窗口,会话就会降级或终止。billion-context 将已消耗的对话压缩为分层摘要,因此你可以运行单次会话数天 — 通过一个上下文窗口处理数十亿代币。与宿主内置的摘要器不同,此处的压缩是增量的、可逆的且对前缀缓存友好:摘要以小范围写入,可按需解压缩,且缓存前缀保持完整。

How it works Context-management tools The proxy injects four context-management tools into the conversation; the model calls them itself as context grows, and the proxy executes compress server-side so folded ranges stay summarized in history until restored: compress — fold a message range into a detailed summary. decompress — restore a compressed range when exact details are needed again. search_context — keyword search over compressed summaries and visible messages. acp_status — context-usage overview plus which ranges are still compressible.

工作原理 上下文管理工具 代理将四个上下文管理工具注入对话;随着上下文增长,模型会自动调用它们,代理在服务器端执行压缩,因此折叠的范围在历史记录中保持摘要状态,直到被恢复:compress — 将消息范围折叠为详细摘要。decompress — 当再次需要确切细节时恢复压缩范围。search_context — 对压缩摘要和可见消息进行关键字搜索。acp_status — 上下文使用概览以及哪些范围仍可压缩。

Which do I need? Pick by your client: Client Use pi billion-context — bili pi (launcher) or bili plugin install pi (native); standalone billion-context-pi remains usable — details: docs/clients.md opencode (1.x / 2.x) billion-context — bili opencode (launcher) or bili plugin install opencode (native); standalone opencode-acp remains usable on 1.x — full guide: OpenCode omp billion-context via bili omp (built-in plugin) or bili plugin install omp (self-spawning native plugin, no launcher) dsh bili dsh (launcher — full native plugin via —patch) or bili plugin install dsh ≡ dsh plugin —profile add billion-context (one unified lane) — details: docs/clients.md kimi bili plugin install kimi (self-spawning native, Kimi Code ≥ 2.0.0) or bili kimi (cert-MITM) or /bili/ prefix — details: docs/clients.md hermes bili plugin install hermes (self-spawning native, Python plugin #958) or bili hermes (cert-MITM) zcode (Z.ai / bigmodel coding plan) bili plugin install zcode (self-spawning native, #1145) or cert-MITM via the GUI’s Settings → Network or /bili/ prefix — details: docs/clients.md claude bili claude (launcher) or bili plugin install claude (native posture, #964 — managed settings block + session-owned proxy; see the notes below) codex bili codex (launcher — the full zero-config posture) or bili plugin install codex (MCP-shell tools companion: start bili first — the shell never spawns a proxy and never routes codex’s own traffic) — details: docs/clients.md jcode billion-context via bili jcode (cert-MITM) or /bili/ prefix — no native mode (compiled Rust binary, no plugin seam, #962) gemini (Gemini CLI) bili gemini (launcher, GOOGLE_GEMINI_BASE_URL /bili/ rewrite) or /bili/ prefix — launcher-only (no in-loop tool seam, #1043) iflow (iFlow CLI) bili iflow (launcher, IFLOW_BASE_URL /bili/ rewrite) or /bili/ prefix qwen (Qwen Code) bili qwen (launcher, cert-MITM) or /bili/ prefix antigravity (Antigravity CLI / agy, Google) bili antigravity (launcher, CLOUD_CODE_URL /bili/ rewrite of daily-cloudcode-pa.googleapis.com — Antigravity’s real default upstream, #3129) or /bili/ prefix — no plugin seam (closed Go language_server; its user-plugin surface is additive-only, #2115) — details: docs/clients.md mcode (MiniMax Code) billion-context via bili mcode (cert-MITM) or /bili/ prefix — no native mode (event hooks only, no model-request seam, #1050) aider billion-context via bili aider (cert-MITM) or /bili/ prefix — no native mode (shell-command-only hooks, no tool-injection seam, #1048) copilot (GitHub Copilot CLI) bili copilot (launcher, cert-MITM) — closed Go binary, no plugin seam (#1049) amp (Amp CLI) bili amp (launcher, cert-MITM) — closed Go binary, no plugin seam (#1049) kiro (Kiro CLI, AWS) bili kiro (launcher, cert-MITM) — Rust shell + Node agent server, no plugin seam; model traffic is the Responses wire on runtime.

我需要哪一个?根据你的客户端选择:客户端使用 pi billion-context — bili pi (启动器) 或 bili plugin install pi (原生);独立版 billion-context-pi 仍然可用 — 详情:docs/clients.md opencode (1.x / 2.x) billion-context — bili opencode (启动器) 或 bili plugin install opencode (原生);独立版 opencode-acp 在 1.x 上仍然可用 — 完整指南:OpenCode omp billion-context 通过 bili omp (内置插件) 或 bili plugin install omp (自启动原生插件,无启动器) dsh bili dsh (启动器 — 通过 —patch 实现完整原生插件) 或 bili plugin install dsh ≡ dsh plugin —profile add billion-context (统一通道) — 详情:docs/clients.md kimi bili plugin install kimi (自启动原生,Kimi Code ≥ 2.0.0) 或 bili kimi (cert-MITM) 或 /bili/ 前缀 — 详情:docs/clients.md hermes bili plugin install hermes (自启动原生,Python 插件 #958) 或 bili hermes (cert-MITM) zcode (Z.ai / bigmodel coding plan) bili plugin install zcode (自启动原生,#1145) 或通过 GUI 的 Settings → Network 使用 cert-MITM 或 /bili/ 前缀 — 详情:docs/clients.md claude bili claude (启动器) 或 bili plugin install claude (原生姿态,#964 — 管理设置块 + 会话所有代理;见下文注释) codex bili codex (启动器 — 完整零配置姿态) 或 bili plugin install codex (MCP-shell 工具伴侣:先启动 bili — shell 不会生成代理,也不会路由 codex 自身的流量) — 详情:docs/clients.md jcode billion-context 通过 bili jcode (cert-MITM) 或 /bili/ 前缀 — 无原生模式 (编译后的 Rust 二进制文件,无插件接口,#962) gemini (Gemini CLI) bili gemini (启动器,GOOGLE_GEMINI_BASE_URL /bili/ 重写) 或 /bili/ 前缀 — 仅启动器 (无循环内工具接口,#1043) iflow (iFlow CLI) bili iflow (启动器,IFLOW_BASE_URL /bili/ 重写) 或 /bili/ 前缀 qwen (Qwen Code) bili qwen (启动器,cert-MITM) 或 /bili/ 前缀 antigravity (Antigravity CLI / agy, Google) bili antigravity (启动器,CLOUD_CODE_URL /bili/ 重写 daily-cloudcode-pa.googleapis.com — Antigravity 的真实默认上游,#3129) 或 /bili/ 前缀 — 无插件接口 (闭源 Go 语言服务器;其用户插件表面仅为附加型,#2115) — 详情:docs/clients.md mcode (MiniMax Code) billion-context 通过 bili mcode (cert-MITM) 或 /bili/ 前缀 — 无原生模式 (仅事件钩子,无模型请求接口,#1050) aider billion-context 通过 bili aider (cert-MITM) 或 /bili/ 前缀 — 无原生模式 (仅 shell 命令钩子,无工具注入接口,#1048) copilot (GitHub Copilot CLI) bili copilot (启动器,cert-MITM) — 闭源 Go 二进制文件,无插件接口 (#1049) amp (Amp CLI) bili amp (启动器,cert-MITM) — 闭源 Go 二进制文件,无插件接口 (#1049) kiro (Kiro CLI, AWS) bili kiro (启动器,cert-MITM) — Rust shell + Node 代理服务器,无插件接口;模型流量为运行时的 Responses 线。