/**
 * Agent Worker Pool Module
 *
 * Provides multi-agent parallelism with automatic load balancing,
 * work distribution, and result aggregation for AGI workflows.
 *
 * Principal Investigator: Bo Shang
 * Framework: agi-cli
 */
import type { AgentController } from './agentController.js';
import type { AgentEventUnion } from '../contracts/v1/agent.js';
export type WorkerStatus = 'idle' | 'busy' | 'error' | 'offline';
export type BalanceStrategy = 'round-robin' | 'least-busy' | 'random' | 'priority';
export interface AgentWorkerConfig {
    /** Unique worker identifier */
    id: string;
    /** Agent controller factory or instance */
    createController: () => Promise<AgentController> | AgentController;
    /** Maximum concurrent tasks this worker can handle (default: 1) */
    maxConcurrency?: number;
    /** Priority for task assignment (higher = preferred) */
    priority?: number;
    /** Tags for routing specific task types */
    tags?: string[];
}
export interface AgentTask<T = string> {
    /** Unique task identifier */
    id: string;
    /** The message/prompt to send to the agent */
    message: string;
    /** Optional transformer for the result */
    transform?: (result: string) => T;
    /** Required worker tags (task routed to workers with all these tags) */
    requiredTags?: string[];
    /** Preferred worker ID (soft preference) */
    preferredWorker?: string;
    /** Task priority (higher = processed first) */
    priority?: number;
    /** Timeout in milliseconds */
    timeout?: number;
    /** Whether to stream events */
    streaming?: boolean;
    /** Callback for streaming events */
    onEvent?: (event: AgentEventUnion) => void;
}
export interface TaskResult<T = string> {
    taskId: string;
    workerId: string;
    success: boolean;
    result?: T;
    error?: Error;
    durationMs: number;
    startedAt: number;
    completedAt: number;
}
export interface AgentWorkerPoolConfig {
    /** Worker configurations */
    workers: AgentWorkerConfig[];
    /** Load balancing strategy (default: 'least-busy') */
    balanceStrategy?: BalanceStrategy;
    /** Default task timeout in ms (default: 24 hours - 86400000ms) */
    defaultTimeout?: number;
    /** Maximum queue size before rejecting tasks (default: 100) */
    maxQueueSize?: number;
    /** Callback for pool events */
    onEvent?: (event: PoolEvent) => void;
}
export interface PoolEvent {
    type: 'worker.ready' | 'worker.busy' | 'worker.idle' | 'worker.error' | 'task.queued' | 'task.started' | 'task.completed' | 'task.failed' | 'pool.saturated' | 'pool.drained';
    timestamp: number;
    workerId?: string;
    taskId?: string;
    data?: Record<string, unknown>;
}
export interface WorkerInfo {
    id: string;
    status: WorkerStatus;
    activeTasks: number;
    completedTasks: number;
    failedTasks: number;
    tags: string[];
    priority: number;
}
export interface PoolStats {
    totalWorkers: number;
    activeWorkers: number;
    idleWorkers: number;
    queuedTasks: number;
    activeTasks: number;
    completedTasks: number;
    failedTasks: number;
    averageTaskDurationMs: number;
}
export declare class AgentWorkerPool {
    private readonly workers;
    private readonly taskQueue;
    private readonly balanceStrategy;
    private readonly defaultTimeout;
    private readonly maxQueueSize;
    private readonly onEvent;
    private roundRobinIndex;
    private totalTaskDuration;
    private completedTaskCount;
    private processing;
    constructor(config: AgentWorkerPoolConfig);
    /**
     * Initialize all workers
     */
    initialize(): Promise<void>;
    /**
     * Submit a task to the pool
     */
    submit<T>(task: AgentTask<T>): Promise<TaskResult<T>>;
    /**
     * Submit multiple tasks and wait for all results
     */
    submitAll<T>(tasks: AgentTask<T>[]): Promise<TaskResult<T>[]>;
    /**
     * Submit multiple tasks and process results as they complete
     */
    submitStream<T>(tasks: AgentTask<T>[]): AsyncGenerator<TaskResult<T>>;
    /**
     * Process queued tasks
     */
    private processQueue;
    /**
     * Execute a task on a worker
     */
    private executeTask;
    /**
     * Select a worker based on the balancing strategy
     */
    private selectWorker;
    /**
     * Get available workers filtered by task requirements
     */
    private getAvailableWorkers;
    /**
     * Get information about all workers
     */
    getWorkerInfo(): WorkerInfo[];
    /**
     * Get pool statistics
     */
    getStats(): PoolStats;
    /**
     * Cancel all queued tasks
     */
    cancelAll(): number;
    private emit;
    private sleep;
}
/**
 * Create an agent worker pool with the given configuration
 */
export declare function createAgentWorkerPool(config: AgentWorkerPoolConfig): AgentWorkerPool;
/**
 * Create a simple agent task
 */
export declare function createAgentTask<T = string>(id: string, message: string, options?: Partial<Omit<AgentTask<T>, 'id' | 'message'>>): AgentTask<T>;
declare const _default: {
    AgentWorkerPool: typeof AgentWorkerPool;
    createAgentWorkerPool: typeof createAgentWorkerPool;
    createAgentTask: typeof createAgentTask;
};
export default _default;
//# sourceMappingURL=agentWorkerPool.d.ts.map