(ctx: ExecutionContext, inputs: AgentInputs)
| 14 | |
| 15 | export class Memory { |
| 16 | async fetchMemoryMessages(ctx: ExecutionContext, inputs: AgentInputs): Promise<Message[]> { |
| 17 | if (!inputs.memoryType || inputs.memoryType === 'none') { |
| 18 | return [] |
| 19 | } |
| 20 | |
| 21 | const workspaceId = this.requireWorkspaceId(ctx) |
| 22 | this.validateConversationId(inputs.conversationId) |
| 23 | |
| 24 | const messages = await this.fetchMemory(workspaceId, inputs.conversationId!) |
| 25 | |
| 26 | switch (inputs.memoryType) { |
| 27 | case 'conversation': |
| 28 | return this.applyContextWindowLimit(messages, inputs.model) |
| 29 | |
| 30 | case 'sliding_window': { |
| 31 | const limit = this.parsePositiveInt( |
| 32 | inputs.slidingWindowSize, |
| 33 | MEMORY.DEFAULT_SLIDING_WINDOW_SIZE |
| 34 | ) |
| 35 | return this.applyWindow(messages, limit) |
| 36 | } |
| 37 | |
| 38 | case 'sliding_window_tokens': { |
| 39 | const maxTokens = this.parsePositiveInt( |
| 40 | inputs.slidingWindowTokens, |
| 41 | MEMORY.DEFAULT_SLIDING_WINDOW_TOKENS |
| 42 | ) |
| 43 | return this.applyTokenWindow(messages, maxTokens, inputs.model) |
| 44 | } |
| 45 | |
| 46 | default: |
| 47 | return messages |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | async appendToMemory( |
| 52 | ctx: ExecutionContext, |
no test coverage detected