DocsReferenceMemory.createThread()

createThread

Creates a new conversation thread in the memory system. Each thread represents a distinct conversation or context and can contain multiple messages.

Usage Example

import { Memory } from "@mastra/memory";
 
const memory = new Memory({ /* config */ });
const thread = await memory.createThread({
  resourceId: "user-123",
  title: "Support Conversation",
  metadata: {
    category: "support",
    priority: "high"
  }
});

Parameters

resourceId:

string
Identifier for the resource this thread belongs to (e.g., user ID, project ID)

threadId?:

string
Optional custom ID for the thread. If not provided, one will be generated.

title?:

string
Optional title for the thread

metadata?:

Record<string, unknown>
Optional metadata to associate with the thread

Returns

id:

string
Unique identifier of the created thread

resourceId:

string
Resource ID associated with the thread

title:

string
Title of the thread (if provided)

createdAt:

Date
Timestamp when the thread was created

updatedAt:

Date
Timestamp when the thread was last updated

metadata:

Record<string, unknown>
Additional metadata associated with the thread