context-optimization

Optimize LLM context windows through compaction, observation masking, KV-cache reuse, and partitioning.

Updated Apr 17, 2026
One-click install
npx skills add https://github.com/Syedyasir001/RVULibPass --skill context-optimization-syedyasir001
Or copy as Structured Prompt for Agent▼
Please help me install this Agent Skill.
Skill: context-optimization
Source: https://github.com/Syedyasir001/RVULibPass/tree/main/.agent/skills/library/context-optimization
Command: npx skills add https://github.com/Syedyasir001/RVULibPass --skill context-optimization-syedyasir001

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve? Long-running agents and large conversations exhaust limited context windows, driving up token costs, latency, and quality degradation. This Skill provides concrete techniques and utilities to extend effective context capacity without larger models. ## Core Features & Use Cases - Four Optimization Strategies: Apply KV-cache optimization, observation masking, compaction, and context partitioning in a prioritized order with measurable performance targets. - Utility Script: Use scripts/compaction.py for token estimation, category-aware summarization, observation masking with retrievable references, budget tracking, and cache metrics. - Decision Framework: Select the right optimization based on what dominates your context (tool outputs, documents, or message history) using threshold-based triggers at 70-80% utilization. - Use Case: An agent processing dozens of tool calls sees context utilization hit 80%. Use this Skill to mask stale tool outputs, compact old turns, and restructure prompts for cache hits, cutting token costs by over 50%. ## Quick Start Ask the AI to optimize the current agent's context usage by masking old tool outputs and compacting conversation history before the window limit is reached.

Frequently Asked Questions about context-optimization

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I reduce token costs in long LLM agent conversations?▼

Apply observation masking to replace verbose tool outputs with compact references, then compact older conversation turns when utilization exceeds 70-80%. Stabilizing prompt prefixes for KV-cache reuse can cut costs by 50% or more on cached tokens.

What is observation masking in agent context management?▼

Observation masking replaces verbose tool outputs with a compact reference like '[Obs:id elided. Key: summary. Full content retrievable.]' once their purpose is served. The full content is stored externally and remains retrievable, achieving 60-80% reduction in masked observations.

How does KV-cache optimization reduce LLM latency?▼

KV-cache optimization places stable content (system prompt, tool definitions) at the prompt prefix so cached tensors are reused across requests. Removing timestamps and session IDs from the prefix can achieve 70%+ hit rates and 40%+ latency reduction.

When should I compact context versus partition across sub-agents?▼

Compact when utilization exceeds 70-80% and the task still fits one window. Partition across sub-agents only when estimated context exceeds 60% of the limit and at least 3 independent subtasks exist, since coordination overhead can exceed savings otherwise.

Why does my KV-cache hit rate drop after prompt changes?▼

Any change to the prompt prefix, even a single whitespace or a dynamic timestamp, invalidates the entire cached block downstream. Pin system prompts as immutable strings and move dynamic metadata into user messages appended after the stable prefix.

What are the risks of aggressive context compaction?▼

Over-aggressive compaction loses task goals, user constraints, and nuanced state, especially when the summarizing model is itself above 85% utilization. Trigger compaction at 70-80%, target 50-70% reduction, and re-validate summaries against the current task goal.