/** * Repeat Pattern - Repeat a step until a condition is met * * Implements the evaluator-optimizer pattern where a step * is executed repeatedly until either: * - A condition function returns true * - Maximum iterations are reached * * @example Basic usage * ```typescript * import { repeat, Agent } from 'praisonai'; * * const generator = new Agent({ instructions: "Improve the text" }); * * const result = await repeat(generator, { * until: (ctx) => ctx.lastResult?.includes('perfect'), * maxIterations: 5 * }).run('Make this text better'); * ``` * * @example With custom evaluator * ```typescript * const result = await repeat(generator, { * until: async (ctx) => { * const score = await evaluateQuality(ctx.lastResult); * return score >= 0.9; * }, * maxIterations: 10 * }).run('Initial draft'); * ``` */ import type { WorkflowContext } from './index'; /** * Configuration for Repeat pattern */ export interface RepeatConfig { /** Condition function - returns true when iteration should stop */ until?: (context: RepeatContext) => boolean | Promise; /** Maximum iterations (default: 10) */ maxIterations?: number; /** Callback for each iteration */ onIteration?: (result: string, iteration: number) => void; /** Delay between iterations in ms (default: 0) */ delayMs?: number; } /** * Context passed to the until condition */ export interface RepeatContext { /** Result from the last iteration */ lastResult: string | null; /** Current iteration number (0-indexed) */ iteration: number; /** All results from previous iterations */ allResults: string[]; /** Additional metadata */ metadata: Record; /** Workflow context if available */ workflowContext?: WorkflowContext; } /** * Result from Repeat execution */ export interface RepeatResult { /** Final result (last iteration output) */ result: string; /** All iteration results */ iterations: string[]; /** Number of iterations executed */ count: number; /** Whether the until condition was satisfied */ conditionMet: boolean; /** Whether max iterations was reached */ maxReached: boolean; } /** * Repeat class - Execute a step repeatedly until condition is met */ export declare class Repeat { readonly id: string; readonly step: TStep; readonly config: Required; constructor(step: TStep, config?: RepeatConfig); /** * Execute the step with given input */ private executeStep; /** * Run the repeat pattern */ run(input: string, context?: WorkflowContext): Promise; /** * Helper to delay execution */ private delay; } /** * Convenience function to create a Repeat pattern * * @example * ```typescript * import { repeat, Agent } from 'praisonai'; * * const optimizer = new Agent({ instructions: "Improve: {{previous}}" }); * * const result = await repeat(optimizer, { * until: (ctx) => ctx.iteration >= 3, * maxIterations: 5 * }).run('Initial text'); * * console.log(result.iterations); // ['improved 1', 'improved 2', 'improved 3'] * ``` */ export declare function repeat(step: TStep, config?: RepeatConfig): Repeat; export default Repeat;