> Discover all available pages from the documentation index: https://mastra.ai/llms.txt # Memory.createThread() The `.createThread()` method creates a new conversation thread in the memory system. Each thread represents a distinct conversation or context and can contain multiple messages. ## Usage example ```typescript await memory?.createThread({ resourceId: 'user-123' }) ``` ## 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`): 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`): Additional metadata associated with the thread ## Extended usage example ```typescript import { mastra } from './mastra' const agent = mastra.getAgent('agent') const memory = await agent.getMemory() const thread = await memory?.createThread({ resourceId: 'user-123', title: 'Memory Test Thread', metadata: { source: 'test-script', purpose: 'memory-testing', }, }) const response = await agent.generate('message for agent', { memory: { thread: thread!.id, resource: thread!.resourceId, }, }) console.log(response.text) ``` ### Related - [Memory Class Reference](https://mastra.ai/reference/memory/memory-class) - [Getting Started with Memory](https://mastra.ai/docs/memory/overview) (Covers threads concept) - [getThreadById](https://mastra.ai/reference/memory/getThreadById) - [listThreads](https://mastra.ai/reference/memory/listThreads) - [recall](https://mastra.ai/reference/memory/recall)