@mastra/core
Version:
Mastra is a framework for building AI-powered applications and agents with a modern TypeScript stack.
81 lines • 2.92 kB
TypeScript
import type { Processor } from '..';
import type { MessageList } from '../../agent/message-list/index.js';
import type { IMastraLogger } from '../../logger/index.js';
import type { MastraDBMessage, MemoryConfigInternal } from '../../memory/index.js';
import type { RequestContext } from '../../request-context/index.js';
import type { MemoryStorage } from '../../storage/index.js';
export type WorkingMemoryTemplate = {
format: 'markdown';
content: string;
} | {
format: 'json';
content: string | Record<string, unknown>;
};
export interface WorkingMemoryConfig {
template?: WorkingMemoryTemplate;
/**
* Scope of working memory
* - 'thread': Working memory is scoped to the current thread
* - 'resource': Working memory is shared across all threads for the resource
* @default 'resource'
*/
scope?: 'thread' | 'resource';
useVNext?: boolean;
/**
* When true, working memory is read-only - the data is provided as context
* but no update tools or instructions are included.
* @default false
*/
readOnly?: boolean;
/**
* Optional logger instance for structured logging
*/
logger?: IMastraLogger;
}
/**
* WorkingMemory processor injects working memory data as a system message.
*
* This is an INPUT processor that:
* 1. Retrieves working memory from storage (thread or resource scope)
* 2. Formats it as a system instruction for the LLM
* 3. Prepends it to the message list
*
* Note: Working memory updates happen via the updateWorkingMemory tool,
* not through this processor. The tool is provided by the Memory class.
*/
export declare class WorkingMemory implements Processor {
private options;
readonly id = "working-memory";
name: string;
defaultWorkingMemoryTemplate: string;
private logger?;
constructor(options: {
storage: MemoryStorage;
template?: WorkingMemoryTemplate;
scope?: 'thread' | 'resource';
useVNext?: boolean;
readOnly?: boolean;
templateProvider?: {
getWorkingMemoryTemplate(args: {
memoryConfig?: MemoryConfigInternal;
}): Promise<WorkingMemoryTemplate | null>;
};
logger?: IMastraLogger;
});
processInput(args: {
messages: MastraDBMessage[];
messageList: MessageList;
abort: (reason?: string) => never;
requestContext?: RequestContext;
}): Promise<MessageList | MastraDBMessage[]>;
private generateEmptyFromSchemaInternal;
private getWorkingMemoryToolInstruction;
private getWorkingMemoryToolInstructionVNext;
/**
* Generate read-only working memory instructions.
* This provides the working memory context without any tool update instructions.
* Used when memory is in readOnly mode.
*/
private getReadOnlyWorkingMemoryInstruction;
}
//# sourceMappingURL=working-memory.d.ts.map