More screenshots

    Works with the AI Agents you already use

    Claude CodeClaude CodeCursorCursorCodex CLICodex CLIMuseMuseDotsDots+21 more

    Memory Folding with Invariants

    1

    Three-tier memory folding system for long-horizon agents that prevents rule loss via deterministic invariant checks.

    $12

    Secure checkout via Stripe

    Money-back guarantee

    Converts to your local currency at checkout

    Security scanned
    Memory Folding with Invariants

    Memory Folding with Invariants

    Example session with this skill installed

    My agent's 'recent' memory tier is full with 20 notes from cycles 26-45. Two of them contain rules under [INVARIANTS & CONDITIONAL GATES]: "ABORT the cycle if the database connection check fails" and "NEVER post without a title". Fold the tier using the memory-folding-invariants skill. For this demo use a stub compressor that produces a plausible summary but drops the database rule, so I can see the enforcer catch it. Show me the fold report, the resulting compressed entry, and the invariant ids.

    • Read your context and instructions
    • Compiled the memory folding

    The fold ran, and the enforcer caught the dropped database rule and restored it verbatim. The demo lives in demo_fold.py.

    Setup. Twenty raw notes for cycles 26 through 45 filled the recent tier. The database rule sat in the cycle 28 note and the title rule in cycle 33, so both were inside the oldest ten that fold. The stub compressor wrote a plausible two-section summary that kept the title rule and softened the Postgres incident into past-tense narrative, which is exactly the failure the skill warns about.

    Fold report

    {
      "tier": "recent",
      "folded": 10,
      "ok": true,
      "inputs": 2,
      "kept": 2,
      "restored": ["ABORT the cycle if the database connection check fails"],
      "retired_removed": [],
      "block_chars": 144,
      "warn": false
    }
    

    Resulting compressed entry (cycles 26-35)

    [INVARIANTS & CONDITIONAL GATES]
    - [inv:0cdd35] NEVER post without a title
    - [inv:5df079] ABORT the cycle if the database connection check fails
    [EPISODIC TRAJECTORY]
    - Weekly digest pipeline ran issues #14 through #16. Engagement-weighted ranking surfaced the infra outage retro as the top performer; open rates moved 27% -> 31% -> 29% (after the #15 re-send).
    - A mid-cycle Postgres outage once forced a redraft against stale data; a connection check was added at cycle start.
    - #15 shipped with a blank subject (title template rendered empty), costing three unsubscribes; re-sent with the fix.
    - Shorter intro paragraph trialled, no signal yet. Theme grouping replaced score ordering after positive reader feedback. Feed cache pruned from 1.8 GB to 640 MB (60-day window). Per-theme click tracking started.
    

    Invariant ids

    idruleorigin
    inv:0cdd35NEVER post without a titlecycle 33, kept by the compressor
    inv:5df079ABORT the cycle if the database connection check failscycle 28, restored by the enforcer

    Both ids are the hash of the normalised rule text, so the agent can retire either one with retire_invariant. After the fold the tier state is ten recent notes for cycles 36 through 45, one compressed entry, and two active invariants.

    Next steps. Replace the stub with your real compressor via with_fallback(primary, backup), call MemoryTiers.add_note() each cycle, and wire list_invariants / retire_invariant from tool_specs() into your tool loop. The skill's test suite passed (12 tests).

    Connects securely to your tools. The creator never sees your data.

    About this skill

    Long-running agents often suffer from "context drift" where critical rules and learned lessons are summarized away as "past events" or deleted entirely during context compaction. Standard LLM summarization tends to convert hard constraints into soft narrative history, causing agents to repeat costly mistakes.

    What it does

    • Three-tier memory folding implements a structured hierarchy (recent, compressed, and deep) to manage long-horizon state without data loss.
    • Deterministic invariant enforcement uses a token-overlap check to verify that mandatory rules and conditional gates survive every compression cycle.
    • Automated rule restoration appends any dropped or weakened invariant back to the summary verbatim without requiring an additional LLM call.
    • Contradiction Reservoir management maintains an append-only log of prediction errors and failed hypotheses that bypass the summarization pipeline.
    • Self-managed retirement allows the agent to explicitly retire obsolete rules through specific tool calls to prevent invariant block bloat.

    How it works

    1. Tiered Rotation: The system monitors the recent note stack and triggers a fold into the compressed tier once capacity is reached, eventually cascading into the deep tier.
    2. Dual-Section Compression: Every fold uses a specific prompt architecture that separates [INVARIANTS & CONDITIONAL GATES] from the [EPISODIC TRAJECTORY].
    3. Post-Fold Verification: A Python-based enforcer compares the input invariants against the generated summary and restores missing content based on a survival threshold.
    4. Context Injection: The agent renders the current memory tiers and the most recent contradiction entries into the head of every new prompt.

    Frameworks & tools

    This skill is provider-neutral and requires Python 3.9+. It uses standard library components for the core logic and is compatible with any LLM (OpenAI, Anthropic, Gemini) via a simple chat function wrapper.

    Why this beats prompting it yourself

    Writing a "remember this" prompt is not enough for agents running hundreds of cycles; LLMs naturally prioritize narrative over constraints during summarization. This skill provides a deterministic safety net that physically prevents rule loss, ensuring an "ABORT if X" instruction never softens into a historical anecdote.

    Use cases

    • Preventing agents from repeating technical mistakes in long-running coding tasks.
    • Maintaining strict safety protocols and negative constraints in autonomous operations.
    • Building agents that require a permanent "lessons learned" audit trail.
    • Managing high-frequency cycle notes without overflowing context windows.

    Known limitations

    The system requires the agent to produce a single-paragraph memory note per cycle. Invariant restoration relies on token overlap, which may cause duplicate entries if the compressor rewords rules significantly.

    Requires Python 3.9+. Invariant check uses token overlap, which can cause duplicate entries if summaries reword rules heavily. Agent must output a one-paragraph note per cycle.

    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 any payment.

    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 28 days ago

    Requires

    Python 3.9+
    Python

    Permissions

    Terminal / Shell
    Read Files
    Write Files

    File Scopes

    memory_tiers.json
    *_contradictions.jsonl

    Runs Python scripts locally. Reads and writes the memory state file and the append-only contradiction log at paths the caller supplies. Makes no network calls of its own; the LLM compressor is a function you pass in, so model traffic goes through your existing client.

    Listed28 days ago

    What's inside

    Frequently Asked Questions

    This skill solves 'context drift,' where agents gradually forget strict rules or safety constraints during long-running tasks. It uses a three-tier folding system and deterministic checks to ensure your agent's core instructions never get 'summarized away' or softened into narrative history.

    The skill is provider-neutral and works with any LLM (including OpenAI, Anthropic, and Gemini) that supports basic chat completions. It is written in Python 3.9+ and can be integrated into most custom agentic frameworks via a simple function wrapper.

    Three standard-library Python modules: memory_tiers.py (the three tiers, the compressor prompt, with_fallback, tool specs and dispatch), invariants.py (parse, enforce, retire, stable ids) and contradictions.py (the append-only Contradiction Reservoir with prompt projection and tool specs). Plus a 12-test offline suite and three reference docs: the two-section compressor prompt with suggested agent-side wording, the documented failure modes each guard catches, and tool wiring for Anthropic, OpenAI and Gemini. SKILL.md walks through the seven integration steps.

    The system uses a Python-based token-overlap check that compares the pre-fold rules against the post-fold summary. If a mandatory invariant is missing or weakened, the system automatically appends the original text back to the memory without needing a second, costly LLM call.

    This skill works best for agents that generate a memory note or summary at the end of every cycle. It is particularly effective for agents performing 50+ consecutive steps where standard context windows would normally lead to information loss.

    New in Agents & Orchestration