n8n-nodes-better-ai-agent
Version:
A better AI Agent node for n8n with improved memory management and modern AI SDK integration
35 lines (34 loc) • 1.59 kB
TypeScript
import type { CoreMessage } from 'ai';
export declare class ChatArrayMemory {
private readonly memory;
/**
* Optional hard limit on the number of messages to keep. If provided, the
* stored conversation will be truncated to the *last* `maxMessages` items
* before persisting so that upstream BufferWindowMemory `k` setting is
* respected.
*/
private readonly maxMessages;
constructor(memory: any, // BufferMemory or BufferWindowMemory
/**
* Optional hard limit on the number of messages to keep. If provided, the
* stored conversation will be truncated to the *last* `maxMessages` items
* before persisting so that upstream BufferWindowMemory `k` setting is
* respected.
*/
maxMessages?: number | null);
/**
* Load the stored chat array by concatenating every JSON array that was
* persisted on previous turns. This keeps the database lean (one delta per
* turn) while still letting us reconstruct the full conversation for the
* next prompt. We apply an optional `maxMessages` window **after**
* reconstruction so the caller controls how much context is sent to the
* model without losing older history in the DB.
*/
load(): Promise<CoreMessage[]>;
/**
* Persist the messages produced in the *current* run (delta). We expect the
* caller to pass **only** the new messages, so we just insert them as a JSON
* array. Nothing is truncated – historical context remains intact in the DB.
*/
save(messages: CoreMessage[]): Promise<void>;
}