SuperAPI AI Directory

context-optimization

General & other

View repository

Updated 10-16 05:48

About this skill

🚀 Context Optimization Techniques

This skill makes it possible to maximize the usefulness of the context window through compression, masking, and partitioning strategies. The goal is to double or triple the effective capacity without the need for larger models, reducing latency and cost.

Mental Model: The quality of the context matters more than the quantity. Optimizing means preserving the signal while eliminating technical and conversational noise.

🚩 Fragility and Autonomy

  • Fragility: Medium. Excessive masking can hide critical reasoning dependencies.
  • Freedom: High in the implementation of optimization triggers.

🚀 When to Activate

  • When context limits restrict the complexity of the task.
  • To reduce operating costs (fewer tokens = lower cost).
  • When noticing significant increases in response latency.
  • When implementing long-running agent systems or massive monorepos.

🧠 Core Concepts

1. The Four Optimization Levers

Strategy Method Impact
Compaction Structured summary near limits. 50-70% reduction.
Observation Masking Replacement of verbose outputs with references. 60-80% reduction in tool logs.
KV-Cache Opt Reordering to maximize stable prefixes. Latency -40%, Cost -50%.
Partitioning Division of tasks into isolated sub-agents. Total noise isolation.

2. The Observation Problem

Tool outputs can account for 80% of token usage. Once processed, keeping the full log has diminishing value and increasing cost.

🛠️ Implementation in Gemini Elite Core

Pattern: Masking with Atomic Reference

Replace long outputs with a summary and a reference ID.

[OBSERVATION MASKED: output_log_42]
Key Findings: Error 404 in /api/auth.
Full log stored in artifacts/logs/auth_error.log

Pattern: Cache-Friendly Ordering

Order the context to maximize "cache hits" of the Gemini engine.

  1. System Prompt (Static - Beginning)
  2. Tool Definitions (Static)
  3. Project Context (Semi-Static)
  4. Current Task State (Dynamic - End)

Trigger Thresholds

  • 70% Utilization: Proximity alert.
  • 80% Utilization: Iterative compaction trigger.
  • 90% Utilization: Aggressive compaction and forced partitioning.

🔗 Integrations

  • context-fundamentals: Basis for the information hierarchy.
  • multi-agent-patterns: Partitioning as an isolation method.
  • memory-systems: Context offloading to external memory systems.

📚 Internal References

  • references/optimization_techniques.md: Technical guide to token budgets, masking patterns, and performance benchmarks.