How to: integrate with Mastra
The @neo4j-labs/agent-memory/integrations/mastra subpath exports
Neo4jMastraMemory — a duck-typed Mastra memory provider backed by a
MemoryClient. Hand it to new Agent({ memory }) and your agent gets
graph-backed conversation history and entity memory.
A runnable example lives at
clients/typescript/examples/mastra.
Wiring
import { Agent } from "@mastra/core/agent";
import { MemoryClient } from "@neo4j-labs/agent-memory";
import { Neo4jMastraMemory } from "@neo4j-labs/agent-memory/integrations/mastra";
const memory = new Neo4jMastraMemory(new MemoryClient());
const agent = new Agent({
name: "scout",
instructions: "You help users plan trips.",
memory,
});
What the adapter implements
-
createThread({ resourceId, title?, metadata? })— wrapscreateConversation.resourceIdbecomes theuserId. -
getMessages(threadId, { limit? })— wrapsgetConversation. -
saveMessage({ threadId, role, content, metadata? })— wrapsaddMessage. -
deleteThread(threadId)— wrapsdeleteConversation.
Bridge transports (TCK conformance servers, local reference) don’t
implement createConversation; in that case createThread synthesizes
a thread id from the supplied resourceId.