Mastra.listMemory()
.listMemory() 方法返回 Mastra 实例中注册的所有 Memory 实例。
使用示例使用示例的直接链接
const memoryInstances = mastra.listMemory()
for (const [key, memory] of Object.entries(memoryInstances)) {
console.log(`Memory "${key}": ${memory.id}`)
}
参数参数的直接链接
此方法不接受任何参数。
返回值返回值的直接链接
memory:
Record<string, MastraMemory>
包含所有已注册 Memory 实例的对象,以其注册键作为键。
示例:检查已注册的 Memory示例:检查已注册的 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"]