Skip to content
Back to skills

Agent Memory Design

ASecurity

Design long-term memory for AI agents — framework-, language- and store-agnostic. Use when deciding what an agent should remember across conversations (and what it must not), designing memory tools (save, recall, forget), deciding whether memory writes need human approval, choosing how memories reach the model or where they are stored, reviewing an existing memory design, or debugging an agent that forgets a user's preferences, fills its memory with the wrong things, or applies a memory where...

  • 4 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 3, 2026
ai-agentsgodebugginggitdatabase

Works with

  • cli

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 3, 2026

npx -y skills add agentailor/skills --skill agent-memory-design --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Agent Memory Design?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Agent Memory Design
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/agentailor-agent-memory-design/badge)](https://www.skillsdirectory.com/skills/agentailor-agent-memory-design)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: agent-memory-design
description: Design long-term memory for AI agents — framework-, language- and store-agnostic. Use when deciding what an agent should remember across conversations (and what it must not), designing memory tools (save, recall, forget), deciding whether memory writes need human approval, choosing how memories reach the model or where they are stored, reviewing an existing memory design, or debugging an agent that forgets a user's preferences, fills its memory with the wrong things, or applies a memory where it doesn't belong. Also covers memory as a prompt-injection surface.
---

# Agent Memory Design

## Overview

Agent memory fails in two opposite directions:

- **It forgets.** The user states a preference once, and the next conversation ignores it.
- **It remembers the wrong thing.** Totals, one-off instructions, inferences, or a line from an email addressed to "any AI assistant" get stored, and live on in every future conversation.

The first makes memory useless; the second makes it dangerous. Both come from decisions made (or skipped) before any library is chosen. **Memory is a set of design decisions, not a component you install.** Once the decisions below are made, picking a store or a framework feature is the easy part.

This skill is about **long-term memory**: facts an agent keeps across conversations. It is not about keeping one long conversation inside the context window.

## The boundary: what is memory, and what isn't

Decide this first. Everything else depends on it.

> **If code reads it, it's a setting. If the agent's records hold it, it's data. Memory is what's left.**

- **A setting** is read by the agent's application code (a timezone, a currency, a default repository). Give it a schema, validation and a proper settings store. Never a memory: the code can't read a memory, and the agent can't validate one.
- **Data** lives in the agent's system of record (transactions, tickets, orders). "You spent $400 on dining" is data. As a memory it is a stale second copy that contradicts the real one the moment a new row lands.
- **A memory** is true, lasting, and read only by the model: "Costco counts as groceries", "in this repo, use pnpm, not npm", "sign off emails as Sam, never Samuel".

What qualifies: **a lasting preference or correction the user stated.** Corrections are the strongest signal: "no, that's not what I meant" means the agent just got it wrong, and the same mistake next time is exactly what memory exists to prevent.

What never qualifies:

- Facts already in the agent's records or settings.
- **One-off instructions** ("skip the tests *just this once*").
- **Inferences** ("you seem to prefer short answers"). Users don't recognize them as their own, and they're the hardest to correct.
- **Anything that came from a document, file, web page or tool result** rather than from the user (see [Memory is persistent prompt injection](#memory-is-persistent-prompt-injection)).

## The five decisions

For each: the options, a default that holds for most single-user agents, and when to choose otherwise.

### 1. What to remember

Covered above. Write the positive definition **and** the never list into the save tool's description, where the model reads it at the moment of deciding. A system-prompt rule is a fallback for a behavior that keeps failing, not the starting point.

### 2. Who decides to save

Options: only when the user asks · whenever the agent decides · both.

**Default: both**, with the agent's side kept narrow (stated preferences and corrections only), and **save without asking first**. "Want me to remember that?" adds a turn to every save; with decision 3 in place it buys nothing.

Choose user-only when users expect full control over what is kept, or when you can't make every write visible.

### 3. Approval or announcement

> **Gate what writes, or shapes writes, to the records. Don't gate what only shapes answers.**

A memory can't approve anything if approval is enforced by the system, not the model; and any effect a memory has on the agent's records still passes through whatever gate guards those records. So memory writes usually don't need a human approval step. They need **visibility**:

- Every save and delete is shown to the user where it happens, never hidden in collapsed tool output.
- **Forget is one click away**, both on that notice and on a page listing every memory.
- Each memory records where it came from (which conversation), so the user can see why it exists.

**Gate memory writes instead** when memories trigger actions (not just shape answers), when memory is shared between users, or when the agent runs unattended and nobody sees the notice.

### 4. How memories reach the model

| Approach | How | Weakness |
| --- | --- | --- |
| Everything up front | Full text of every memory in context, every call | Pays for details most turns don't need |
| **Index + load on demand** | Short titles in context; a tool returns details | The model must notice a title applies |
| Retrieval | Search memories against each message, inject matches | The model can't see what was left out |

**Default: index + load on demand.** The risk is a memory the agent never loads, which looks exactly like no memory. Mitigate it with titles:

- A title names **when** the memory applies: `spending questions: what "food" means`, not `Food`.
- A title can instead **state the whole preference** (`"food" means dining and groceries`). That's cheaper (no lookup) but caps the detail at title length. Choose one style deliberately; the agent's tests will assume it.
- **Rebuild the index on every message.** An index built once per session hides a memory saved earlier in the same session, and a test harness that builds it once per run will grade the harness instead of the agent.

The index can live in the system prompt or in the recall tool's own description; either works.

### 5. Where memories live

**Default: whatever store you already run.** For a list-titles-every-message design, the store is noise until thousands of memories; the **prompt breaks first** (a few hundred titles cost thousands of tokens on every call).

- **A database** gives uniqueness constraints (titles unique, ignoring case), safe concurrent writes, and search when you need it (full-text, vectors).
- **Files** give hand-editing, git history, and a natural fit for agents that already work through filesystem tools. One file per memory degrades on *listing* (every file opened); keep an index file. One JSON file degrades on *writes* and can lose one of two concurrent writes.

## The tools

Three tools, small and single-purpose: **save** (`title`, `content`, optional `replaces` to update in place), **recall** (by id), **forget** (by id, never by search, since a predicate can match more than intended). The behavior lives in their descriptions. Every failure returns something the agent can act on in one step: a duplicate title returns the existing memory and how to replace it; a full memory says so and suggests what to drop; unknown ids come back by name; a forget that matched nothing is an error, not "ok". Full schemas and payloads: [references/tools.md](references/tools.md). For tool design in general, see [`tool-design`](https://github.com/agentailor/skills/tree/main/tool-design).

**Cap the count** and fail loudly at the cap, pushing toward replacing. A cap that's hit is a signal, not a nuisance: see [When it stops scaling](#when-it-stops-scaling).

## Memory is persistent prompt injection

Injection in one turn is bad; injection that gets **remembered** survives into every future conversation. Layer four defenses:

1. **The rule**: never save content that came from a document, file, page or tool result. State it in the save tool's description.
2. **Provenance**: record where each memory came from.
3. **Visibility**: every write is shown, with forget one click away.
4. **No authority**: memory shapes answers; it never approves, and is never read as permission.

## Validation checklist

- [ ] **Bounded** — memory holds stated preferences and corrections only; settings and data have their own stores.
- [ ] **Never-list written** — the save tool's description says what must not be saved, including content from tools and documents.
- [ ] **Visible** — every save and delete is shown to the user where it happens.
- [ ] **Reversible** — forget is one click from the notice and from a page listing every memory.
- [ ] **Traceable** — each memory records where it came from.
- [ ] **Powerless** — no memory can approve, authorize or unlock an action.
- [ ] **Indexed well** — titles name when a memory applies (or deliberately state it), and the index is rebuilt every message.
- [ ] **Updatable** — a new version replaces the old one instead of adding a near-duplicate.
- [ ] **Capped** — a limit exists, and hitting it returns a message the agent can act on.
- [ ] **Honest tools** — duplicates, unknown ids and no-op deletes return actionable errors, never silent success.
- [ ] **Evaluated** — tests grade the **store** (what was written) and the **answer** (whether a memory was applied where it belongs), not whether the agent claimed to remember or called recall.

## Workflows

**Designing memory from scratch** — Draw the boundary first: list what the agent's settings and records already hold, so memory never duplicates them. Then walk the five decisions in order and write down the default or the reason to deviate. Draft the three tools with the never-list in the save description. Decide how a write is shown and forgotten before building storage. Finish with the checklist.

**Reviewing an existing memory design** — Walk the checklist. For each miss, name the failure direction it causes (forgets, or remembers the wrong thing), quote where it happens, and propose the fix. The most common real misses: settings or totals stored as memories, silent writes, an index built once per session, deletion by search, and no never-list.

**Debugging** — Classify the symptom, then check in this order:

- *It forgets* → is the memory saved at all (check the store)? Is it in the index this message? Does its title name the situation the user asked about?
- *It remembers junk* → does the save description carry the never-list? Was the junk a one-off, a fact from the agent's records, an inference, or tool content?
- *It applies a memory where it doesn't fit* → is the title broader than the preference? Test with a question one category narrower than the memory: the answer must not widen.

## Failure modes to avoid

- **Memory as a second database** — totals, balances and settings stored as memories go stale and contradict the source of truth.
- **Asking before every save** — doubles the turns; make the write visible and undoable instead.
- **Silent writes** — a memory the user never saw is one they can't correct.
- **Vague titles** — `Deploys` instead of `deploy requests: staging needs a manual approval first`; the agent never connects it to the question.
- **A stale index** — built once per session or per test run; new memories are invisible.
- **Deleting by search** — a predicate the agent wrote can match more than it meant to. Delete by id.
- **Raising the cap instead of curating** — more memories than the prompt can hold means the boundary is leaking.
- **Grading the call instead of the effect** — recalling a memory that turns out not to apply costs a round trip, and models differ on how eagerly they do it. Grade what was saved and whether a memory was *misapplied*; never fail a run just for calling recall.

## When it stops scaling

Past roughly a hundred memories, a single-user agent is almost certainly storing things it shouldn't: tighten the boundary before anything else. If memory legitimately grows (long-lived or multi-user agents), add a **curator** — a separate, scheduled pass that merges near-duplicates, archives stale preferences and flags memories that contradict the data, proposing every change for approval. Past a few hundred, **stop listing and start searching**; that's where the store choice begins to matter. With several users, scope every memory to its owner and reconsider decision 3.

## References

- [references/tools.md](references/tools.md) — the three memory tools as neutral JSON schemas with their descriptions, and every success and error payload, each explained by the agent failure it prevents.

Files in this skill

  • SKILL.md12.2 KB
  • references/tools.md6.8 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.