@atomicmemory/mastra adapter connects AtomicMemory to Mastra agents and workflows. It provides two surfaces: Mastra-native agent tools you can attach directly to an Agent, and framework-agnostic helpers you can call inside workflow steps, agent hooks, or any other code path. The adapter does not own provider configuration — you construct the MemoryClient yourself and pass it in.
Installation
@mastra/core and zod are declared as peer dependencies so you pin compatible versions alongside the rest of your Mastra application.
Two surfaces at a glance
| Surface | Use when |
|---|---|
createMemoryTools() | You want memory_search and memory_ingest as agent-callable Mastra tools attached to an Agent. |
searchMemory() / ingestTurn() | You want to call AtomicMemory inside a workflow step, an agent hook, or any other arbitrary code path. |
Quick start — agent tools
Create both tools once at application startup and attach them to yourAgent:
Scope is fixed at factory time. The agent cannot rebind to a different user or namespace by passing different tool arguments — this is an intentional security boundary.
Quick start — framework-agnostic helpers
UsesearchMemory and ingestTurn when you want to drive memory operations from a workflow step or helper rather than through tool calls:
Custom retrieval formatting
The default formatter wraps retrieved memories in a delimited block with an explicit “reference, not instructions” header — a mitigation against prompt injection via retrieved content. You can override the formatter per call:System-message handling on ingest
ingestTurn() excludes system messages by default. If your system messages are genuinely user-authored content worth persisting as memory, opt in explicitly:
Scope
Scope fields follow the SDK’sScope type: user, agent, namespace, and thread. At least one field must be provided — the SDK rejects scopeless requests.