context-window-management
Skill này làm gì
Công cụ này giúp AI quản lý lượng thông tin nó có thể “nhớ” trong một cuộc trò chuyện. Nó dùng các kỹ thuật như tóm tắt, cắt bớt hoặc ưu tiên điều quan trọng nhất để AI không bị lạc trong các cuộc trò chuyện dài.
Khi nào nên dùng
- ✓Khi bạn có một cuộc trò chuyện rất dài với AI và thấy nó bắt đầu quên những gì đã nói trước đó.
- ✓Khi xây dựng hệ thống mà AI cần duy trì ngữ cảnh từ nhiều tương tác trước đó.
- ✓Khi bạn muốn AI luôn xem xét thông tin quan trọng nhất, kể cả khi cuộc trò chuyện kéo dài.
Liên kết skill
https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-window-management/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
“Làm sao để AI nhớ các chi tiết quan trọng từ một cuộc trò chuyện đã kéo dài hàng giờ?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
AI phân tích lượng văn bản nó có thể xử lý cùng lúc (gọi là “context window”). Nếu cuộc trò chuyện quá dài, nó dùng các chiến lược để tóm tắt phần cũ hoặc tập trung vào thông tin liên quan nhất để tiếp tục hiệu quả.
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 Window Management
Strategies for managing LLM context windows including summarization, trimming, routing, and avoiding context rot
Capabilities
- context-engineering
- context-summarization
- context-trimming
- context-routing
- token-counting
- context-prioritization
Prerequisites
- Knowledge: LLM fundamentals, Tokenization basics, Prompt engineering
- Skills_recommended: prompt-engineering
Scope
- Does_not_cover: RAG implementation details, Model fine-tuning, Embedding models
- Boundaries: Focus is context optimization, Covers strategies not specific implementations
Ecosystem
Primary_tools
- tiktoken - OpenAI's tokenizer for counting tokens
- LangChain - Framework with context management utilities
- Claude API - 200K+ context with caching support
Patterns
Tiered Context Strategy
Different strategies based on context size
When to use: Building any multi-turn conversation system
interface ContextTier {
maxTokens: number;
strategy: 'full' | 'summarize' | 'rag';
model: string;
}
const TIERS: ContextTier[] = [
{ maxTokens: 8000, strategy: 'full', model: 'claude-3-haiku' },
{ maxTokens: 32000, strategy: 'full', model: 'claude-3-5-sonnet' },
{ maxTokens: 100000, strategy: 'summarize', model: 'claude-3-5-sonnet' },
{ maxTokens: Infinity, strategy: 'rag', model: 'claude-3-5-sonnet' }
];
async function selectStrategy(messages: Message[]): ContextTier {
const tokens = await countTokens(messages);
for (const tier of TIERS) {
if (tokens <= tier.maxTokens) {
return tier;
}
}
return TIERS[TIERS.length - 1];
}
async function prepareContext(messages: Message[]): PreparedContext {
const tier = await selectStrategy(messages);
switch (tier.strategy) {
case 'full':
return { messages, model: tier.model };
case 'summarize':
const summary = await summarizeOldMessages(messages);
return { messages: [summary, ...recentMessages(messages)], model: tier.model };
case 'rag':
const relevant = await retrieveRelevant(messages);
return { messages: [...relevant, ...recentMessages(messages)], model: tier.model };
}
}
Serial Position Optimization
Place important content at start and end
When to use: Constructing prompts with significant context
// LLMs weight beginning and end more heavily
// Structure prompts to leverage this
function buildOptimalPrompt(components: {
systemPrompt: string;
criticalContext: string;
conversationHistory: Message[];
currentQuery: string;
}): string {
// START: System instructions (always first)
const parts = [components.systemPrompt];
// CRITICAL CONTEXT: Right after system (high primacy)
if (components.criticalContext) {
parts.push(`## Key Context\n${components.criticalContext}`);
}
// MIDDLE: Conversation history (lower weight)
// Summarize if long, keep recent messages full
const history = components.conversationHistory;
if (history.length > 10) {
const oldSummary = summarize(history.slice(0, -5));
const recent = history.slice(-5);
parts.push(`## Earlier Conversation (Summary)\n${oldSummary}`);
parts.push(`## Recent Messages\n${formatMessages(recent)}`);
} else {
parts.push(`## Conversation\n${formatMessages(history)}`);
}
// END: Current query (high recency)
// Restate critical requirements here
parts.push(`## Current Request\n${components.currentQuery}`);
// FINAL: Reminder of key constraints
parts.push(`Remember: ${extractKeyConstraints(components.systemPrompt)}`);
return parts.join('\n\n');
}
Intelligent Summarization
Summarize by importance, not just recency
When to use: Context exceeds optimal size
interface MessageWithMetadata extends Message {
importance: number; // 0-1 score
hasCriticalInfo: boolean; // User preferences, decisions
referenced: boolean; // Was this referenced later?
}
async function smartSummarize(
messages: MessageWithMetadata[],
targetTokens: number
): Message[] {
// Sort by importance, preserve order for tied scores
const sorted = [...messages].sort((a, b) =>
(b.importance + (b.hasCriticalInfo ? 0.5 : 0) + (b.referenced ? 0.3 : 0)) -
(a.importance + (a.hasCriticalInfo ? 0.5 : 0) + (a.referenced ? 0.3 : 0))
);
…
Câu hỏi thường gặp
“Context window” là gì?
Đây là lượng văn bản tối đa AI có thể xử lý và “nhớ” cùng một lúc. Hãy hình dung nó như bộ nhớ ngắn hạn của AI.
Vì sao tóm tắt lại quan trọng?
Tóm tắt cho phép AI cô đọng thông tin cũ thành một văn bản ngắn hơn, giải phóng chỗ trong “bộ nhớ” cho thông tin mới quan trọng mà không mất ý nghĩa tổng thể.
AI có quên hết mọi thứ nếu cuộc trò chuyện quá dài không?
Không nhất thiết. Công cụ này giúp AI quản lý ngữ cảnh bằng cách ưu tiên điều quan trọng nhất, để nó có thể “nhớ” phần thiết yếu, kể cả trong các cuộc trò chuyện dài.
Chi tiết
Mô tả gốc của tác giả
Strategies for managing LLM context windows including summarization, trimming, routing, and avoiding context rot
Độ phổ biến
- Sao GitHub
- 48k
- Vị trí xếp hạng
- #4260
- Giấy phép
- MIT
- Cập nhật
- 15/10/2026
Bình luận
- …
Thêm skill từ kho mã này
00-andruia-consultant
48kGiúp agent của bạn bắt đầu hoặc cải thiện các dự án AI. Phân tích mã, gợi ý công cụ và lập kế hoạch hành động bằng tiếng Tây Ban Nha.
007
48kCho phép agent của bạn thực hiện kiểm toán bảo mật và mô hình hóa mối đe dọa. Hữu ích để bảo vệ dự án khỏi các cuộc tấn công và lỗ hổng.
10-andruia-skill-smith
48kGiúp agent của bạn tạo hoặc cải thiện các công cụ AI. Xác định cách công cụ hoạt động, viết tài liệu và kiểm tra cấu trúc.
20-andruia-niche-intelligence
48kGiúp agent của bạn tạo bản tóm tắt về một ngành cụ thể. Hữu ích để hiểu bối cảnh, quy tắc, cách người dùng tương tác và rủi ro của dự án.
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.