context-compression
Design and evaluate compression strategies for long-running sessions
Author
Category
Development ToolsInstall
Hot:1
Download and extract to your skills directory
Copy command and send to OpenClaw for auto-install:
Download and install this skill https://openskills.cc/api/download?slug=sickn33-skills-context-compression&locale=en&source=copy
Context Compression - AI Agent Context Compression Strategy
Skill Overview
Context Compression is a context compression strategy skill specifically designed for long-running AI agent sessions. It helps developers design and evaluate effective compression methods that minimize token consumption while preserving critical information.
Applicable Scenarios
1. Ultra-long Session Management
When an AI agent session generates millions of tokens of conversation history, compression becomes essential. This skill provides three production-ready compression methods—anchored iterative summarization, opaque compression, and regenerative full summarization—to help you find the best balance between information retention and token savings.
2. Large Codebase Analysis
When handling large codebases that exceed the context window limit (5M+ token systems), this skill offers a three-stage compression workflow: research phase generates architecture analysis documents, planning phase converts them into implementation specifications, and implementation phase executes based on the specifications—compressing massive code into an approximately 2,000-word actionable specification.
3. Compression Quality Evaluation
When building an evaluation framework to test compression quality, this skill provides a probe-based evaluation method that directly measures functional quality via four types of questions—recall, tracking, continuation, and decision—more accurately reflecting compression effectiveness than traditional ROUGE or embedding-similarity metrics.
Core Features
1. Structured Summary Design
Provides clear summary structure templates including session intent, file modifications, decision records, current status, and next actions. By enforcing structure, it prevents silent loss of critical information. Studies show structured summaries can increase compression quality by 0.35 points (out of 5) while only using an additional 0.7% tokens.
2. Compression Trigger Strategies
Supports multiple compression trigger strategies: fixed threshold (70–80% context utilization), sliding window (keep the most recent N turns + summary), importance-based (prioritize compressing low-relevance parts), and task-boundary (compress when a logical task is completed). Sliding window combined with structured summaries provides the best balance in most coding scenarios.
3. Artifact Tracking Solution
Identifies and addresses artifact-tracking issues—the weakest dimension across compression methods (scoring only 2.2–2.5/5.0). Provides an independent artifact index or explicit file-state tracking scheme to ensure the AI agent knows which files were created, modified, or read, including technical details like function names, variable names, and error messages.
Frequently Asked Questions
What is tokens-per-task, and why is it more important than tokens-per-request?
tokens-per-request only measures the token count for a single request, but if compression loses critical information (such as file paths or error messages), the agent must re-acquire information and re-explore solutions, wasting more tokens. tokens-per-task measures the total token consumption from task start to completion, including re-acquisition costs—that is the correct optimization target. A compression strategy that saves 0.5% tokens but causes 20% more re-acquisition is actually more expensive.
Which scenarios are suitable for the three compression methods?
Anchored iterative summarization is suitable for long-running sessions (100+ messages), scenarios needing file tracking (coding, debugging), and when you need to verify what was retained. Opaque compression is suitable when maximal token savings are required, sessions are relatively short, and re-acquisition costs are low. Regenerative summarization is suitable when summary interpretability is critical, sessions have clear phase boundaries, and each compression can accept full-context review.
How do you evaluate whether context compression quality is good enough?
Use a probe-based evaluation method: after compression, ask the agent four types of questions—recall ("What was the original error message?"), tracking ("Which files did we modify?"), continuation ("What should we do next?"), and decision ("What did we decide about the Redis issue?"). If the agent answers correctly, compression retained the correct information; if it guesses or hallucinates, key content was lost. Also monitor six dimensions: accuracy, context awareness, artifact tracking, integrity, continuity, and instruction adherence.