(ctx: ExecutionContext, inputs: AgentInputs, messages: Message[])
| 76 | } |
| 77 | |
| 78 | async seedMemory(ctx: ExecutionContext, inputs: AgentInputs, messages: Message[]): Promise<void> { |
| 79 | if (!inputs.memoryType || inputs.memoryType === 'none') { |
| 80 | return |
| 81 | } |
| 82 | |
| 83 | const workspaceId = this.requireWorkspaceId(ctx) |
| 84 | |
| 85 | const conversationMessages = messages.filter((m) => m.role !== 'system') |
| 86 | if (conversationMessages.length === 0) { |
| 87 | return |
| 88 | } |
| 89 | |
| 90 | this.validateConversationId(inputs.conversationId) |
| 91 | |
| 92 | const key = inputs.conversationId! |
| 93 | |
| 94 | let messagesToStore = conversationMessages |
| 95 | if (inputs.memoryType === 'sliding_window') { |
| 96 | const limit = this.parsePositiveInt( |
| 97 | inputs.slidingWindowSize, |
| 98 | MEMORY.DEFAULT_SLIDING_WINDOW_SIZE |
| 99 | ) |
| 100 | messagesToStore = this.applyWindow(conversationMessages, limit) |
| 101 | } else if (inputs.memoryType === 'sliding_window_tokens') { |
| 102 | const maxTokens = this.parsePositiveInt( |
| 103 | inputs.slidingWindowTokens, |
| 104 | MEMORY.DEFAULT_SLIDING_WINDOW_TOKENS |
| 105 | ) |
| 106 | messagesToStore = this.applyTokenWindow(conversationMessages, maxTokens, inputs.model) |
| 107 | } |
| 108 | |
| 109 | messagesToStore = await Promise.all( |
| 110 | messagesToStore.map((message) => this.maskContentForStorage(ctx, message)) |
| 111 | ) |
| 112 | |
| 113 | await this.seedMemoryRecord(workspaceId, key, messagesToStore) |
| 114 | |
| 115 | logger.debug('Seeded memory', { |
| 116 | workspaceId, |
| 117 | key, |
| 118 | count: messagesToStore.length, |
| 119 | }) |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Handlers persist messages to memory before the executor redacts block |
no test coverage detected