Billion-context: layered compression lets agents restore billion-token history
Unlike one-shot summaries, restoring original content on demand means day-one decisions remain traceable after weeks-long sessions with multiple refactors — no detail is permanently lost to compression. Developers running long-horizon coding or tool-using agents can adopt it across Claude Code, Codex, OpenCode and DeepSeek Harness to cut token costs while keeping history searchable.
The billion-context approach lets an agent compress, search and restore its own conversation history instead of relying on one-shot summarisation. It applies incremental layered compression, folding old messages into summaries while keeping the original content. A decompress function restores raw content on demand, and search_context retrieves relevant compressed summaries before recovery. Prompt Cache prefix stability is preserved to reduce recomputation and token cost. It works with coding agents including Claude Code, Codex, OpenCode and DeepSeek Harness.
让Agent自己压缩、搜索、恢复历史上下文,用有限的窗口支撑十亿Token级别的累计会话
billion-context:解决长时运行时上下文爆满、Token成本高,以及压缩后丢失关键历史信息的问题
跟一次性摘要式压缩最大的区别是历史可恢复
其思路是把历史对话分层压缩,同时保留原始内容,让模型在需要时再搜索、恢复特定片段,让有限窗口通过持续压缩与恢复,来支撑十亿级Token的长会话
首先增量分层压缩:Agent可以主动选择压缩哪些历史消息,将旧上下文折叠为摘要,而不是反复压缩整段对话
按需恢复:需要追溯早期决策、代码修改或工具调用时,可以通过decompress恢复原始内容
历史搜索:通过search_context检索压缩摘要和当前可见消息,找到相关历史后再按需恢复原始内容
Prompt Cache优化:尽量保持缓存前缀稳定,减少重复计算和Token成本
举个例子,AI连续开发了一个项目数周,中途经历多次重构,第十天需要追溯第一天为什么选择某个数据库架构,可以搜索历史并恢复当时的原始讨论,而不是只能依赖一段可能遗漏细节的压缩摘要
支持面比较广,Claude Code、Codex、OpenCode、DeepSeek Harness等Coding Agent都适用
#AI上下文扩展 #billioncontext #AIcontext