UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

164 lines 5.17 kB
/** * UserMemory Class * * A specialized memory implementation for storing user-specific information * and preferences with optimized retrieval. Designed to maintain context * across conversations and interactions while minimizing memory usage. */ import { BaseMemory, MemoryItem, MemorySearchParams, MemorySearchResult } from './BaseMemory.js'; /** * Configuration options for UserMemory */ export interface UserMemoryOptions { /** * Maximum number of items to keep in memory * Uses LRU eviction policy when limit is reached */ maxSize?: number; /** * Enable indexing for faster retrieval * Creates optimized search indexes for common user attributes */ enableIndexing?: boolean; /** * Time in milliseconds after which memory items expire * Set to 0 to disable expiration (default) */ expirationMs?: number; /** * Whether to compress stored content to reduce memory footprint */ useCompression?: boolean; /** * Custom serializer for memory items * Can be used to optimize memory storage further */ serializer?: (item: any) => string; /** * Custom deserializer for memory items */ deserializer?: (data: string) => any; } /** * UserMemory: Specialized memory system for storing and retrieving * user-specific information with optimized performance. * * Features: * - Memory-efficient storage of user preferences and history * - Fast indexed retrieval for common user attributes * - Automatic memory management with LRU eviction * - Optional content compression */ export declare class UserMemory implements BaseMemory { private items; private userIndex; private attributeIndex; private lruOrder; private options; /** * Create a new UserMemory instance with optimized data structures */ constructor(options?: UserMemoryOptions); /** * Add a memory item with optimized indexing * @param content The content to store * @param metadata Additional metadata about the content * @returns The created memory item */ add(content: string, metadata?: Record<string, any>): Promise<MemoryItem>; /** * Search for memory items with optimized retrieval algorithms * @param params Search parameters * @returns Search results with relevance scores */ search(params: MemorySearchParams): Promise<MemorySearchResult>; /** * Get a specific memory item by ID * @param id The ID of the item to retrieve * @returns The memory item or null if not found */ get(id: string): Promise<MemoryItem | null>; /** * Update an existing memory item * @param id The ID of the item to update * @param updates The updates to apply * @returns The updated item or null if not found */ update(id: string, updates: Partial<Omit<MemoryItem, 'id' | 'createdAt'>>): Promise<MemoryItem | null>; /** * Remove an item from memory * @param id The ID of the item to remove * @returns Whether the item was removed */ remove(id: string): Promise<boolean>; /** * Clear all items from memory */ clear(): Promise<void>; /** * Reset the memory (clear and reinitialize) */ reset(): Promise<void>; /** * Get all memory items for a specific user * @param userId The user ID to get items for * @param limit Maximum number of items to return * @returns Memory items for the user */ getUserItems(userId: string, limit?: number): Promise<MemorySearchResult>; /** * Get user preferences stored in memory * @param userId The user ID to get preferences for * @returns Object containing user preferences */ getUserPreferences(userId: string): Promise<Record<string, any>>; /** * Store a user preference * @param userId The user ID to store the preference for * @param key The preference key * @param value The preference value */ setUserPreference(userId: string, key: string, value: any): Promise<void>; /** * Add a user interaction to memory * @param userId The user ID * @param interaction The interaction details */ addUserInteraction(userId: string, interaction: Record<string, any>): Promise<void>; /** * Helper: Check if a memory item has expired * @private */ private isExpired; /** * Helper: Update the access time for an item * @private */ private updateAccessTime; /** * Helper: Evict the least recently used item when max size is reached * @private */ private evictLeastRecentlyUsed; /** * Helper: Remove an item from metadata indexes * @private */ private removeFromMetadataIndexes; /** * Helper: Add an item to metadata indexes * @private */ private addToMetadataIndexes; /** * Helper: Apply simple compression to content * @private */ private compressContent; /** * Helper: Decompress content * @private */ private decompressContent; } //# sourceMappingURL=UserMemory.d.ts.map