/** * Loop Pattern - Iterate over items executing a step for each * * Supports iteration over: * - Arrays (from variables) * - CSV files * - Text files (one item per line) * * @example Array iteration * ```typescript * const workflow = new Workflow('process-items'); * workflow.addStep({ * name: 'processor', * execute: async (input, ctx) => ctx.get('currentItem') * }); * * const result = await loop(agent, { over: 'items' }) * .run({ items: ['a', 'b', 'c'] }, context); * ``` * * @example CSV iteration * ```typescript * const result = await loop(agent, { fromCsv: './data.csv' }) * .run({}, context); * ``` */ import type { WorkflowContext } from './index'; /** * Configuration for Loop pattern */ export interface LoopConfig { /** Variable name containing array to iterate over */ over?: string; /** Path to CSV file to iterate over */ fromCsv?: string; /** Path to text file (one item per line) */ fromFile?: string; /** Variable name for current item (default: 'item') */ varName?: string; /** Maximum iterations (safety limit, default: 1000) */ maxIterations?: number; /** Continue on error (default: false) */ continueOnError?: boolean; /** Callback for each iteration */ onIteration?: (item: T, index: number, total: number) => void; } /** * Result from Loop execution */ export interface LoopResult { /** Results from each iteration */ results: T[]; /** Total iterations executed */ iterations: number; /** Any errors that occurred */ errors: Array<{ index: number; error: Error; }>; /** Whether all iterations completed successfully */ success: boolean; } /** * Loop class - Iterate over items executing an agent/step for each */ export declare class Loop { readonly id: string; readonly step: TStep; readonly config: Required>; constructor(step: TStep, config?: LoopConfig); /** * Get items to iterate over from context or file */ private getItems; /** * Load items from CSV file */ private loadCsv; /** * Parse a single CSV line */ private parseCsvLine; /** * Load items from text file (one per line) */ private loadTextFile; /** * Execute an agent/step with a specific item */ private executeStep; /** * Run the loop over all items */ run(input: Record | TItem[], context?: WorkflowContext): Promise>; } /** * Convenience function to create a Loop * * @example * ```typescript * import { loop, Agent } from 'praisonai'; * * const processor = new Agent({ instructions: "Process {{item}}" }); * const loopPattern = loop(processor, { over: 'items' }); * * const result = await loopPattern.run({ items: ['a', 'b', 'c'] }); * console.log(result.results); // ['processed a', 'processed b', 'processed c'] * ``` */ export declare function loop(step: TStep, config?: LoopConfig): Loop; export default Loop;