> Discover all available pages from the documentation index: https://mastra.zisheng.pro/zh-TW/llms.txt # Mastra.getMemory() `.getMemory()` 方法依鍵從 Mastra registry 取得 Memory 執行個體。Memory 執行個體在 Mastra 建構函式中註冊,可供已儲存的 Agent 參照。 ## 使用範例 ```typescript const memory = mastra.getMemory('conversationMemory') // Use the memory instance const thread = await memory.createThread({ resourceId: 'user-123', title: 'New Conversation', }) ``` ## 參數 **key** (`TMemoryKey extends keyof TMemory`): 要取得的 Memory 執行個體的註冊鍵。必須與在 Mastra 建構函式中註冊 Memory 時使用的鍵相符。 ## 傳回值 **memory** (`TMemory[TMemoryKey]`): 具有指定鍵的 Memory 執行個體。如果找不到該 Memory,則擲回錯誤。 ## 範例:註冊和取得 Memory ```typescript import { Mastra } from '@mastra/core' import { Memory } from '@mastra/memory' import { LibSQLStore } from '@mastra/libsql' const conversationMemory = new Memory({ storage: new LibSQLStore({ id: 'conversation-store', url: ':memory:' }), }) const mastra = new Mastra({ memory: { conversationMemory, }, }) // Later, retrieve the memory instance const memory = mastra.getMemory('conversationMemory') ``` ## 相關內容 - [Mastra.listMemory()](https://mastra.zisheng.pro/zh-TW/reference/core/listMemory) - [Memory 概覽](https://mastra.zisheng.pro/zh-TW/docs/memory/overview)