Command Palette

Search for a command to run...

UnylyUnyly
Назад к скиллам

context-engineering

БесплатноБез исполняемых скриптовНе проверен

Strategies for managing LLM context windows effectively in AI agents. Use when building agents that handle long conversations, multi-step tasks, tool…

itsmostafaот itsmostafa★ 26 звёзд на GitHub18 установок в других каталогах

Об этом скилле

Context Engineering

Context engineering is the discipline of curating and maintaining the optimal set of tokens during LLM inference. Unlike prompt engineering (crafting individual prompts), context engineering focuses on what information enters the context window and when.

Table of Contents

Core Principles

Context as a Finite Resource

LLMs have limited "attention budgets." As context length increases, models experience context rot—decreased ability to accurately recall information. The goal is finding the smallest possible set of high-signal tokens that maximize desired outcomes.

Effective Context = Relevant Information / Total Tokens

Key insight: More context isn't better. The right context is better.

The Context Pollution Problem

Every token added to context has costs:

  • Increased latency and compute
  • Diluted attention to important information
  • Higher risk of hallucination from conflicting data
  • Reduced model performance on retrieval tasks

Context Management Strategies

1. Context Trimming

Drop older conversation turns, keeping only the last N turns.

Aspect Details
Mechanism Sliding window over conversation history
Pros Deterministic, zero latency, preserves recent context verbatim
Cons Abrupt loss of long-range context, "amnesia" effect
Best for Independent tasks, short interactions, predictable workflows
def trim_context(messages: list, keep_last_n: int = 10) -> list:
    """Keep system message + last N turns."""
    system_msgs = [m for m in messages if m["role"] == "system"]
    other_msgs = [m for m in messages if m["role"] != "system"]
    return system_msgs + other_msgs[-keep_last_n:]

2. Context Summarization

Compress prior messages into structured summaries.

Aspect Details
Mechanism LLM generates summary of older context
Pros Retains long-range memory, smoother UX, scalable
Cons Summarization bias risk, added latency, potential compounding errors
Best for Complex multi-step tasks, long-horizon interactions
SUMMARIZATION_PROMPT = """Summarize the conversation so far, preserving:
1. Key decisions made
2. Important context established
3. Current task state and goals
4. Any constraints or preferences expressed

Be concise but complete. Output as structured markdown."""

async def summarize_context(messages: list, model) -> str:
    """Generate a summary of conversation history."""
    conversation_text = format_messages_for_summary(messages)
    response = await model.generate(
        system=SUMMARIZATION_PROMPT,
        user=conversation_text
    )
    return response.content

3. Hybrid Approach

Combine trimming and summarization for optimal balance.

class HybridContextManager:
    def __init__(
        self,
        keep_recent: int = 5,      # Recent turns to keep verbatim
        summary_threshold: int = 20, # When to trigger summarization
    ):
        self.keep_recent = keep_recent
        self.summary_threshold = summary_threshold
        self.running_summary = ""

    def process(self, messages: list) -> list:
        if len(messages) < self.summary_threshold:
            return messages

        # Summarize older messages
        old_messages = messages[:-self.keep_recent]
        self.running_summary = summarize(old_messages, self.running_summary)

        # Return summary + recent messages
        return [
            {"role": "system", "content": f"Previous context:\n{self.running_summary}"},
            *messages[-self.keep_recent:]
        ]

4. Session Memory

Persist reusable facts, preferences, and task state outside the context window. Load only the relevant slice for the current turn.

Aspect Details
Mechanism External store keyed by user, session, task, or resource
Pros Recovers long-range context without carrying all history
Cons Requires retrieval, freshness, and deletion policies
Best for Agents, project work, personalization, long-running workflows

Separate durable memory from ephemeral scratchpads. Durable memory should contain stable facts and explicit decisions, not every intermediate thought.

System Prompt Design

Principles for Context-Efficient Prompts

  1. Clear and direct language: Avoid ambiguity that requires clarification turns
  2. Structured sections: Organize by purpose (role, capabilities, constraints)
  3. Minimal yet comprehensive: I
Полный SKILL.md на GitHub

Установить context-engineering в Claude Code и Claude Desktop

Зарегайся, чтобы установить скилл

Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.

  • Открой команду установки в одну строку
  • Сохраняй скиллы в синхронизируемую библиотеку
  • Уведомления, когда скиллы обновляются
Зарегаться бесплатноУ меня уже есть аккаунт

Разрешённые инструменты

Инструменты, которые скиллу разрешено вызывать.

Без ограничений — скилл может использовать любой инструмент.

Вложенные файлы

reference/evaluation-strategies.mdreference/summarization-patterns.md

FAQ

Что делает скилл context-engineering?

Strategies for managing LLM context windows effectively in AI agents. Use when building agents that handle long conversations, multi-step tasks, tool orchestration, or need to maintain coherence across extended interactions.

Как установить скилл context-engineering?

Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.

Скилл context-engineering запускает скрипты?

Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.

Похожие скиллы

Сравнить context-engineering с