crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
124 lines • 3.58 kB
TypeScript
/**
* OptimizedShortTermMemory implementation
* Enhanced version of ShortTermMemory with comprehensive memory optimizations
*/
import { BaseMemory, MemoryItem, MemorySearchParams, MemorySearchResult } from './BaseMemory.js';
/**
* Options for configuring OptimizedShortTermMemory behavior
*/
export interface OptimizedShortTermMemoryOptions {
/**
* Maximum capacity of memory items
* @default 1000
*/
capacity?: number;
/**
* Whether to use LRU (Least Recently Used) eviction policy
* @default true
*/
useLRU?: boolean;
/**
* Interval in milliseconds for automatic pruning of old memories
* If undefined, no automatic pruning occurs
* @default undefined
*/
pruneIntervalMs?: number;
/**
* Maximum age in milliseconds for a memory item before it becomes eligible for pruning
* @default 24 hours
*/
maxAgeMs?: number;
/**
* Whether to use weak references for large memory items
* @default true
*/
useWeakReferences?: boolean;
/**
* Size threshold for considering an item "large" (in approximate bytes)
* @default 50000 (~50KB)
*/
largeObjectThreshold?: number;
/**
* Whether to use content deduplication for similar content
* @default true
*/
enableDeduplication?: boolean;
/**
* Whether to track memory usage statistics
* @default true
*/
trackStats?: boolean;
}
/**
* OptimizedShortTermMemory class for efficient in-memory storage
* Enhanced with weak references, content deduplication, and optimized data structures
*/
export declare class OptimizedShortTermMemory implements BaseMemory {
private itemCache;
private contentStore;
private idToContentRef;
private accessOrder;
private capacity;
private useLRU;
private maxAgeMs;
private pruneIntervalId?;
private trackStats;
private retentionPolicy;
constructor(options?: OptimizedShortTermMemoryOptions);
/**
* Add an item to memory with optimized capacity management and deduplication
*/
add(content: string, metadata?: Record<string, any>): Promise<MemoryItem>;
/**
* Search for items in memory with optimized relevance scoring
*/
search(params: MemorySearchParams): Promise<MemorySearchResult>;
/**
* Get an item by its ID with LRU tracking
*/
get(id: string): Promise<MemoryItem | null>;
/**
* Update an existing memory item
*/
update(id: string, updates: Partial<Omit<MemoryItem, 'id' | 'createdAt'>>): Promise<MemoryItem | null>;
/**
* Remove an item from memory
*/
remove(id: string): Promise<boolean>;
/**
* Clear all items from memory
*/
clear(): Promise<void>;
/**
* Reset the memory (clear and initialize)
*/
reset(): Promise<void>;
/**
* Clean up resources when no longer needed
*/
dispose(): void;
/**
* Get the current memory size
*/
get size(): number;
/**
* Get memory statistics
*/
getStats(): Record<string, any>;
/**
* Prune old memories based on maxAgeMs
* Optimized to minimize iteration over items
*/
private pruneOldMemories;
/**
* Update the access order for LRU tracking
* Optimized for minimal array operations
*/
private updateAccessOrder;
/**
* Evict an item based on the eviction policy
* Currently implements LRU (Least Recently Used)
*/
private evictItem;
}
//# sourceMappingURL=OptimizedShortTermMemory.d.ts.map