defineLoopTask
Purpose and behavior
Section titled “Purpose and behavior”Declare a task that runs attempt then check for at most maxRounds rounds, passing each rejected check’s feedback to the next attempt. Each round consumes one workflow attempt and, with a checkpoint, saves its phase. The output is the accepted value; exhaustion fails the task with LoopTaskExhausted and a callback exception fails it at once.
Complete example and detailed rules.
Parameters and properties
Section titled “Parameters and properties”optionsRequiredLoopTaskOptions<T>Task identity, dependencies, bounded attempt callback and acceptance check.options.maxRoundsRequirednumberPositive safe integer limiting logical rounds across resumes. Replaying an interrupted phase uses its existing round but consumes another workflow attempt.options.attemptRequired(context: LoopTaskContext, feedback: string | undefined) => T | Promise<T>Produce the candidate output from the phase context and previous rejected check feedback; feedback is undefined in round one. Persisted outputs must be lossless JSON or undefined.options.checkRequired(context: LoopTaskContext, result: T) => LoopCheckResult | Promise<LoopCheckResult>Accept the candidate with done: true or request another round with done: false and text feedback. May invoke a reviewer agent; report its usage through the context. Exceptions fail the task.options.cacheOptionalTaskCacheOptions | undefinedResult cache: a hit restores the stored lossless JSON value with no attempt, usage or side effects. On a miss, a result that is not lossless JSON fails the task. Rejected on gates, interactions and dispatch-result tasks.options.keyRequiredstringUnique key in the workflow, matching [A-Za-z0-9][A-Za-z0-9._-]*. Records, events and checkpoints identify the task by it.options.afterOptionalreadonly Task<unknown>[] | undefinedTasks that must be done before this one starts, default none; only these can be read with context.value().options.conditionOptional((context: TaskContext) => boolean | Promise<boolean>) | undefinedEvaluated with attempt 0 before the task runs, including when a later start() resumes it; false ends the task as skipped, which skips its dependents.options.timeoutMsOptionalnumber | undefinedDeadline in milliseconds for each attempt, a positive integer up to 2147483647. Expiry aborts context.signal and fails the attempt, which retry may repeat.