UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

156 lines 4.49 kB
/** * FlowExecutionTracker * * Provides optimized performance tracking for flow execution with minimal overhead. * Tracks execution times, resource usage, and execution paths with configurable sampling. */ import { Flow, FlowState } from '../index.js'; import { FlowEventBus } from '../events/FlowEventBus.js'; import { FlowMemoryConnectorInterface } from '../memory/FlowMemoryConnectorInterface.js'; /** * Flow execution metrics */ export interface FlowExecutionMetrics { startTime: number; endTime: number; executionTimeMs: number; methodCallCount: Record<string, number>; methodDurations: Record<string, number>; stateChanges: number; routeEvaluations: number; errorCount: number; eventCount: number; heapUsed?: number; heapTotal?: number; externalMemory?: number; peakMemoryUsageMb?: number; } /** * Metrics sample point for time series analysis */ export interface MetricsSample { timestamp: number; metrics: Partial<FlowExecutionMetrics>; snapshot?: any; } /** * Execution trace entry with optimized storage */ export interface ExecutionTraceEntry { timestamp: number; type: 'method_call' | 'method_return' | 'state_change' | 'route_evaluation' | 'error'; target?: string; duration?: number; snapshot?: any; error?: Error; } /** * Configuration options for FlowExecutionTracker */ export interface FlowTrackerOptions { sampleInterval?: number; minimumDurationToTrack?: number; trackMethodCalls?: boolean; trackStateChanges?: boolean; trackRouteEvaluations?: boolean; maxTraceEntries?: number; maxSamples?: number; compressTraces?: boolean; persistMetrics?: boolean; eventBus?: FlowEventBus; memoryConnector?: FlowMemoryConnectorInterface; trackProcessMetrics?: boolean; processMetricsInterval?: number; methodDurationWarningMs?: number; memoryWarningThresholdMb?: number; eventRateWarningThreshold?: number; } /** * FlowExecutionTracker provides optimized performance tracking for flows * with minimal overhead and configurable sampling. */ export declare class FlowExecutionTracker<TState extends FlowState = FlowState> { private metrics; private metricSamples; private executionTrace; private flow; private isTracking; private eventHandlers; private processMetricsTimer?; private options; /** * Create a tracker for a specific flow */ constructor(flow: Flow<TState>, options?: FlowTrackerOptions); /** * Start tracking flow execution with optimized event listeners */ startTracking(): void; /** * Stop tracking and finalize metrics */ stopTracking(): FlowExecutionMetrics; /** * Record a method call with optimized overhead */ recordMethodCall(methodName: string): () => void; /** * Record a state change with minimal overhead */ recordStateChange(stateChanges: Record<string, any>): void; /** * Record a route evaluation with minimal overhead */ recordRouteEvaluation(routeId: string, result: boolean): void; /** * Record an error with tracking */ recordError(error: Error, context?: string): void; /** * Get current metrics snapshot */ getMetrics(): FlowExecutionMetrics; /** * Get execution trace */ getExecutionTrace(): ExecutionTraceEntry[]; /** * Get metric samples for time series analysis */ getMetricSamples(): MetricsSample[]; /** * Clear all collected data */ clearData(): void; /** * Take a snapshot of current metrics */ private takeSample; /** * Add an entry to the execution trace with optimized storage */ private addTraceEntry; /** * Register event listeners for flow events */ private registerEventListeners; /** * Unregister event listeners */ private unregisterEventListeners; /** * Start tracking process metrics at intervals */ private startProcessMetricsTracking; /** * Persist metrics to memory system */ private persistMetricsToMemory; /** * Get representative samples from the full set * Uses an algorithm to select samples distributed across the time range * with efficient memory usage and optimal performance characteristics */ private getRepresentativeSamples; } //# sourceMappingURL=FlowExecutionTracker.d.ts.map