agentleFS
EnigmaWUEnigmaWU/MyCodeAgentSkills/build-agent-memory-systems/SKILL.md

build-agent-memory-systems

Skill4 starsChanged 3 months agoMITView on GitHub

WHEN/WHERE/WHO: [Scheduling: Agents or developers designing memory layers for autonomous agents that must retain context across sessions.] HOW: [Structural: Use this SKILL to configure short-term working memory, semantic vector stores, and episodic event logs to avoid LLM amnesia.] WHY: [Scheduling: Without persistent memory, an agent starts from zero every message. A structured memory system allows deep personalization and context awareness over long time horizons.]

The file

We split this skill into the rules it gives an agent

9 rules. About 0 are common, 9 are distinctive, and 0 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈9

    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
  1. Distinctive:

    When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter …

    line 13
  2. Distinctive:

    Use when an agent must remember facts from past sessions or retrieve relevant domain knowledge dynamically.

    line 23
  3. Distinctive:

    Stop Rule: If the required retrieval scale, latency target, or memory type is still unclear, stop and ask before choosing storage and …

    line 46
  4. Distinctive:

    Token Budget Protection: Never blindly append all past messages into the context window.

    line 49
  5. Distinctive:

    If the user hasn't specified whether they need Semantic Search (Vector DB) or just simple conversation persistence (SQL/NoSQL), pause and …

    line 53
  6. Distinctive:

    Ensure the state schema resets or truncates upon task completion.

    line 61
  7. Distinctive:

    Ensure the extraction tool actually runs (test it).

    line 76
  8. Distinctive:

    Verify that the Summarizer successfully truncates the history without losing the core user intent.

    line 77
  9. Distinctive:

    Do short-term, long-term, and episodic memories have distinct stores, triggers, and retrieval paths?

    line 84

≈ “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.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Build Agent Memory Systems

Common Contract (Load First)

When this skill is activated, first load skill-common and apply the shared conventions it defines: canonical section order, frontmatter rules, anti-pattern guidance, and the Review In Mind loop in review-in-mind. This skill adds only domain-specific rules below.

Who

Architects, principal developers, or AI engineers designing autonomous systems that require deep personalization or long-running context.

What

Design and implement a multi-tiered memory architecture for agents, including Short-Term (working/scratchpad) memory, Long-Term (semantic/vector) memory, and Episodic (event/history) memory.

When

  • Triggered by requests like: "add memory to this agent", "how do I persist context?", or "design an agent memory system".
  • Use when an agent must remember facts from past sessions or retrieve relevant domain knowledge dynamically.

Where

Applies to backend agent orchestration, state schemas, and database configurations (e.g., Vector DBs, SQL history logs).

Why

LLMs are stateless. The "context window" is too small to fit an entire user's history or a massive codebase. By injecting only the relevant memories dynamically via RAG (Retrieval-Augmented Generation) and summarizing older context, the agent remains highly capable without hitting token limits or context degradation.

Inputs

  • Memory Requirements: What specifically needs to be remembered (user facts, code snippets, tool outcomes)?
  • Scale and Latency: How fast must retrieval happen, and how large is the dataset?

Output (Logical Evidence)

  • Memory Architecture Design: A mapping of data types to short-term or long-term storage mechanisms.
  • RAG & Summarization Logic: The code logic that manages when to write to memory and when/how to retrieve from it.

Optimization Readiness

  • Failure Signals: The design overfills the context window, mixes memory namespaces, retrieves irrelevant history, or lacks a clear rule for when to summarize versus retrieve.
  • Evidence To Collect: Retrieval traces, summarization outputs, latency measurements, token-usage trends, and examples of useful versus noisy recalled memories.
  • Safe Mutation Boundaries: Refine storage partitioning, retrieval heuristics, summarization thresholds, and memory examples without changing the core short-term, episodic, and long-term memory split.
  • Acceptance Criteria: Accept revisions only if the design preserves token budget, isolates tenant state correctly, and retrieves relevant memory with clear write and recall rules.
  • Rejected Revision Handling: Record failed chunking strategies, noisy retrieval patterns, and unsafe namespace designs so they are not retried blindly.
  • Transfer Check: Confirm the workflow still works for both lightweight conversation persistence and larger semantic-memory architectures.
  • Stop Rule: If the required retrieval scale, latency target, or memory type is still unclear, stop and ask before choosing storage and summarization strategy.

Constraints (Logical Boundaries)

  • Token Budget Protection: Never blindly append all past messages into the context window. Old messages MUST be summarized or evicted to maintain a safe token buffer.
  • State Partitioning: Strictly partition memory namespaces (e.g., user_123 vs system_global) to prevent cross-tenant data leakage.

One More Thing

If the user hasn't specified whether they need Semantic Search (Vector DB) or just simple conversation persistence (SQL/NoSQL), pause and ask them about the scale of data they expect to handle.


How (Structural Workflow)

1. Define the Short-Term Memory (Scratchpad)

  • Design the state schema (e.g., in LangGraph) to hold the immediate context of the current task.
  • Ensure the state schema resets or truncates upon task completion.

2. Implement the Episodic Memory (Conversation History)

  • Configure an append-only log (e.g., SQLite, Postgres, or Redis) to store raw message exchanges.
  • Implement a Summarizer Agent: A background process that triggers when the message history exceeds N tokens. The Summarizer squashes the history into a dense <summary> block and clears the raw messages, leaving only the summary and the last 3 turns.

3. Implement the Semantic/Long-Term Memory (Vector/Knowledge Graph)

  • Determine the extraction trigger: When the agent learns a "core fact" (e.g., user preference or global architecture rule), it explicitly calls a save_memory tool.
  • The save_memory tool chunks the text, embeds it, and saves it to a Vector Database (like Chroma, Pinecone, or pgvector).

4. Wire the Retrieval Mechanism

  • At the start of the agent's turn (or via a specific search_memory tool), the agent queries the Vector DB based on the current context.
  • The retrieved results are injected directly into the system prompt's <relevant_context> section.

5. Validate the Memory Lifecycle

  • Ensure the extraction tool actually runs (test it).
  • Verify that the Summarizer successfully truncates the history without losing the core user intent.

Review In Mind (ReviewInMindGenie)

Execute the common review loop in review-in-mind before delivering.

Review lens for this skill:

  • Do short-term, long-term, and episodic memories have distinct stores, triggers, and retrieval paths?
  • Is there a validation step proving extraction and retrieval actually work?
  • Are privacy, retention, and eviction rules explicit?

Download now (ZIP)

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
What did you use it for? e.g. Reviewing pull requests in a Rails app

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.