Chuyển đến nội dung
Skillpedia
Agent48k · #4260

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.md

Sao 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

Hãy dùng skill này để giúp tôi: https://github.com/sickn33/agentic-awesome-skills/blob/main/plugins/agentic-awesome-skills-claude/skills/context-window-management/SKILL.md Đọc tệp SKILL.md tại liên kết đó và làm theo hướng dẫn cho việc của tôi.
Bạn muốn AI tự tìm những skill như thế này?Cài MCP Skillpedia miễn phí: chỉ một dòng, và AI sẽ tìm trong 15.000+ skill trước mỗi việc.Cài đặt trong 1 phút →

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

repo: sickn33/agentic-awesome-skills

Độ 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

Skill này có hữu ích không?

0

Đăng nhập để bình chọn.

Bình luận

  • …

Thêm skill từ kho mã này

Skill tương tự