context-compressor
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseContext Compressor Protocol
上下文压缩器协议
Reduce content by 70% — preserve critical information, discard repetition and noise. Target: compressed output should be ~30% of original size with preserved information density.
可将内容压缩70%——保留关键信息,去除重复内容与冗余信息。目标:压缩后的输出大小约为原始内容的30%,同时保持信息密度。
Workflow
工作流程
1. Detect content type
2. Mark critical elements (these are never discarded)
3. Apply type-specific compression
4. Verify 70% target
5. Present compressed output1. 检测内容类型
2. 标记关键元素(这些内容绝不会被丢弃)
3. 应用针对特定类型的压缩规则
4. 验证70%的压缩目标
5. 输出压缩后的内容Step 1: Detect Content Type
步骤1:检测内容类型
| Content Type | Detection Criteria |
|---|---|
| Conversation history | User/assistant message pairs |
| Code file | Function/class structures, syntax |
| Research results | URLs, source references, data points |
| Meeting notes / document | Headers, bullet lists, decisions |
| 内容类型 | 检测标准 |
|---|---|
| 对话历史 | 用户/助手的消息配对 |
| 代码文件 | 函数/类结构、语法特征 |
| 研究成果 | 网址、来源引用、数据点 |
| 会议纪要/文档 | 标题、项目符号列表、决策内容 |
Step 2: Mark Critical Elements
步骤2:标记关键元素
These elements are never discarded:
- Decisions & conclusions: "We decided to use X", "Y was chosen"
- Errors & fixes: Discovered bugs, applied solutions
- Numerical data: Dates, version numbers, metrics, amounts
- Dependencies: "A must finish before B" constraints
- Action items: Who does what, when
- Current state: Latest version, current config, last decision
以下内容绝不会被丢弃:
- 决策与结论:如“我们决定使用X”、“选择了Y”
- 错误与修复方案:已发现的bug、已应用的解决方案
- 数值数据:日期、版本号、指标、金额
- 依赖关系:如“A必须在B之前完成”的约束条件
- 行动项:责任人、任务内容、截止时间
- 当前状态:最新版本、当前配置、最终决策
Step 3: Type-Specific Compression
步骤3:针对特定类型的压缩规则
Conversation History
对话历史
Discard: Greetings, acknowledgments ("OK", "Got it", "Thanks"), repeated explanations, intermediate reasoning that contradicts the final conclusion.
Keep: User's clear requests, decisions and rationale, error messages and fixes, current task status.
Format:
[CONVERSATION SUMMARY — N messages -> M lines]
Context: [what the task is, 1 sentence]
Decisions: [bullet list]
Current status: [where things stand]
Pending: [open questions if any]需丢弃的内容:问候语、确认语(如“好的”、“明白了”、“谢谢”)、重复的解释、与最终结论矛盾的中间推理过程。
需保留的内容:用户明确的请求、决策及其依据、错误信息与修复方案、当前任务状态。
格式:
[对话总结 — 原N条消息 → 现M行]
上下文:[任务内容,1句话]
决策:[项目符号列表]
当前状态:[进展情况]
待处理:[如有未解决的问题]Code File
代码文件
Discard: Comments (except docstrings), excessive blank lines, long import lists (consolidate), temporary debug prints.
Keep: All function/class signatures (with parameters), return types and critical type annotations, exception handling, configuration constants. Summarize function bodies as single-line pseudocode.
Format:
python
undefined需丢弃的内容:注释(文档字符串除外)、过多的空行、冗长的导入列表(合并处理)、临时调试打印语句。
需保留的内容:所有函数/类的签名(含参数)、返回类型与关键类型注解、异常处理逻辑、配置常量。将函数体总结为单行伪代码。
格式:
python
undefined[COMPRESSED — original: ~N lines -> now: ~M lines]
[已压缩 — 原约N行 → 现约M行]
class ClassName:
"""[Original docstring]"""
def method_name(self, param: Type) -> ReturnType:
# [What it does — 1 line summary]
...
undefinedclass ClassName:
"""[原始文档字符串]"""
def method_name(self, param: Type) -> ReturnType:
# [功能描述 — 1行总结]
...
undefinedResearch / Web Results
研究/网页结果
Discard: Duplicate information, generic background, verbose URLs (use domain name), out-of-scope quotes.
Keep: Concrete data points, primary source findings, contradictory findings (keep both), directly relevant findings.
Format:
[RESEARCH SUMMARY — N sources -> M items]
Topic: [what was researched]
Key findings:
- [Finding 1] (Source: domain.com)
- [Finding 2] (Source: domain.com)
Contradictions:
- [Source A says X, Source B says Y]
Missing / unverified:
- [Information not found]需丢弃的内容:重复信息、通用背景内容、冗长的URL(仅保留域名)、与主题无关的引用内容。
需保留的内容:具体数据点、主要研究发现、矛盾的研究结果(需同时保留双方内容)、直接相关的研究结论。
格式:
[研究总结 — 原N个来源 → 现M项内容]
主题:[研究主题]
关键发现:
- [发现1](来源:domain.com)
- [发现2](来源:domain.com)
矛盾点:
- [来源A称X,来源B称Y]
缺失/未验证内容:
- [未找到的信息]Documents / Meeting Notes
文档/会议纪要
Discard: Intro/closing paragraphs (if no content), repetitive statements, generic commentary.
Keep: Decisions made, action items (who, what, when), alternatives discussed and why rejected, next steps.
需丢弃的内容:引言/结尾段落(若无实质内容)、重复表述、通用评论。
需保留的内容:已做出的决策、行动项(责任人、任务、时间)、讨论过的备选方案及被否决的原因、后续步骤。
Step 4: Verify 70% Target
步骤4:验证70%的压缩目标
Original size : ~N words / lines / tokens
Compressed size : ~M words / lines / tokens
Compression : ~X% reduction
Target: 70% [Achieved / Below target]If below target (< 50% reduction): re-scan for repetition, compress background more aggressively, convert long examples to single-line references.
原始大小 : 约N个单词/行/令牌
压缩后大小 : 约M个单词/行/令牌
压缩率 : 约X%的缩减比例
目标:70% [已达成/未达成]若未达成目标(缩减比例<50%):重新扫描重复内容,更激进地压缩背景信息,将长示例转换为单行引用。
Output Header
输出头部
Every compression starts with:
CONTEXT COMPRESSOR
Type : [content type]
Before : ~N [words/lines]
After : ~M [words/lines]
Saving : ~X% reduction每次压缩的输出均以以下内容开头:
CONTEXT COMPRESSOR
类型 : [内容类型]
压缩前 : 约N个[单词/行]
压缩后 : 约M个[单词/行]
节省占比: 约X%的缩减比例When to Skip
跳过压缩的场景
- Content is already short (< 200 words / 50 lines)
- User said "all details matter"
- Legal, medical, or financial documents (information loss risk too high)
- 内容本身已较短(<200单词/50行)
- 用户明确表示“所有细节都很重要”
- 法律、医疗或金融类文档(信息丢失风险过高)
Guardrails
约束规则
- Never discard decisions or error resolutions — these are the most valuable context.
- Preserve contradictions — if two sources disagree, keep both.
- Show compression ratio — the user must see how much was removed.
- Cross-skill: works with (can compress ledger entries) and
memory-ledger(provides compressed history for retrospective).agent-reviewer
- 绝不能丢弃决策或错误解决方案——这些是最有价值的上下文信息。
- 保留矛盾内容——若两个来源观点不一致,需同时保留双方内容。
- 显示压缩比例——用户必须知晓被移除内容的占比。
- 跨技能兼容:可与(可压缩分类账条目)和
memory-ledger(为回顾提供压缩后的历史记录)配合使用。agent-reviewer