본문으로 건너뛰기
Skillpedia
에이전트18k · #10640

context-optimization

하는 일

이 스킬은 제한된 컨텍스트 창 안에 더 많은 유용한 작업을 담는 방법을 다룹니다. 예를 들면 장황한 도구 출력을 가리기, 캐시된 프롬프트 앞부분 재사용, 여러 에이전트로 작업 나누기입니다. AI 비용을 줄이거나 더 큰 작업을 하려는 팀을 위한 스킬입니다.

사용하는 경우

  • ✓작업이 컨텍스트 공간을 다 쓰거나 토큰 비용이 너무 많이 들 때.
  • ✓긴 도구 출력이 에이전트가 거의 필요로 하지 않는 세부 내용으로 컨텍스트를 채울 때.
  • ✓반복되는 비용을 줄이려고 프롬프트의 캐시된 부분을 재사용하고 싶을 때.

스킬 링크

https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/main/skills/context-optimization/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/muratcankoylan/Agent-Skills-for-Context-Engineering/blob/main/skills/context-optimization/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“에이전트의 도구 출력이 컨텍스트를 너무 빨리 채웁니다. 품질을 잃지 않고 대화를 가볍게 유지하는 방법을 보여 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

스킬은 영향과 위험에 따라 기법의 순위를 매깁니다. 출력 마스킹, 프롬프트 시작 부분 캐싱, 작업 분할 등이 있으며, 각 변경을 측정하라고 말합니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

Context Optimization Techniques

Context optimization extends the effective capacity of limited context windows through strategic compression, masking, caching, and partitioning. Effective optimization increases useful capacity without requiring larger models or longer windows — but only when applied with measurement discipline. The techniques below are ordered by impact and risk.

When to Activate

Activate this skill when:

  • Context budgets or token costs constrain task complexity
  • Observation masking can replace verbose tool outputs with retrievable references
  • Prefix or KV-cache hit rate needs improvement
  • Retrieval scoping can reduce irrelevant loaded context
  • Context partitioning can extend effective capacity across agents
  • Budget triggers are needed for masking, compaction, or partitioning

Do not activate this skill for adjacent work owned by other skills:

  • Explaining why attention or context windows behave this way: context-fundamentals.
  • Diagnosing active lost-in-middle, poisoning, distraction, confusion, or clash: context-degradation.
  • Designing a structured handoff summary for a long conversation: context-compression.
  • Storing large outputs, plans, or logs as files: filesystem-context.
  • Model-initiated rewrites of its own context and their re-prefill cost: self-managed-context.

Core Concepts

Apply four primary strategies in this priority order:

  1. KV-cache optimization — Reorder and stabilize prompt structure so the inference engine reuses cached Key/Value tensors. This is the cheapest optimization when the runtime supports prefix caching: low quality risk, immediate cost and latency savings. Apply it first when stable prefixes exist.

  2. Observation masking — Replace verbose tool outputs with compact references once their purpose has been served. Tool outputs can dominate agent trajectories (claim-context-optimization-tool-output-dominance), so masking often yields the largest capacity gains. The original content remains retrievable if needed downstream.

  3. Compaction — Summarize accumulated context when utilization exceeds 70%, then reinitialize with the summary. This distills the window's contents while preserving task-critical state. Compaction is lossy — apply it after masking has already removed the low-value bulk.

  4. Context partitioning — Split work across sub-agents with isolated contexts when a single window cannot hold the full problem. Each sub-agent operates in a clean context focused on its subtask. Reserve this for tasks where estimated context exceeds 60% of the window limit, because coordination overhead is real.

The governing principle: context quality matters more than quantity. Every optimization preserves signal while reducing noise. Measure before optimizing, then measure the optimization's effect.

Detailed Topics

Compaction Strategies

Trigger compaction when context utilization exceeds 70%: summarize the current context, then reinitialize with the summary. This distills the window's contents in a high-fidelity manner, enabling continuation with minimal performance degradation. Prioritize compressing tool outputs first (they consume 80%+ of tokens), then old conversation turns, then retrieved documents. Never compress the system prompt — it anchors model behavior and its removal causes unpredictable degradation.

Preserve different elements by message type:

  • Tool outputs: Extract key findings, metrics, error codes, and conclusions. Strip verbose raw output, stack traces (unless debugging is ongoing), and boilerplate headers.
  • Conversational turns: Retain decisions, commitments, user preferences, and context shifts. Remove filler, pleasantries, and exploratory back-and-forth that led to a conclusion already captured.
  • Retrieved documents: Keep claims, facts, and data points relevant to the active task. Remove supporting evidence and elaboration that served a one-time reasoning purpose.

Target 50-70% token reduction with less than 5% quality degradation. If compaction exceeds 70% reduction, audit the summary for critical information loss — over-aggressive compaction is the most common failure mode.

Observation Masking

Mask observations selectively based on recency and ongoing relevance — not uniformly. Apply these rules:

  • Never mask: Observations critical to the current task, observations from the most recent turn, observations used in active reasoning chains, and error outputs when debugging is in
자주 묻는 질문

관찰 마스킹이란 무엇인가요?

긴 도구 출력을 짧은 참조로 바꾸는 방식이며, 에이전트는 필요할 때 그 참조를 다시 찾아볼 수 있습니다.

프리픽스 캐싱이란 무엇인가요?

프롬프트의 변하지 않는 시작 부분을 재사용해서, 모델이 매번 다시 처리하지 않게 하는 방식입니다.

이렇게 하면 답변 품질이 떨어지나요?

스킬은 각 변경을 측정하라고 말합니다. 답변 품질이 유지될 때만 그 기법을 쓰면 됩니다.

상세 정보

작성자의 원본 설명

This skill should be used for improving context efficiency: context budgeting, observation masking, prefix or KV-cache strategy, partitioning, token-cost reduction, retrieval scoping, and extending effective context capacity without lowering answer quality.

repo: muratcankoylan/Agent-Skills-for-Context-Engineering

인기도

GitHub 스타
18k
순위
#10640
라이선스
MIT
업데이트
2026. 10. 11.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬