Memory API
The Memory API provides methods to manage conversation threads and message history in Mastra.
Memory Thread Operations
Get All Threads
Retrieve all memory threads for a specific resource:
const threads = await client.getMemoryThreads({
resourceid: "resource-1",
});
Create a New Thread
Create a new memory thread:
const thread = await client.createMemoryThread({
title: "New Conversation",
metadata: { category: "support" },
resourceid: "resource-1",
});
Working with a Specific Thread
Get an instance of a specific memory thread:
const thread = client.getMemoryThread("thread-id");
Thread Methods
Get Thread Details
Retrieve details about a specific thread:
const details = await thread.get();
Update Thread
Update thread properties:
const updated = await thread.update({
title: "Updated Title",
metadata: { status: "resolved" },
resourceid: "resource-1",
});
Delete Thread
Delete a thread and its messages:
await thread.delete();
Message Operations
Save Messages
Save messages to memory:
const savedMessages = await client.saveMessageToMemory({
messages: [
{
role: "user",
content: "Hello!",
id: "1",
threadId: "thread-1",
createdAt: new Date(),
type: "text",
},
],
});
Get Memory Status
Check the status of the memory system:
const status = await client.getMemoryStatus();