Check work and retry
Use test output or a review to accept an agent’s work or request another attempt.
Repeat until a check accepts
Section titled “Repeat until a check accepts”Define an attempt and a check with defineLoopTask(). The check accepts the result or returns feedback for the next attempt. Set maxRounds so a result that never passes ends with a bounded failure.
Round 1 is rejected; round 2 receives the feedback and is accepted. after, condition and cache work as on other tasks.
Code, then run a command
Section titled “Code, then run a command”The agent works in attempt, the tests run in check, both in one warm sandbox.
Keep the sandbox, attempt and check separate so each step is easy to follow.
Run run-loop.ts; it keeps the sandbox open until the workflow finishes.
coding.perform(context) ties the agent’s tokens and cancellation to the loop and its budget. coder is a helper: only fix goes in the workflow. attempt returns JSON because a checkpoint saves every candidate, even rejected ones.
A failing npm test returns a nonzero status, and its output becomes the feedback. You decide where it goes: the next brief, as here, or a continued conversation.
Ask a second agent to review
Section titled “Ask a second agent to review”check can dispatch a reviewer and turn its typed response into a verdict. Both agents count against the same budget.
Pass it as check: reviewChanges. The request’s agent replaces the sandbox’s agent for this dispatch only.
Limits
Section titled “Limits”| Limit or event | What happens |
|---|---|
maxRounds | Caps the rounds, resumes included. |
| Workflow attempts | Each round, and each replay of an interrupted round, counts against budget.attempts. |
timeoutMs | Bounds each round. It stops callbacks that honor context.signal. |
| An exception | Fails the task at once. A loop task has no retry option. |
| The last check rejects | The task fails with LoopTaskExhausted, which holds the last feedback. Dependents do not run. |
Fix a failing CI build handles each outcome in a complete script.
Checkpoint and resume
Section titled “Checkpoint and resume”With a checkpoint, each candidate is saved before check. On resume, a saved candidate goes straight to check, and rejected rounds are not rerun.
An interrupted round replays only with resume: "retry-incomplete", since it may already have changed files. Changing maxRounds makes the checkpoint incompatible.
Each task record lists its rounds, and each phase emits a loop workflow event. context.idempotencyKey differs per round and phase, to deduplicate effects as in Job queues and workers.
API: defineLoopTask · LoopTaskOptions · LoopTaskContext · LoopCheckResult · LoopTaskExhausted · defineAgentTask.