> Discover all available pages from the documentation index: https://mastra.zisheng.pro/llms.txt # Mastra.getMemory() `.getMemory()` 方法按键从 Mastra 注册表获取 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/reference/core/listMemory) - [Memory 概览](https://mastra.zisheng.pro/docs/memory/overview)