跳到正文
Skillpedia
智能体48k · #4249

context-compression

它能做什么

这个工具可以帮助 AI 记住很长的对话。它会总结其中最重要的部分,避免 AI 跟丢信息,让它专注于完成任务所需的关键内容。

适用场景

  • ✓当你和 AI 的对话变得很长,它开始忘记信息时。
  • ✓当你处理大型代码项目,而 AI 无法一次“看到”全部内容时。
  • ✓当你想生成对话摘要,供 AI 随时回顾时。

技能链接

https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-compression/SKILL.md

复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。

使用方法

最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。

可直接粘贴的消息

请用这个技能帮我:https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-compression/SKILL.md 阅读该链接中的 SKILL.md 文件,并在我的任务中按照它的说明来做。
想让你的 AI 自己找到这样的技能吗?安装免费的 Skillpedia MCP:只需一行,每次任务前它都会在 15,000+ 个技能中搜索。1 分钟完成安装 →

可以这样问 AI

“AI,请总结一下我们目前的对话,重点说明文件修改和已经做出的决定。”

每周 5 个新技能,1 分钟读完。

工作原理

AI 会生成结构化的摘要,保留重要信息,比如你的意图、修改过的文件和后续步骤。如果对话变得很长,它会先总结新的部分,再把它与旧的摘要合并。

技术内容(原始 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 Use

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

Core Concepts

Context compression trades token savings against information loss. Three production-ready approaches exist:

  1. Anchored Iterative Summarization: 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. Structure forces preservation by dedicating sections to specific information types.

  2. Opaque Compression: Produce compressed representations optimized for reconstruction fidelity. Achieves highest compression ratios (99%+) but sacrifices interpretability. Cannot verify what was preserved.

  3. Regenerative Full Summary: Generate detailed structured summaries on each compression. Produces readable output but may lose details across repeated compression cycles due to full regeneration rather than incremental merging.

The critical insight: structure forces preservation. Dedicated sections act as checklists that the summarizer must populate, preventing silent information drift.

Detailed Topics

Why Tokens-Per-Task Matters

Traditional compression metrics target tokens-per-request. This is the wrong optimization. When compression loses critical details like file paths or error messages, the agent must re-fetch information, re-explore approaches, and waste tokens recovering context.

The right metric is tokens-per-task: total tokens consumed from task start to completion. A compression strategy saving 0.5% more tokens but causing 20% more re-fetching costs more overall.

The Artifact Trail Problem

Artifact trail integrity is the weakest dimension across all compression methods, scoring 2.2-2.5 out of 5.0 in evaluations. Even structured summarization with explicit file sections struggles to maintain complete file tracking across long sessions.

Coding agents need to know:

  • Which files were created
  • Which files were modified and what changed
  • Which files were read but not changed
  • Function names, variable names, error messages

This problem likely requires specialized handling beyond general summarization: a separate artifact index or explicit file-state tracking in agent scaffolding.

Structured Summary Sections

Effective structured summaries include explicit sections:

## Session Intent
[What the user is trying to accomplish]

## Files Modified
- auth.controller.ts: Fixed JWT token generation
- config/redis.ts: Updated connection pooling
- tests/auth.test.ts: Added mock setup for new config

## Decisions Made
- Using Redis connection pool instead of per-request connections
- Retry logic with exponential backoff for transient failures

## Current State
- 14 tests passing, 2 failing
- Remaining: mock setup for session service tests

## Next Steps
1. Fix remaining test failures
2. Run full test suite
3. Update documentation

This structure prevents silent loss of file paths or decisions because each section must be explicitly addressed.

Compression Trigger Strategies

When to trigger compression matters as much as how to compress:

Strategy Trigger Point Trade-off
Fixed threshold 70-80% context utilization Simple but may compress too early
Sliding window Keep last N turns + summary Predictable context size
Importance-based Compress low-relevance sections first Complex but preserves signal
Task-boundary Compress at logical task completions Clean summaries but unpredictable timing

The sliding window approach with structured summaries provides the best balance of predictability and quality for most coding agent use cases.

Probe-Based Evaluation

…

常见问题

为什么 “token” 很重要?

Token 可以理解为 AI 用来理解和生成文本的词或词的片段。很长的对话会消耗大量 token,而这个工具可以在不丢失关键信息的前提下,帮你减少 token 的用量。

AI 会忘记它修改过哪些文件吗?

会的,在非常长的对话中可能发生这种情况。这个工具会尽量保留一份清晰的修改文件记录,防止 AI 迷失。

使用这个工具的最佳方式是什么?

当对话越来越长,或者你需要 AI 记住大型项目中的特定细节时,就可以使用它。结构化的摘要能帮助 AI 保持专注。

详情

作者的原始描述

When agent sessions generate millions of tokens of conversation history, compression becomes mandatory. The naive approach is aggressive compression to minimize tokens per request.

repo: sickn33/agentic-awesome-skills

热度

GitHub 星标
48k
排名
#4249
许可证
MIT
更新时间
2026/10/15

这个技能有用吗?

0

登录 后即可投票。

评论

  • …

同一仓库的更多技能

相似技能