Skip to main content
A session remembers one conversation. Memory is what an agent keeps across conversations: a user’s preferences, facts it was told, decisions made last week. You give an agent one or more named memory slots; each slot stores short text items through a provider and is keyed by a scope (one memory for everybody, one per session, or one per user). For each slot, createAgent({ memory }):
  1. Recalls at the start of every run (send(), stream(), each session turn): on the run’s first model call, the newest items go into the system prompt in a <memory name="..."> block. The block stays for the rest of the run and is not saved in the session transcript.
  2. Gives the model a remember_<name> tool (input { text }) to store a new item, and a recall_<name> tool (input { query?, limit? }) to search the slot, newest items first.

Memory in code

The system prompt of the second conversation ends with:

Scopes

A run reads and writes the items of its scope key: A scope function sees the run’s sessionId and the metadata passed to send() / stream(), so you can keep one memory per user across all their sessions:
When a run has no scope key (a 'session' slot in a send() without a sessionId, or a scope function that returns undefined), the slot is off for that run: nothing is recalled and its tools are not offered.

Configuration options

defineMemory(options) returns a MemorySlot: A slot with expose: { remember: false } is read-only for the model: you fill it from code with provider.add(scopeKey, { text }).

Providers

All keep at most maxItems items per scope key (default 1000; adding one more drops the oldest) and match a query by keyword: an item matches when it contains one of the query’s words of three or more letters, ignoring case.

SQLite

Pass the same SqliteStore to the agent and to the provider, and sessions, checkpoints and memory share one database file. An existing file gains the table when it is opened. Keep the store open while the agent runs.
For semantic search or a hosted store, implement MemoryProvider:

Testing memory

With mockModel, assert on the system prompt of the first request and drive the tools with scripted tool calls:

Limitations

  • Recall and the memory tools apply to the agent’s own runs, not to its sub-agents. When agent.approvals.resolve() continues a run after an approval pause, the recalled block stays in the prompt but the memory tools are not offered for the rest of that run.
  • An agent directory’s memory/ folder is part of the agent: see Agent directories.