# AI Agent Memory Architecture: Storage Backends Per Layer

Published 2026-12-01. https://kanbanmcp.com/blog/ai-agent-memory-architecture-storage

# AI Agent Memory Architecture: Storage Backends Per Layer

## Key takeaways

- Split agent memory into working, episodic, semantic, and procedural layers, each with its own storage backend and retrieval trigger.
- Inject working memory every turn via card notes, but trigger episodic recall only on events like card claims to save tokens.
- Use a relational table for known queries like task state, and reserve vector stores for fuzzy recall of past sessions.
- Store procedural memory as checked-in playbooks or card notes so the next agent retrieves it without reading chat logs.
- Namespace shared backends with a project_id column to prevent context bleed between unrelated projects.

A working ai agent memory architecture splits memory into four layers: working (session state), episodic (past runs), semantic (project facts), and procedural (learned workflows), each with its own storage backend and retrieval trigger. For a solo dev running 2-5 coding agents, that means one SQLite table per layer, not one shared store, and this guide gives you the exact schema, triggers, and code patterns for n8n and Pydantic AI.

## What are the four layers of an ai agent memory architecture?

Four layers, each with a different lifespan and retrieval trigger:

| Layer | What it holds | Storage backend | Retrieval trigger |
|---|---|---|---|
| Working memory | The current task and its context | The agent session itself | Always in context |
| Episodic memory | What happened in past sessions | Chat logs, session summaries | Pulled in when a task resumes |
| Semantic memory | Project facts and decisions | Notes, README, task board as system of record | Loaded at task start |
| Procedural memory | Workflows that worked before | Checked-in scripts, prompts, runbooks | Matched when a similar task appears |

Chat sessions sit outside all four layers. They are working memory only, and they evaporate. If a project lives only across chats, you lose the context of the project weeks later, which is the failure most solo developers hit first.

The practical mapping: the task board is your system of record, notes hold semantic memory, workflows live in the repo, and chat sessions stay disposable. [KanbanMCP](https://kanbanmcp.com/agent-memory) treats the board as the shared layer, where an agent claims a card and leaves a note for the next one. Pydantic AI structures this through dependencies and output schemas ([docs.pydantic.dev](https://docs.pydantic.dev)), which is how you keep each layer typed and retrievable instead of buried in prose.

## How do working memory and episodic memory differ in retrieval triggers?

Working memory gets injected every turn: system prompt, current card context, the agent's claim. Episodic memory gets pulled on demand, when a query or event asks for it. Mixing the two is how you get context bleed and repeating logic that used to work.

### Injecting working memory: the card note pattern

Put the working state on the card itself. An agent claims a card, does the work, and leaves a note for the next one: what it tried, what broke, what's left. The next agent's working memory is just that note plus the card title, nothing more. This is the pattern behind [KanbanMCP](https://kanbanmcp.com/), where the board is the system of record and chat sessions stay disposable. The trigger is structural: the note loads because the card was claimed, not because anyone remembered to paste it.

### Episodic recall: query-on-claim, not query-every-turn

Episodic retrieval should fire on events, not every turn. Good triggers: card claimed (pull prior notes on sibling cards), card moved to done (store what worked), session start (pull the last three notes on this project). Query-every-turn burns tokens and buries the current card under stale sessions. If a project only exists across chats, you can't recover the context of the project a week later; event-triggered recall fixes that without Obsidian-style density that becomes too much for management.

## How do you implement a memory bank in n8n vs Pydantic AI?

The difference is where retrieval lives: n8n puts it in workflow nodes you wire by hand, Pydantic AI puts it in typed dependencies your agent code reads and writes.

### n8n: sub-workflow as retrieval trigger

n8n gives you dedicated memory nodes (buffer window, Redis, Postgres chat memory) attached to an AI Agent node, so working memory is configured, not coded ([n8n docs](https://docs.n8n.io)). The pattern that scales past a demo is a sub-workflow as your retrieval trigger: one workflow that takes a query and a project id, hits Postgres for semantic memory and Redis for recent context, and returns a single formatted block. Your main agent workflow calls it once at the start, injects the result into the system prompt, and calls a mirror sub-workflow at the end to write back. That keeps the system of record in one place and makes every agent session disposable, because recovery is just "call the retrieval workflow again".

### Pydantic AI: typed memory via dependencies and output schemas

In Pydantic AI, memory enters through `deps`: a dataclass holding the project id, a database connection, and whatever typed state models you want the agent to see. Retrieval is a function call in a tool or in `deps` setup, and the output schema forces the agent to write back structured notes instead of freeform chat. The trade is honest: you write more code, but every memory write has a type, so a week later you can query it without re-reading a transcript. The same split applies to our own board: KanbanMCP holds the system of record, each agent claims a card and leaves a typed note for the next one, and you connect any MCP client at [https://kanbanmcp.com/docs/connect](https://kanbanmcp.com/docs/connect). Where it falls short: KanbanMCP has no vector retrieval, so semantic memory still needs a separate store.

## When should you use a vector store vs a relational table for semantic memory?

Use a relational table when you know what you're looking for: task state, decisions, card ownership, anything you filter or update by column. Use a vector store when you don't: fuzzy recall of a past session's notes, "didn't another agent solve something like this in March?" Retrieval triggers differ too. Rows get queried when an agent claims a card; vectors get searched when context bleed sets in and the agent starts repeating logic that used to work.

### The boring default: SQLite/Postgres first

Most solo setups need neither at first. A single `decisions` table with a project_id, a note, and a timestamp covers 80% of semantic memory, and it's greppable. Add embeddings only when plain search fails you, and even then embed just the session summaries, not every message.

The honest gap: KanbanMCP (https://kanbanmcp.com/agents) keeps the system of record on cards with agent handoff notes, which is relational thinking by default. It has no vector search, so recovering context from months-old sessions means reading notes, not querying them. If that becomes your bottleneck, bolt a vector index on top of your own summaries.

## How do you structure procedural memory so agents reuse learned workflows?

Procedural memory is the workflow an agent figured out once and should never have to rediscover: the deploy order, the migration gotcha, the test command that has to run before commit. Store it as a checked-in playbook or a card note, not a chat log. The pattern is simple: write the workflow where the next agent will actually retrieve it, which means the card it claims, not a session it never sees.

### Card notes as the retrieval point

When an agent claims a card, the note is the first thing it reads. That makes the card the natural handoff point: the previous agent leaves the working steps, the next one picks them up without reading back through hundreds of chats and sessions. Keep the note short and imperative, one workflow per note, so it reads like a runbook rather than a transcript.

Treat the board as the system of record and the notes as working memory, and keep chat sessions disposable. Anything that must survive belongs in a relational table or a markdown file in the repo; SQLite's documentation covers the durability guarantees that make a single-file store enough for most solo setups ([SQLite documentation](https://www.sqlite.org/docs.html)). KanbanMCP handles the claim-and-leave-a-note flow on the board itself, with the mechanics described on [KanbanMCP features](https://kanbanmcp.com/features).

Where this falls short: a card note only helps if the next agent claims that card. Workflows that apply across projects still need a repo-level playbook file, and nothing here searches notes semantically.

## What are the failure modes when memory layers share the same storage backend?

### Context bleed between projects

When working memory and episodic logs for all projects share one table or one vector collection, an agent working on your billing bug retrieves notes from your scraper project because both mention "retry logic". The fix is namespacing: separate collections or a project_id column on every row, and filter at query time, not after retrieval. A shared backend is fine if every query carries a project scope.

### Stale facts beating fresh state

If semantic facts ("we use SQLite") live in the same table as task state ("task 12: migrate to Postgres"), similarity search returns the old fact with the same confidence as the fresh task. Fix: split layers. Task state goes in a relational table you overwrite; semantic facts get a version and a timestamp so retrieval prefers the newest. The pgvector docs cover the hybrid query pattern for mixing filters with similarity search: [pgvector README](https://github.com/pgvector/pgvector).

Two more failure modes worth naming: unbounded episodic logs slow every retrieval as the table grows, so prune or summarise weekly; and procedural memory stored only in chat history drifts, because the playbook nobody pinned gets paraphrased differently each session. Promote stable workflows to a file or table once they repeat.

## What does a minimal ai agent memory architecture look like in practice?

For a solo dev running 2-5 agents, the minimal setup is: a board as the system of record, per-card notes as working memory, one flat notes store for episodic recall, and chat sessions treated as disposable.

### Where a shared board covers two of the four layers

A Kanban card is your working memory and procedural handoff. An agent claims a card, does the work, and leaves a note: what it tried, what broke, what the next agent should pick up. You watch the same board and steer. This is what KanbanMCP does — the card carries the context, so no agent starts a session with no idea what the last one was doing.

### Where you still need to build the other two

Honest limits: KanbanMCP has no vector recall and no embedded semantic store. Episodic memory (a week-old decision) and semantic memory (reusable facts) need a separate notes file or table you point agents at. If a project lives only across chats, you lose the context of the project a week later — the board plus one notes store fixes most of that without more process than you need.

## FAQ

### What are the four types of memory in an AI agent?

Working, episodic, semantic, and procedural. Working memory is the current session context. Episodic memory records what happened in past sessions. Semantic memory holds project facts and decisions. Procedural memory stores workflows that worked before, like deploy steps. Each layer has a different lifespan and retrieval trigger, requiring its own storage backend.

### How do I give my custom AI agent memory?

Split memory into layers and give each a home. Put working state on the task card. Store episodic summaries in a flat notes table, queried when a task resumes. Keep semantic facts in a relational table with timestamps. Promote repeated workflows to checked-in playbooks. Treat chat sessions as disposable, and fire retrieval on events like card claims.

### Does n8n have memory for AI agents?

Yes. n8n offers memory nodes, including buffer window, Redis, and Postgres chat memory, that attach to an AI Agent node so working memory is configured rather than coded. For production, use a sub-workflow as your retrieval trigger: it queries Postgres and Redis once at session start, returns a formatted block, and a mirror sub-workflow writes results back.

### How do I add memory to a Pydantic AI agent?

Pass memory through deps: a dataclass holding the project id, a database connection, and typed state models the agent can read. Retrieval is a function call in a tool or during deps setup. Define an output schema so the agent writes back structured notes instead of freeform chat. You write more code, but every memory write has a type and stays queryable later.

### Should agent memory be a vector database or a regular database?

Use a regular database when you know what you are looking for, like task state, decisions, or ownership. Use a vector store for fuzzy recall, like finding a past session that solved a similar problem. Most solo setups should start with SQLite or Postgres. Add embeddings only when plain search fails, and embed summaries, not every message.
