워킹Memory
그만큼WorkingMemory은입력 프로세서작업 Memory 데이터를 시스템 메시지로 주입합니다. 이는 저장소에서 영구 정보를 검색하고 LLM에 대한 지침으로 형식을 지정하여 Agent가 대화 전반에 걸쳐 사용자에 대한 컨텍스트를 유지할 수 있도록 합니다.
사용예사용예에 대한 직접 링크
import { WorkingMemory } from '@mastra/core/processors'
const processor = new WorkingMemory({
storage: memoryStorage,
scope: 'resource',
template: {
format: 'markdown',
content: `# User Profile
- **Name**:
- **Preferences**:
- **Goals**:
`,
},
})
생성자 매개변수생성자 매개변수에 대한 직접 링크
options:
Options
작업 Memory 프로세서의 구성 옵션입니다
Options
storage:
MemoryStorage
작업 Memory 데이터를 가져오는 데 사용할 저장소 인스턴스입니다
template?:
WorkingMemoryTemplate
작업 Memory의 형식과 구조를 정의하는 템플릿입니다
WorkingMemoryTemplate
format:
'markdown' | 'json'
작업 Memory 콘텐츠의 형식입니다
content:
string
작업 Memory 데이터의 구조를 정의하는 템플릿 콘텐츠입니다
scope?:
'thread' | 'resource'
작업 Memory의 범위입니다. 'thread'는 현재 스레드로 범위를 한정하고, 'resource'는 해당 리소스의 모든 스레드에서 공유합니다
useVNext?:
boolean
개선된 지침을 포함한 차세대 지침 형식을 사용합니다
readOnly?:
boolean
true이면 작업 Memory가 읽기 전용 컨텍스트로 제공됩니다. 데이터가 대화에 주입되지만 updateWorkingMemory Tool이나 업데이트 지침은 포함되지 않습니다. 작업 Memory를 수정하지 않고 참조해야 하는 Agent에 유용합니다.
templateProvider?:
{ getWorkingMemoryTemplate(args: { memoryConfig?: MemoryConfig }): Promise<WorkingMemoryTemplate | null> }
런타임 템플릿 확인을 위한 동적 템플릿 Provider입니다
logger?:
IMastraLogger
구조화된 로깅을 위한 선택적 로거 인스턴스입니다
보고보고에 대한 직접 링크
id:
string
'working-memory'로 설정된 프로세서 식별자입니다
name:
string
'WorkingMemory'로 설정된 프로세서 표시 이름입니다
defaultWorkingMemoryTemplate:
string
사용자 지정 템플릿이 제공되지 않았을 때 사용하는 기본 Markdown 템플릿입니다
processInput:
(args: { messages: MastraDBMessage[]; messageList: MessageList; abort: (reason?: string) => never; requestContext?: RequestContext }) => Promise<MessageList | MastraDBMessage[]>
작업 Memory를 가져와 메시지 목록에 시스템 메시지로 추가합니다
확장된 사용 예확장된 사용 예에 대한 직접 링크
src/mastra/agents/personalized-agent.ts
import { Agent } from '@mastra/core/agent'
import { WorkingMemory, MessageHistory } from '@mastra/core/processors'
import { PostgresStorage } from '@mastra/pg'
const storage = new PostgresStorage({
connectionString: process.env.DATABASE_URL,
})
export const agent = new Agent({
id: 'personalized-agent',
name: 'personalized-agent',
instructions: 'You are a helpful assistant that remembers user preferences',
model: 'openai/gpt-5.6-sol',
inputProcessors: [
new WorkingMemory({
storage,
scope: 'resource',
template: {
format: 'markdown',
content: `# User Information
- **Name**:
- **Location**:
- **Preferences**:
- **Communication Style**:
- **Current Projects**:
`,
},
}),
new MessageHistory({ storage, lastMessages: 50 }),
],
outputProcessors: [new MessageHistory({ storage })],
})
JSON 형식의 예JSON 형식의 예에 대한 직접 링크
import { WorkingMemory } from '@mastra/core/processors'
const processor = new WorkingMemory({
storage: memoryStorage,
scope: 'resource',
template: {
format: 'json',
content: JSON.stringify({
user: {
name: { type: 'string' },
preferences: { type: 'object' },
goals: { type: 'array' },
},
}),
},
})
행동행동에 대한 직접 링크
입력 처리입력 처리에 대한 직접 링크
- 요청 컨텍스트에서
threadId및resourceId를 가져옵니다 - 범위에 따라 다음 중 하나에서 작업 Memory를 가져옵니다.
- 스레드 메타데이터(
scope: 'thread') - 리소스 레코드(
scope: 'resource')
- 스레드 메타데이터(
- 템플릿(Provider, 옵션 또는 기본값)을 확인합니다.
- 모드에 따라 시스템 지침을 생성합니다.
- 일반 모드: 정보, 템플릿 구조, 현재 데이터 저장/업데이트에 대한 지침이 포함됩니다.
- 읽기 전용 모드 (
readOnly: true): 업데이트 지침 없이 현재 데이터만 컨텍스트로 포함합니다
- 지침을
source: 'memory'태그가 있는 시스템 메시지로 추가합니다
작업 기억 업데이트작업 기억 업데이트에 대한 직접 링크
작업 Memory 업데이트는 이 프로세서가 아니라 Memory 클래스가 제공하는 updateWorkingMemory Tool을 통해 이루어집니다. 이 프로세서는 현재 작업 Memory 상태를 대화에 주입하는 작업만 처리합니다.
기본 템플릿기본 템플릿에 대한 직접 링크
템플릿이 제공되지 않으면 프로세서는 다음 필드가 포함된 기본 마크다운 템플릿을 사용합니다.
- 이름, 성
- 위치, 직업
- 관심분야, 목표
- 이벤트, 사실, 프로젝트