context-distillation-compressor
Skill2 starsChanged 28 days agoApache-2.0View on GitHub
Performs AST-guided semantic context distillation, lossy-to-lossless prompt compaction, and memory pruning to prevent context bloat and token degradation in long agent trajectories.
In this repository108 other files it gives its agents.
- AGENTS.mdAGENTS.md
- everything-gemini-maintainerSkill
- adversarial-fuzz-generatorSkill
- agent-evalsSkill
- ai-first-engineeringSkill
- alloydb-omni-vectorSkill
- apache-kafka-streamsSkill
- api-craftsmanSkill
- architecture-designerSkill
- argon-3d-game-engineSkill
- argon-3d-scene-architectSkill
- argon-procedural-asset-generatorSkill
- argon-visual-critique-loopSkill
- argo-workflowsSkill
- autonomous-incident-healerSkill
- axum-web-serviceSkill
- bigquery-vector-searchSkill
- browser-qa-testerSkill
- chromadb-vector-storeSkill
- cilium-ebpf-networkingSkill
- clickhouse-analyticsSkill
- cloud-deploy-canarySkill
- cloudflare-r2-object-storageSkill
- cloudflare-workersSkill
- cloud-run-agentsSkill
- context-cachingSkill
- context-warmerSkill
- continuous-learningSkill
- cost-oracle-finopsSkill
- cross-repo-swarm-syncSkill
- cve-remediation-orchestratorSkill
- database-architectSkill
- dataproc-spark-analyticsSkill
- dbt-transformationSkill
- debezium-cdcSkill
- devops-pipelineSkill
- distributed-rate-limitingSkill
- docker-compose-orchestratorSkill
- duckdb-local-olapSkill
- dynamic-thinking-allocationSkill
- ebpf-microvm-sandboxSkill
- ebpf-sandbox-enforcerSkill
- elephant-goldfish-modelSkill
- envoy-ai-gatewaySkill
- ephemeral-swarm-orchestratorSkill
- fastapi-productionSkill
- fullstack-nextjsSkill
- game-audio-synthesizerSkill
- game-studioSkill
- gemini-function-callingSkill
- gemini-groundingSkill
- gemini-live-audio-transcriberSkill
- gemini-live-multimodalSkill
- gemini-live-screen-visionSkill
- gemini-multimodalSkill
- genetic-prompt-cross-pollinatorSkill
- git-craftsmanSkill
- github-opsSkill
- google-axSkill
- google-flow-orchestratorSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
3 rules. About 0 are common, 3 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 57
When injecting full source files into context, large function implementations that are irrelevant to the target edit are skeletalized:
- Distinctive: line 74
If a tool produces $>4,000$ characters of build logs or table dumps:
- Distinctive: line 80
When compaction triggers, history turns $[1 \dots N-4]$ are distilled into three markdown sections:
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Context Distillation & Semantic Compaction (context-distillation-compressor)
Mitigates token pressure, context dilution, and attention degradation in long multi-turn Gemini 3.8 and Antigravity sessions through AST-guided semantic distillation, idempotent tool-call deduplication, lossless structured compression, and active context compaction.
1. Architectural Pipeline: Dual-Tier Context Compaction
┌─────────────────────────────────────────────────────────────────────────────┐
│ CONTEXT DISTILLATION & COMPACTION PIPELINE │
│ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 1. Active Turn Monitoring & Token Pressure Sensor │ │
│ │ • Trajectory token count: $T_{current} / T_{max}$ │ │
│ │ • Trigger Threshold: Alert at $70\%$, Auto-Compaction at $85\%$ │ │
│ └──────────────────────────────────┬──────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 2. Semantic Distillation Engine │ │
│ │ ┌───────────────────────────┐ ┌──────────────────────────┐ │ │
│ │ │ A. AST Outline Compaction │ │ B. Tool Output Truncation│ │ │
│ │ │ • Collapse class bodies│ │ • Retain header/footer│ │ │
│ │ │ • Retain type signatures│ │ • Store full blob in │ │ │
│ │ │ and docstrings │ │ disk artifacts/ │ │ │
│ │ └─────────────┬─────────────┘ └────────────┬─────────────┘ │ │
│ └──────────────────┼────────────────────────────────┼─────────────────┘ │
│ └────────────────┬───────────────┘ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 3. Lossless Checkpoint & Instinct Synthesis │ │
│ │ • Synthesize resolved decisions into a structured summary ledger │ │
│ │ • Persist learned instincts into `.agents/hooks/learned-instincts│ │
│ │ • Prune redundant intermediate tool calls from prompt history │ │
│ └──────────────────────────────────┬──────────────────────────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────────────────────────────────────────────────────────────┐ │
│ │ 4. Reconstituted Compressed Prompt Assembly │ │
│ │ • Core Goal + Active Work State + Distilled Architectural Summary│ │
│ │ • Result: 60%–85% token volume reduction with 100% intent fidelity│ │
│ └─────────────────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────────────────┘2. Compaction Strategies & Algorithms
A. Tree-Sitter AST Skeletonization
When injecting full source files into context, large function implementations that are irrelevant to the target edit are skeletalized:
// Original: 250 lines
class UserService {
async processBilling(id: string, opts: BillingOpts): Promise<Receipt> {
// 60 lines of validation and stripe orchestration
}
}
// Distilled AST View: 5 lines (92% token reduction)
class UserService {
/** Processes user billing and invoice creation */
async processBilling(id: string, opts: BillingOpts): Promise<Receipt>;
}B. Tool Result Deduplication & Offloading
- If a tool produces $>4,000$ characters of build logs or table dumps:
- The complete output is written to
<workspace>/.system_generated/artifacts/<hash>.log. - The active prompt receives a 10-line excerpt plus a reference pointer:
[Artifact Stored: file://.../artifacts/build.log (12,400 bytes, 0 errors, 4 warnings)]
- The complete output is written to
C. Checkpoint Compaction Protocol
- When compaction triggers, history turns $[1 \dots N-4]$ are distilled into three markdown sections:
- Established Architecture Decisions: Immutable design agreements.
- Resolved Edge Cases & Pitfalls: Invariants learned during past iterations.
- Remaining Active Goal Queue: Strict next actions.
3. Operational Recipes
Analyzing Context Pressure via CLI
# Analyze prompt token volume and compaction opportunities
everything-gemini compact analyze --workspace .
# Execute dry-run semantic compaction
everything-gemini compact distill --threshold 75 --dry-run
# Run active AST pruning on workspace context files
everything-gemini compact prune --ast --jsonHook Integration
The hooks/context-compactor/hooks.json hook automatically monitors incoming turns and triggers compaction scripts before context overflow can occur.
4. Cross-Reference Links
- See skills/context-caching/SKILL.md for Google Cloud Vertex context caching rules.
- See skills/context-warmer/SKILL.md for cache pre-warming strategies.
- See agents/performance-tuner.md for trajectory latency optimization.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

