UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

159 lines 4.36 kB
/** * SegmentedMemory implementation * Provides tiered memory storage with automatic promotion/demotion * between hot, warm, and cold segments based on access patterns */ import { BaseMemory, MemoryItem, MemorySearchParams, MemorySearchResult } from '../BaseMemory.js'; /** * Options for configuring SegmentedMemory behavior */ export interface SegmentedMemoryOptions { /** * Maximum number of items in hot cache (frequently accessed) * @default 100 */ hotCacheSize?: number; /** * Maximum number of items in warm cache (occasionally accessed) * @default 1000 */ warmCacheSize?: number; /** * Maximum time in milliseconds an item can be inactive before being demoted from hot to warm * @default 5 minutes */ hotDemotionTimeMs?: number; /** * Maximum time in milliseconds an item can be inactive before being demoted from warm to cold * @default 1 hour */ warmDemotionTimeMs?: number; /** * Interval in milliseconds for automatic tier management (promotions/demotions) * @default 1 minute */ tierManagementIntervalMs?: number; /** * Whether to track memory usage statistics * @default true */ trackStats?: boolean; /** * Whether to prefetch related items when promoting an item * @default false */ enablePrefetching?: boolean; /** * Number of related items to prefetch when enablePrefetching is true * @default 5 */ prefetchCount?: number; } /** * Memory tiers for segmentation */ export type MemoryTier = 'hot' | 'warm' | 'cold'; /** * SegmentedMemory class * Implements tiered memory storage with automatic promotion/demotion based on access patterns */ export declare class SegmentedMemory implements BaseMemory { private hotCache; private warmCache; private coldStorage; private hotCacheSize; private warmCacheSize; private hotDemotionTimeMs; private warmDemotionTimeMs; private trackStats; private enablePrefetching; private prefetchCount; private tierManagementIntervalId?; private itemRelations; private stats; constructor(options?: SegmentedMemoryOptions); /** * Add a memory item * New items are always inserted into hot cache first */ add(content: string, metadata?: Record<string, any>): Promise<MemoryItem>; /** * Search for memory items across all tiers */ search(params: MemorySearchParams): Promise<MemorySearchResult>; /** * Get a memory item by ID * Updates access time and promotes item if found */ get(id: string): Promise<MemoryItem | null>; /** * Update a memory item */ update(id: string, updates: Partial<Omit<MemoryItem, 'id' | 'createdAt'>>): Promise<MemoryItem | null>; /** * Remove a memory item */ remove(id: string): Promise<boolean>; /** * Clear all memory items */ clear(): Promise<void>; /** * Reset the memory */ reset(): Promise<void>; /** * Clean up resources when disposing */ dispose(): void; /** * Get the total number of items across all tiers */ get size(): number; /** * Get memory performance statistics */ getStats(): typeof this.stats; /** * Get memory tier distribution */ getTierDistribution(): { hot: number; warm: number; cold: number; }; /** * Add a relation between two items * Used for prefetching related items */ addRelation(sourceId: string, targetId: string): boolean; /** * Manage tiers by promoting and demoting items based on access patterns */ private manageTiers; /** * Find an item across all tiers */ private findItem; /** * Access an item, update its access time, and promote it to appropriate tier */ private accessItem; /** * Prefetch related items */ private prefetchRelatedItems; /** * Ensure hot cache has capacity for a new item */ private ensureHotCacheCapacity; /** * Ensure warm cache has capacity for a new item */ private ensureWarmCacheCapacity; /** * Update memory statistics */ private updateStats; } //# sourceMappingURL=SegmentedMemory.d.ts.map