context-compression
Skill này làm gì
Skill này giúp AI của bạn quản lý các cuộc trò chuyện rất dài. Nó tóm tắt các phần công việc đã xong và giữ lại các quyết định quan trọng. Dành cho người chạy các phiên dài mà AI bắt đầu mất dấu.
Khi nào nên dùng
- ✓Khi cuộc trò chuyện đã dài hơn khoảng hai mươi đến ba mươi lượt.
- ✓Khi AI bắt đầu lặp lại các gợi ý trước đó hoặc quên các quyết định.
- ✓Khi bạn hoàn thành một giai đoạn công việc và muốn chuyển sang giai đoạn khác.
Liên kết skill
https://github.com/vudovn/ag-kit/blob/main/.agents/skills/context-compression/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Cuộc trò chuyện này đã rất dài và chúng ta cứ lặp lại. Hãy tóm tắt những gì chúng ta đã hoàn thành và giữ các quyết định chính.”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill thay thế các đầu ra công cụ dài và công việc đã xong bằng các bản tóm tắt ngắn. Các quyết định chính được giữ lại để AI có thể tiếp tục làm việc mà không mất ngữ cảnh.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
Context Compression — Long Session Management
Keep sessions productive by compressing completed work while preserving key decisions.
Overview
Long sessions (30+ turns) cause context degradation — the AI loses track of earlier work, repeats itself, or forgets decisions. Context compression proactively summarizes completed phases so the context window stays focused on active work.
Token Impact: Recovers 5,000-15,000 tokens in long sessions by replacing verbose tool outputs with semantic summaries.
When to Compress
| Signal | Action |
|---|---|
| Session has 20+ turns | Consider proactive compression |
| Agent repeats earlier suggestions | Context is saturated — compress now |
| User says "we already discussed this" | Compress immediately |
| Switching to a new phase of work | Compress the completed phase |
| Large tool output (500+ lines) | Micro-compact the output |
Compression Levels
Level 1: Micro-Compact (Tool Output)
Compress individual tool outputs while retaining semantic content:
❌ Before (raw grep output — 200 lines, ~4,000 tokens):
src/auth/jwt.ts:15: import { verify } from 'jsonwebtoken'
src/auth/jwt.ts:23: export function validateToken(token: string) {
src/auth/jwt.ts:24: try {
src/auth/jwt.ts:25: const decoded = verify(token, SECRET)
... (195 more lines)
✅ After (micro-compact — 5 lines, ~100 tokens):
Grep results for "jwt": Found 8 files, 42 matches.
Key files: src/auth/jwt.ts (main JWT logic), src/middleware/auth.ts (middleware),
src/api/login.ts (token creation). Token validation at jwt.ts:23-40.
Error handling at jwt.ts:42-55. Secret loaded from env at jwt.ts:8.
Level 2: Phase Summary
Replace a completed work phase with a summary:
❌ Before (full research transcript — ~3,000 tokens):
[turn 1] Read package.json...
[turn 2] Read src/index.ts...
[turn 3] Grep for "auth"...
[turn 4] Found 8 files related to auth...
[turn 5] Read src/auth/jwt.ts...
... (10 more turns of exploration)
✅ After (phase summary — ~200 tokens):
## Research Phase Complete
- Project: Next.js 15 app with JWT auth
- Auth files: 8 files in src/auth/, src/middleware/, src/api/
- Token flow: login → create JWT → store in httpOnly cookie → validate in middleware
- Bug location: src/auth/jwt.ts:45 — expiry check uses `<` instead of `<=`
- Decision: Fix the comparison operator, add edge case test
Level 3: Session Checkpoint
Full session summary for long-running work:
## Session Checkpoint (Turn 35)
### Completed
- [x] Researched auth system (8 files, JWT flow mapped)
- [x] Fixed token expiry bug in jwt.ts:45
- [x] Added edge case test in jwt.test.ts
- [x] Verified: all 42 tests passing
### In Progress
- [ ] Update API documentation
- [ ] Review related middleware
### Key Decisions
1. Keep httpOnly cookies (not localStorage) for token storage
2. Use `<=` for expiry check to include exact-moment expiry
3. Add 5-minute grace period for clock skew
### Files Modified
- src/auth/jwt.ts (line 45: comparison fix)
- tests/auth/jwt.test.ts (added 3 edge case tests)
Compression Protocol
Step 1: Identify Completed Phases
What work is DONE and won't be revisited?
→ Research findings already synthesized
→ Implementation already verified
→ Decisions already made and applied
Step 2: Extract Key Information
From the completed phase, preserve:
✅ Decisions made and WHY
✅ File paths and line numbers of changes
✅ Key findings that inform ongoing work
✅ Error messages or test results (summarized)
Discard:
❌ Step-by-step tool invocation details
❌ Full file contents that were read
❌ Exploratory dead-ends that didn't lead anywhere
❌ Verbose error stack traces (keep the message only)
Step 3: Write Summary
Use the Phase Summary format above.
Keep to 100-300 tokens per completed phase.
Include enough detail to resume work without re-reading.
Best Practices
- Compress phases, not facts — Individual decisions should stay, full transcripts should go
- Preserve "why" over "what" — Why a decision was made matters more than the exact commands run
- Never auto-compress — Always tell the user "I'm summarizing the completed research phase to keep context focused"
- Keep file references — Always preserve file paths and line numbers in summaries
- Checkpoint on phase transitions — Natural compression point when switching from research to implementation
Câu hỏi thường gặp
Khi nào tôi nên yêu cầu nén?
Dùng khi phiên dài, khi AI lặp lại chính nó hoặc khi bạn chuyển sang giai đoạn công việc mới.
Nó có làm mất các quyết định quan trọng không?
Skill được thiết kế để giữ các quyết định chính trong khi tóm tắt phần còn lại.
Nó giúp được bao nhiêu?
Nó nhằm giải phóng chỗ trong các phiên dài, và mức tiết kiệm phụ thuộc vào từng phiên.
Chi tiết
Mô tả gốc của tác giả
Manage and compress conversation context in long sessions. Detect when context is growing large, summarize completed work phases, archive old findings while preserving key decisions. Prevents context degradation.
repo: vudovn/ag-kit
Độ phổ biến
- Sao GitHub
- 8.2k
- Vị trí xếp hạng
- #12529
- Giấy phép
- MIT
- Cập nhật
- 18/10/2026
Bình luận
- …
Thêm skill từ kho mã này
batch-operations
8.2kGiúp agent của bạn thực hiện cùng một thay đổi trên nhiều file cùng lúc, như đổi tên một hàm hoặc thay một import cũ ở khắp nơi.
brainstorming
8.2kDạy agent của bạn đặt câu hỏi làm rõ trước khi xây dựng bất cứ thứ gì mới hoặc phức tạp, để agent hiểu mục tiêu của bạn trước.
code-review-checklist
8.2kCung cấp cho agent của bạn một danh sách kiểm tra để rà soát mã về tính đúng đắn, bảo mật, hiệu năng, kiểm thử và tài liệu, kể cả rủi ro riêng của AI.
code-review-graph
8.2kGiúp agent của bạn rà soát mã trong dự án lớn bằng một bản đồ cấu trúc, để nó chỉ đọc các file bị ảnh hưởng bởi một thay đổi.
Skill tương tự
add-model-provider
394kGiúp agent của bạn kết nối nhà cung cấp mô hình AI mới với OpenClaw bằng lệnh an toàn, giữ API key khỏi văn bản thuần và chạy thử.
acp-router
394kGiúp agent của bạn gửi một tác vụ đến trợ lý lập trình như Claude Code hoặc Cursor qua OpenClaw, để công việc chạy ngay trong công cụ đó.
browser-automation
394kHướng dẫn agent của bạn điều khiển trang web từng bước, gồm đăng nhập, tab và cách khôi phục khi trang ngừng phản hồi.