当用户要求“压缩上下文”、“总结对话历史记录”、“实施压缩”、“减少令牌使用”或提及上下文压缩、结构化摘要、每个任务令牌优化或超出上下文限制的长时间运行代理会话时,应使用此技能。
数据来源:ClawHub。 在 ClawSkills 查看
选择你使用的 Agent
方法一:命令行安装(推荐)
推荐(无需提前安装 clawhub)
npx clawhub@latest --dir ~/.claude/skills install context-engineering或使用 clawhub CLI(需提前安装)
clawhub --dir ~/.claude/skills install context-engineering⚠️ 需要 Node.js 18+,没有 Node?请使用下方方法二直接下载 ZIP。 安装 Node.js →
方法二:手动下载安装(无需 Node)
下载 ZIP,解压后将文件夹放到以下路径,重启 Agent 即可:
安装路径
~/.claude/skills/context-engineering/💡解压后将文件夹放到上方路径,重启 Agent 即可生效
--- name: context-compression description: This skill should be used when the user asks to "compress context", "summarize conversation history", "implement compaction", "reduce token usage", or mentions context compression, structured summarization, tokens-per-task optimization, or long-running agent sessions exceeding context limits. ---
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.
Activate this skill when:
Context compression trades token savings against information loss. Three production-ready approaches exist:
The critical insight: structure forces preservation. Dedicated sections act as checklists that the summarizer must populate, preventing silent information drift.
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.
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:
This problem likely requires specialized handling beyond general summarization: a separate artifact index or explicit file-state tracking in agent scaffolding.
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.
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.
Traditional metrics like ROUGE or embedding similarity fail to capture functional compression quality. A summary may score high on lexical overlap while missing the one file path the agent needs.
Probe-based evaluation directly measures functional quality by asking questions after compression:
| Probe Type | What It Tests | Example Question | |------------|---------------|------------------| | Recall | Factual retention | "What was the original error message?" | | Artifact | File tracking | "Which files have we modified?" | | Continuation | Task planning | "What should we do next?" | | Decision | Reasoning chain | "What did we decide about the Redis issue?" |
If compression preserved the right information, the agent answers correctly. If not, it guesses or hallucinates.
Six dimensions capture compression quality for coding agents:
Accuracy shows the largest variation between compression methods (0.6 point gap). Artifact trail is universally weak (2.2-2.5 range).
For large codebases or agent systems exceeding context windows, apply compression through three phases:
When provided with a manual migration example or reference PR, use it as a template to understand the target pattern. The example reveals constraints that static analysis cannot surface: which invariants must hold, which services break on changes, and what a clean migration looks like.
This is particularly important when the agent cannot distinguish essential complexity (business requirements) from accidental complexity (legacy workarounds). The example artifact encodes that distinction.
...
安装 情境工程代理技能 后,可以对 AI 说这些话来触发它
Help me get started with Agent-Skills-for-Context-Engineering
Explains what Agent-Skills-for-Context-Engineering does, walks through the setup, and runs a quick demo based on your current project
Use Agent-Skills-for-Context-Engineering to this skill should be used when the user asks to "compress context",...
Invokes Agent-Skills-for-Context-Engineering with the right parameters and returns the result directly in the conversation
What can I do with Agent-Skills-for-Context-Engineering in my ai agent & automation workflow?
Lists the top use cases for Agent-Skills-for-Context-Engineering, with example commands for each scenario
将技能文件夹放到 ~/.claude/skills/context-engineering/ 目录(个人级,所有项目可用),或 .claude/skills/context-engineering/(项目级)。重启 AI 客户端后,用 /context-engineering 主动调用,或让 AI 根据上下文自动发现并使用。
情境工程代理技能 支持 Claude、Cursor、OpenClaw,可与这些 AI 平台无缝集成,扩展其能力。
情境工程代理技能 可免费安装使用。请查阅仓库了解许可证信息。
当用户要求“压缩上下文”、“总结对话历史记录”、“实施压缩”、“减少令牌使用”或提及上下文压缩、结构化摘要、每个任务令牌优化或超出上下文限制的长时间运行代理会话时,应使用此技能。
情境工程代理技能 属于「AI Agent & Automation」分类,该分类的技能帮助 AI 智能体在此领域执行专业任务。
Automate my ai agent & automation tasks using Agent-Skills-for-Context-Engineering
Identifies repetitive steps in your workflow and sets up Agent-Skills-for-Context-Engineering to handle them automatically