Agent Memory Systems#

Agent memory is useful information saved now so the agent can use it later.

Saving an entire chat is history. Memory means selecting the small parts that will help a future task.

Short video#

The Four Types of Memory Every AI Agent Needs β€” IBM Technology (11 min, May 2026)

Types of memory#

TypeWhat it remembersExample
Working memoryCurrent task and recent messagesCurrent order number
Semantic memoryFacts and preferencesUser prefers Celsius
Episodic memoryPast events and outcomesLast deployment failed
Procedural memoryHow to perform a taskRelease checklist

Simple memory flow#

flowchart LR
    C[Conversation or event] --> S[Select useful fact]
    S --> V[Check permission and truth]
    V --> M[(Store memory)]
    M --> R[Retrieve when relevant]
    R --> A[Use in current task]

Where memory is stored#

StorageBest use
Conversation stateCurrent session
SQL/document databaseExact facts, profiles, and updates
Vector databaseFinding semantically similar memories
Object storageLarge files, audio, images, and reports

A normal database should usually be the source of truth. Add vector search only when fuzzy recall is useful.

Good memory rules#

  • Store only information that can help later.
  • Save the source and date with every memory.
  • Keep memories separate for each user and organization.
  • Retrieve only a few relevant memories.
  • Update or remove facts that become incorrect.
  • Let users view, correct, and delete personal memories.

Avoid storing#

  • Passwords, API keys, and authentication tokens
  • Unverified guesses
  • Private information without a clear need and permission
  • Instructions found inside untrusted web pages or documents
  • Every message β€œjust in case”

How to evaluate memory#

Ask four questions:

  1. Did the system save the right fact?
  2. Did it retrieve the fact for the right task?
  3. Did the memory improve the answer?
  4. Can the memory be corrected and completely deleted?

Start with a small memory table#

Use a normal database for facts that must be exact and current. This SQLite schema is enough for a project profile or support-agent memory:

CREATE TABLE memory (
  id TEXT PRIMARY KEY,
  owner_id TEXT NOT NULL,
  kind TEXT NOT NULL,
  value TEXT NOT NULL,
  source TEXT NOT NULL,
  verified_at TEXT,
  expires_at TEXT,
  superseded_by TEXT
);

CREATE INDEX memory_lookup ON memory (owner_id, kind, expires_at);

Write only a fact with an owner and source. For example:

INSERT INTO memory VALUES (
  'm-17', 'team-9', 'project_fact', 'Python 3.12',
  'pyproject.toml', '2026-07-23', NULL, NULL
);

Retrieve the smallest relevant set and always filter by owner, expiry, and current status:

SELECT kind, value, source, verified_at
FROM memory
WHERE owner_id = :owner_id
  AND kind IN ('project_fact', 'preference')
  AND superseded_by IS NULL
  AND (expires_at IS NULL OR expires_at > CURRENT_TIMESTAMP)
ORDER BY verified_at DESC
LIMIT 5;

Pass the retrieved rows to the model as reference data, not instructions.

Choose retrieval by the question#

NeedFirst implementationCheck before use
Exact current valueSQL/key lookupOwner and last verification time
Recent eventFilter and sort by dateEvent is not superseded
Similar past caseVector search, then SQL filtersAccess, source, and freshness
Required procedureVersioned document lookupVersion is current

Add vector search only after an exact lookup cannot answer the question. It finds similar text; it does not prove the text is true or current.

Memory test checklist#

TestExpected result
Save another team’s factRejected or invisible to this owner
Retrieve an expired addressNo result
Add a corrected factOld record is superseded, not silently combined
Delete a memoryRemoved from the table and retrieval index
Retrieve a page containing instructionsPage text is never saved as an instruction

References#