본문으로 건너뛰기

마스트라.getMemory()

그만큼.getMemory()메소드는 해당 키를 사용하여 Mastra 레지스트리에서 Memory 인스턴스를 검색합니다. Memory 인스턴스는 Mastra 생성자에 등록되며 저장된 Agent에서 참조할 수 있습니다.

사용예
사용예에 대한 직접 링크

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 등록 및 검색
예: Memory 등록 및 검색에 대한 직접 링크

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')