Mastra.listMemory()
.listMemory() 方法返回所有在 Mastra 实例中注册的内存实例。
🌐 The .listMemory() method returns all memory instances registered with the Mastra instance.
使用示例Direct link to 使用示例
🌐 Usage example
const memoryInstances = mastra.listMemory();
for (const [key, memory] of Object.entries(memoryInstances)) {
console.log(`Memory "${key}": ${memory.id}`);
}
参数Direct link to 参数
🌐 Parameters
此方法不接受任何参数。
🌐 This method takes no parameters.
返回Direct link to 返回
🌐 Returns
memory:
Record<string, MastraMemory>
An object containing all registered memory instances, keyed by their registry keys.
示例:检查注册内存Direct link to 示例:检查注册内存
🌐 Example: Checking Registered Memory
import { Mastra } from "@mastra/core";
import { Memory } from "@mastra/memory";
import { LibSQLStore } from "@mastra/libsql";
const conversationMemory = new Memory({
id: "conversation-memory",
storage: new LibSQLStore({ id: 'conversation-store', url: ":memory:" }),
});
const analyticsMemory = new Memory({
id: "analytics-memory",
storage: new LibSQLStore({ id: 'analytics-store', url: ":memory:" }),
});
const mastra = new Mastra({
memory: {
conversationMemory,
analyticsMemory,
},
});
// List all registered memory instances
const allMemory = mastra.listMemory();
console.log(Object.keys(allMemory)); // ["conversationMemory", "analyticsMemory"]
相关Direct link to 相关
🌐 Related