Aperture Context Engineering

    by Saqib Mehdi

    1

    Aggressively shrink LLM context windows by 20-66% while pinning tasks, constraints, and searchable history.

    $19

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIDeepSeekDeepSeekMuseMuse+23 more

    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

    MetricValue
    Original Tokens8,422
    Curated Tokens3,158
    Savings62.5%
    Spans Archived14
    Evidence Re-admitted2 (Order ID: #9921, Date: 2024-10-12)
    Cache Hit Fraction0.88
    StatusSuccess (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

    1. Integrate curate_messages(messages, merge_system=True) into your Anthropic client call.
    2. Run python scripts/audit_transcript.py on your full production logs to calibrate the compact_high threshold.
    3. 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 4098 for 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

    ApproachTask successToken savings
    Aperture1.00 across every task family20–66%
    Naive truncation0.00 across every task family—

    Prompt-injection defense

    In the reported injection-defense evaluation:

    • Both Aperture arms refuse a SYSTEM OVERRIDE planted 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. 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. 2

      Sign in to Agensi

      Your agent shows a sign-in link. Sign in and click Allow.

    3. 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
    PythonGit

    Permissions

    Terminal / Shell
    Read Files
    Write Files
    Network Access
    Listedtoday

    What's inside

    Frequently Asked Questions

    This skill prevents goal drift and silent failures in long sessions by pinning system prompts and task statements while automatically restoring dropped facts from an archive when the model needs them. It also protects against injection attacks by marking untrusted tool output and maintains provider cache stability to keep costs low.

    The skill provides a dependency-free Python runtime that includes a curation engine, a searchable archive for dropped history, and adapters for major message formats like OpenAI, Anthropic, Gemini, and others. You also get a trace ledger for observability and a transcript auditing script to project potential savings from your existing logs.

    You can provide your agent with a list of messages to be curated or use the built-in Curator object to manage ingestion and survival probes in a loop. For more autonomy, you can bind a recall tool to the agent so it can manually search the archive for any history that was removed to save space.

    The skill uses a character-based token estimator that varies by script, such as roughly one token per character for CJK and two for Arabic or Devanagari. Users should calibrate their specific token budgets against real provider telemetry for the highest accuracy.

    This skill is written in standard library Python and requires no external dependencies. It works with any agent loop that can process message lists or tool outputs in the supported provider formats like Bedrock Converse, Cohere, or Ollama.

    Ask your agent to use the curate_messages function to fit a conversation into a specific token budget or to run the audit_transcript script on your logs to identify context-health risks. You can also tell it to register survival probes for critical safety constraints to ensure they never leave the active window.

    New in Prompt & Skill Engineering