UNPKG

crewai-ts

Version:

TypeScript port of crewAI for agent-based workflows

182 lines 4.88 kB
/** * FlowScheduler * * Provides optimized scheduling of flows with efficient dependency resolution, * parallel execution management, and resource allocation strategies. */ import { Flow, FlowState } from '../index.js'; import { FlowEventBus, FlowEvent } from '../events/FlowEventBus.js'; /** * Flow node in the dependency graph */ export interface FlowNode<T extends FlowState = FlowState> { id: string; flow: Flow<T>; dependencies: string[]; priority: number; metadata?: Record<string, any>; status?: FlowExecutionStatus; result?: any; error?: Error; } /** * Flow execution status */ export declare enum FlowExecutionStatus { PENDING = "pending", SCHEDULED = "scheduled", RUNNING = "running", SUCCESSFUL = "successful", FAILED = "failed", CANCELLED = "cancelled" } /** * Flow execution options */ export interface FlowSchedulingOptions { maxConcurrent?: number; priorityLevels?: number; priorityWeights?: number[]; maxExecutionTimeMs?: number; minExecutionDelayMs?: number; executionTimeout?: number; memoryLimit?: number; memoryThrottling?: boolean; cpuLimit?: number; trackPerformance?: boolean; eventBus?: FlowEventBus; stopOnFirstError?: boolean; retryCount?: number; retryDelayMs?: number; beforeExecution?: <T extends FlowState>(node: FlowNode<T>) => Promise<void>; afterExecution?: <T extends FlowState>(node: FlowNode<T>, result: any) => Promise<void>; onError?: <T extends FlowState>(node: FlowNode<T>, error: Error) => Promise<boolean>; } /** * Flow execution result */ export interface FlowExecutionResult { successful: boolean; completedFlows: string[]; failedFlows: string[]; skippedFlows: string[]; results: Map<string, any>; errors: Map<string, Error>; executionTime: number; metrics?: { totalFlows: number; maxConcurrent: number; peakMemoryUsageMb?: number; cpuUtilization?: number; averageFlowDurationMs: number; }; } /** * Flow scheduler event */ export interface FlowSchedulerEvent extends FlowEvent { type: 'flow_scheduler:start' | 'flow_scheduler:complete' | 'flow_scheduler:error'; schedulerId: string; flowCount?: number; concurrentFlows?: number; } /** * FlowScheduler provides optimized scheduling of flows with efficient dependency resolution */ export declare class FlowScheduler { private options; private id; private nodes; private dependents; private scheduled; private running; private completed; private failed; private results; private errors; private trackers; private startTime; private endTime; private peakConcurrent; private totalDuration; private retryAttempts; private readonly defaultOptions; /** * Create a new FlowScheduler with optimized scheduling capabilities */ constructor(options?: FlowSchedulingOptions, id?: string); /** * Register a flow for execution */ registerFlow<T extends FlowState>(flow: Flow<T>, options?: { id?: string; dependencies?: string[]; priority?: number; metadata?: Record<string, any>; }): string; /** * Unregister a flow */ unregisterFlow(id: string): boolean; /** * Execute all flows respecting dependencies and concurrency limits */ execute(options?: FlowSchedulingOptions): Promise<FlowExecutionResult>; /** * Get all registered flows */ getFlows(): FlowNode[]; /** * Get a specific flow by ID */ getFlow(id: string): FlowNode | undefined; /** * Get all ready flows that have all dependencies satisfied */ getReadyFlows(): FlowNode[]; /** * Get execution results */ getResults(): Map<string, any>; /** * Get execution errors */ getErrors(): Map<string, Error>; /** * Get performance metrics for all flows */ getPerformanceMetrics(): Record<string, any>; /** * Validate the dependency graph for cycles and missing dependencies */ private validateDependencyGraph; /** * Start executing a flow */ private startFlow; /** * Execute a flow and handle results/errors */ private executeFlow; /** * Wait for any running flow to complete */ private waitForAnyFlowToComplete; /** * Cancel all running flows */ private cancelAllRunningFlows; /** * Prepare the execution result */ private prepareExecutionResult; /** * Check if there are more flows to execute */ private hasMoreFlowsToExecute; /** * Calculate the current concurrency limit based on system resources */ private calculateCurrentConcurrencyLimit; } //# sourceMappingURL=FlowScheduler.d.ts.map