context-compression
它能做什么
这个技能说明如何把很长的智能体对话压缩成较短的摘要,同时不丢失重要的决策、文件和下一步。适合进行长时间 AI 会话或把工作交给另一个智能体的人。
适用场景
- ✓当一次很长的 AI 会话即将耗尽空间,需要摘要时。
- ✓当智能体忘记了它改过哪些文件,或早先做出了什么决定时。
- ✓当你需要交接摘要,让另一个智能体能够继续工作时。
技能链接
https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/main/skills/context-compression/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“请总结这段很长的编程会话,以便新的智能体能够接手工作,而不丢失我们已经做出的决定。”
每周 5 个新技能,1 分钟读完。
工作原理
该技能说明如何撰写结构化的摘要,保留决策、已修改的文件、风险和后续行动,并检查该摘要是否仍然有效。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
Context Compression Strategies
When agent sessions generate millions of tokens of conversation history, compression becomes mandatory. The naive approach is aggressive compression to minimize tokens per request. The correct optimization target is tokens per task: total tokens consumed to complete a task, including re-fetching costs when compression loses critical information.
When to Activate
Activate this skill when:
- Agent sessions exceed context window limits
- Codebases exceed context windows (5M+ token systems)
- Designing conversation summarization strategies
- Debugging cases where agents "forget" what files they modified
- Building evaluation frameworks for compression quality
- Creating durable handoff summaries that preserve decisions, files, risks, and next actions
Do not activate this skill for adjacent work owned by other skills:
- General token-efficiency tactics such as masking, prefix caching, or partitioning:
context-optimization. - Diagnosing why a long context is failing before choosing a mitigation:
context-degradation. - Writing raw outputs, logs, or plans to files without summarizing them:
filesystem-context. - Designing long-term semantic memory across sessions:
memory-systems. - The model deciding when and where to rewrite its own context:
self-managed-context. This skill still owns what the replacement text must preserve.
Core Concepts
Context compression trades token savings against information loss. Select from three production-ready approaches based on session characteristics:
Anchored Iterative Summarization: Implement this for long-running sessions where file tracking matters. Maintain structured, persistent summaries with explicit sections for session intent, file modifications, decisions, and next steps. When compression triggers, summarize only the newly-truncated span and merge with the existing summary rather than regenerating from scratch. This prevents drift that accumulates when summaries are regenerated wholesale — each regeneration risks losing details the model considers low-priority but the task requires. Structure forces preservation because dedicated sections act as checklists the summarizer must populate, catching silent information loss.
Opaque Compression: Reserve this for short sessions where re-fetching costs are low and maximum token savings are required. It produces compressed representations optimized for reconstruction fidelity, achieving 99%+ compression ratios but sacrificing interpretability entirely. The tradeoff matters: there is no way to verify what was preserved without running probe-based evaluation, so never use this when debugging or artifact tracking is critical.
Regenerative Full Summary: Use this when summary readability is critical and sessions have clear phase boundaries. It generates detailed structured summaries on each compression trigger. The weakness is cumulative detail loss across repeated cycles — each full regeneration is a fresh pass that may deprioritize details preserved in earlier summaries.
Detailed Topics
Optimize for Tokens-Per-Task, Not Tokens-Per-Request
Measure total tokens consumed from task start to completion, not tokens per individual request. When compression drops file paths, error messages, or decision rationale, the agent must re-explore, re-read files, and re-derive conclusions — wasting far more tokens than the compression saved. A strategy saving 0.5% more tokens per request but causing 20% more re-fetching costs more overall. Track re-fetching frequency as the primary quality signal: if the agent repeatedly asks to re-read files it already processed, compression is too aggressive.
Solve the Artifact Trail Problem First
Artifact trail integrity is often the weakest dimension in compression evaluations (claim-context-compression-factory-benchmark). Address this proactively because general summarization cannot reliably maintain it.
Preserve these categories explicitly in every compression cycle:
- Which files were created (full paths)
- Which files were modified and what changed (include function names, not just file names)
- Which files were read but not changed
- Specific identifiers: function names, variable names, error messages, error codes
Implement a separate artifact index or explicit file-state tracking in agent scaffolding rather than relying on the summarizer to capture these details. Even structured summarization with dedicated file sections st
常见问题
好的摘要应该保留什么?
已做出的决定、修改过的文件、尚存的风险以及后续行动。
为什么不直接把所有内容都缩短?
该技能的目标是减少每个完成任务的总 token 数,因为丢失的细节可能迫使智能体重复工作。
这和长期记忆一样吗?
不一样。它侧重于总结单次会话,而跨会话的记忆是另一个话题。
详情
作者的原始描述
This skill should be used when long-running agent sessions need context compression, structured summarization, compaction, token-per-task optimization, or durable handoff summaries that preserve decisions, files, risks, and next actions.
热度
- GitHub 星标
- 18k
- 排名
- #10637
- 许可证
- MIT
- 更新时间
- 2026/10/11
评论
- …
同一仓库的更多技能
context-engineering-collection
18k帮你的智能体管理输入 AI 模型上下文窗口的内容,涵盖记忆、工具、多智能体配置以及评估。
advanced-evaluation
18k教你的智能体如何用另一个 AI 来评判 AI 的回答,包括打分、并排比较和偏差检查。
bdi-mental-states
18k教你的智能体用 BDI 方法对信念、目标和计划进行建模,使其决策可以被追溯和解释。
context-degradation
18k帮你的智能体发现并修复 AI 在长对话中回答变差的问题,例如细节在中间丢失。