> Discover all available pages from the documentation index: https://mastra.zisheng.pro/ko/llms.txt # 워킹Memory 그만큼`WorkingMemory`은**입력 프로세서**작업 Memory 데이터를 시스템 메시지로 주입합니다. 이는 저장소에서 영구 정보를 검색하고 LLM에 대한 지침으로 형식을 지정하여 Agent가 대화 전반에 걸쳐 사용자에 대한 컨텍스트를 유지할 수 있도록 합니다. ## 사용예 ```typescript 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 데이터를 가져오는 데 사용할 저장소 인스턴스입니다 **options.template** (`WorkingMemoryTemplate`): 작업 Memory의 형식과 구조를 정의하는 템플릿입니다 **options.template.format** (`'markdown' | 'json'`): 작업 Memory 콘텐츠의 형식입니다 **options.template.content** (`string`): 작업 Memory 데이터의 구조를 정의하는 템플릿 콘텐츠입니다 **options.scope** (`'thread' | 'resource'`): 작업 Memory의 범위입니다. 'thread'는 현재 스레드로 범위를 한정하고, 'resource'는 해당 리소스의 모든 스레드에서 공유합니다 **options.useVNext** (`boolean`): 개선된 지침을 포함한 차세대 지침 형식을 사용합니다 **options.readOnly** (`boolean`): true이면 작업 Memory가 읽기 전용 컨텍스트로 제공됩니다. 데이터가 대화에 주입되지만 updateWorkingMemory Tool이나 업데이트 지침은 포함되지 않습니다. 작업 Memory를 수정하지 않고 참조해야 하는 Agent에 유용합니다. **options.templateProvider** (`{ getWorkingMemoryTemplate(args: { memoryConfig?: MemoryConfig }): Promise }`): 런타임 템플릿 확인을 위한 동적 템플릿 Provider입니다 **options.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`): 작업 Memory를 가져와 메시지 목록에 시스템 메시지로 추가합니다 ## 확장된 사용 예 ```typescript 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 형식의 예 ```typescript 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' }, }, }), }, }) ``` ## 행동 ### 입력 처리 1. 요청 컨텍스트에서 `threadId` 및 `resourceId`를 가져옵니다 2. 범위에 따라 다음 중 하나에서 작업 Memory를 가져옵니다. - 스레드 메타데이터(`scope: 'thread'`) - 리소스 레코드(`scope: 'resource'`) 3. 템플릿(Provider, 옵션 또는 기본값)을 확인합니다. 4. 모드에 따라 시스템 지침을 생성합니다. - **일반 모드**: 정보, 템플릿 구조, 현재 데이터 저장/업데이트에 대한 지침이 포함됩니다. - **읽기 전용 모드** (`readOnly: true`): 업데이트 지침 없이 현재 데이터만 컨텍스트로 포함합니다 5. 지침을 `source: 'memory'` 태그가 있는 시스템 메시지로 추가합니다 ### 작업 기억 업데이트 작업 Memory 업데이트는 이 프로세서가 아니라 Memory 클래스가 제공하는 `updateWorkingMemory` Tool을 통해 이루어집니다. 이 프로세서는 현재 작업 Memory 상태를 대화에 주입하는 작업만 처리합니다. ### 기본 템플릿 템플릿이 제공되지 않으면 프로세서는 다음 필드가 포함된 기본 마크다운 템플릿을 사용합니다. - 이름, 성 - 위치, 직업 - 관심분야, 목표 - 이벤트, 사실, 프로젝트 ## 관련된 - [난간](https://mastra.zisheng.pro/ko/docs/agents/guardrails)