跳到主要内容

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"]