createAgent({ memory }):
- 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. - Gives the model a
remember_<name>tool (input{ text }) to store a new item, and arecall_<name>tool (input{ query?, limit? }) to search the slot, newest items first.
Memory in code
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:
'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 sameSqliteStore 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.
MemoryProvider:
Testing memory
WithmockModel, 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.