UNPKG

@langgraph-js/memory

Version:

A memory management system based on PostgreSQL + pgvector for LangGraph workflows

88 lines (80 loc) 2.74 kB
import { AIMessage, ToolMessage, HumanMessage, SystemMessage } from '@langchain/core/messages'; export interface IdSet { userId?: string; agentId?: string; runId?: string; } export interface MemoryFilters extends IdSet { categories?: string[] | string; createdAtBefore?: string; createdAtAfter?: string; updatedAtBefore?: string; updatedAtAfter?: string; expirationDateBefore?: string; expirationDateAfter?: string; [key: string]: any; } export interface GetAllMemoryOptions extends MemoryFilters { limit?: number; } export interface DeleteAllMemoryOptions extends MemoryFilters {} export interface SearchResult { results: MemoryItem[]; relations?: any[]; } /** * The MemoryItem interface defines the structure of a stored memory item. */ export interface MemoryItem { /** Unique identifier for the memory item */ id: string; /** Group identifier for the memory item */ org_id: string; /** Associated agent ID (optional) */ agent_id?: string; /** Associated user ID (optional) */ user_id?: string; /** Associated application ID (optional) */ app_id?: string; /** Associated run ID (optional) */ run_id?: string; /** Indicates whether the memory item is immutable (read-only) (optional) */ immutable?: boolean; /** Memory content as a string */ memory: string; /** Categories/tags for the memory item (optional) */ categories?: string[]; /** Additional metadata (optional), as a key-value object */ metadata?: Record<string, any>; /** Similarity score for search results (optional) */ score?: number; /** Creation time of the memory item, as a string */ created_at: string; /** Last updated time of the memory item, as a string */ updated_at: string; /** Expiration date of the memory item (optional), as a string */ expiration_date?: string; } export interface MemoryBase { add( messages: (HumanMessage | SystemMessage | AIMessage | ToolMessage)[], config: { metadata?: Record<string, any>; filters?: MemoryFilters; infer?: boolean; } & IdSet, ): Promise<SearchResult>; get(memoryId: string): Promise<MemoryItem | null>; search( query: string, config: { limit?: number; filters?: MemoryFilters; } & IdSet, ): Promise<SearchResult>; update(memoryId: string, data: string): Promise<{ message: string }>; delete(memoryId: string): Promise<{ message: string }>; deleteAll(config: DeleteAllMemoryOptions): Promise<{ message: string }>; reset(): Promise<void>; getAll(config: GetAllMemoryOptions): Promise<SearchResult>; }