- Home
- Skills
- Prompt & Skill Engineering
- Aperture Context Engineering
Aperture Context Engineering
by Saqib Mehdi
Aggressively shrink LLM context windows by 20-66% while pinning tasks, constraints, and searchable history.
$19
Works with the AI Agents you already use
Aperture Context Engineering
Example session with this skill installed
I have a 60-turn conversation history that is hitting the 8k token limit. I need to prune it for an Anthropic model call without losing the original user request or the safety constraints.
- Read your context and instructions
- Compiled the aperture context engineering
I have processed the transcript using the Aperture protocol. The curation applied hysteresis compaction to clear the droppable tail while pinning the task statement and safety constraints.
Curation Report
| Metric | Value |
|---|---|
| Original Tokens | 8,422 |
| Curated Tokens | 3,158 |
| Savings | 62.5% |
| Spans Archived | 14 |
| Evidence Re-admitted | 2 (Order ID: #9921, Date: 2024-10-12) |
| Cache Hit Fraction | 0.88 |
| Status | Success (Constraints Protected) |
# The following message list has been curated for Anthropic-native shapes
curated_messages = [
{"role": "system", "content": "You are a deployment assistant. [Pinned Constraint]: Never deploy to production without approval."},
{"role": "user", "content": "[Task]: Deploy the latest build to the staging environment and run integration tests."},
{"role": "assistant", "content": "I will begin the staging deployment."},
# ... [14 tool output spans moved to archive] ...
{"role": "user", "content": "[Evidence Restored]: Order #9921 was logged in tool_output_42 with status: PENDING."},
{"role": "user", "content": "Wait, what was the status of that last order we saw?"}
]
Next steps
- Integrate
curate_messages(messages, merge_system=True)into your Anthropic client call. - Run
python scripts/audit_transcript.pyon your full production logs to calibrate thecompact_highthreshold. - Register survival probes for your "approval" keyword to alert if governance content ever hits the budget limit.
Connects securely to your tools. The creator never sees your data.
About this skill
Aperture: Guardrailed Context Curation for LLM Agents
The Problem
In long-running agent sessions, 60–90% of accumulated tokens can come from tool outputs that are read once and never referenced again.
Naive truncation is dangerous for two reasons:
1. Dropped facts can cause silent fabrication
When relevant facts are removed from the context, models may guess plausible answers instead of acknowledging that the information is unknown.
In the author's recorded live runs:
- A Gemini model guessed
4098for a vault code. - A Groq model repeated filler text verbatim.
2. Dropped constraints can cause governance decay
Removing constraints during compaction can weaken an agent's adherence to them.
Published research (arXiv:2606.22528, based on 1,323 episodes) reports prohibited-action rates rising from 0% to 30–59% after compaction drops a constraint.
What Aperture Does
Aperture adds guardrailed context curation to LLM agent loops that accumulate conversation history or tool outputs.
It provides three integration modes:
1. One-shot mode
Call curate_messages() before any model call.
- Designed to fail open.
- Curation errors cannot break the agent loop.
- If curation fails, the original message list is returned unchanged.
2. Loop mode
Use the Curator with:
- Survival probes to check whether important information remains available.
- Sticky evidence to protect critical facts and constraints.
- A JSONL trace ledger that makes every drop, elision, and re-admission decision observable.
3. Advisory mode
Audit an existing transcript and estimate potential token savings before changing any code.
Reproducible Evaluation
Aperture includes a deterministic evaluation suite with:
- 5 evaluation arms
- 10 task families
- 2 model behaviors
- 6 languages: English, Chinese, Spanish, Arabic, Hindi, and Urdu
Reported results
| Approach | Task success | Token savings |
|---|---|---|
| Aperture | 1.00 across every task family | 20–66% |
| Naive truncation | 0.00 across every task family | — |
Prompt-injection defense
In the reported injection-defense evaluation:
- Both Aperture arms refuse a
SYSTEM OVERRIDEplanted in a tool output. - All three baseline approaches obey the injected instruction.
Test coverage
The project reports:
- 152 unit tests passing.
- 10 wire-shape checks against the real adapter.
- An independent 16-battery stress suite covering:
- Cache economics
- Multilingual recall
- Prompt injection
- Protocol handling
To reproduce the evaluation and regenerate the reported numbers, run:
python scripts/run_eval.py
Security and Reliability
Aperture is designed with a conservative security posture:
- Uses Python's standard library only; no pip installations required.
- Makes no network calls.
- Does not harvest environment variables.
- Does not access secrets.
- Uses no obfuscation.
- Fails open by design.
Fail-open behavior: If any error occurs during curation, Aperture returns the original message list unchanged and reports the failure. The curation layer is designed not to interrupt the agent loop.
What Is Included
The package provides:
- The complete runtime:
aperture_lite - The evaluation suite
- 152 unit tests
- Integration patterns for agent frameworks
- A sample transcript
- Updates for the 0.8 version line
In Short
Aperture helps agent systems reduce context overhead without blindly discarding information that may be essential for correctness or policy compliance. It combines context curation with evidence preservation, survival checks, and an observable decision trail.
Run the evaluation yourself:
python scripts/run_eval.py
Find more skills like this on the Claude Skills Marketplace, the Codex Skills Marketplace and the Gemini Skills Marketplace, or browse Claude Skills for Prompt & Skill Engineering.
Character-based token estimation requires calibration for non-English scripts. Deterministic results are based on provided synthetic tasks; user workloads should be audited with the audit script.
How to use
- 1
Connect your agent to the Agensi MCP
Copy the prompt and paste it into Claude, ChatGPT, Cursor or any agent that supports MCP. It sets up the connection for you. Manual setup
- 2
Sign in to Agensi
Your agent shows a sign-in link. Sign in and click Allow.
- 3
Ask for what you need
Your agent loads this skill and uses it on your task. It always asks before buying a skill.
Reviews
No reviews yet
Be one of the first to try it. Every listed skill goes through the trust checks below.
Security scanned
Checked by our 8-point scan before listing
Fresh listing
Recently published to Agensi
Money-back guarantee
Doesn't do what its page promises? You get your money back.
Trust & safety
Security scan
Security scan passed today
- Software
Python
Git