Loop Mode
Loop Mode lets the agent work autonomously through multi-step tasks — iterating until the job is done or you stop it.
How It Works
Enable Loop Mode in the composer, set the goal and max iterations. The agent will:
Think → Act → Observe → Evaluate → Repeat
Each iteration produces a full agent response (think + tool calls + results). The agent decides whether to continue based on progress toward the goal.
You can stop at any time — the agent stops cleanly after the current iteration.
Controls
Click the Loop button next to the composer to open settings:
| Control | What it does |
|---|---|
| Enable toggle | Turn loop on/off for this message |
| Max iterations | Safety limit (1–100, server-capped) |
| Goal | What the agent should accomplish |
While looping, the toggle button shows a spinning Refresh icon.
Loop Events
The relay emits these events during loop execution:
| Event | When |
|---|---|
loop_iteration | Start of each iteration (number, max, prompt) |
loop_complete | Agent signals completion via internal marker |
loop_max_iterations | Safety limit reached |
When Loop Mode Excels
- Batch operations — process file by file through a directory
- Test-driven development — write test → run → fix → repeat
- Refactoring — find pattern → refactor → verify → find next
- Codebase audits — scan files for patterns, add missing pieces
Loop + Goal = Autonomous Execution
The loopGoal field guides the loop. Instead of "apply this fix", you describe the end state:
Goal: "Add proper error handling with try/catch to all route handlers in src/routes/"
→ Agent finds files → analyzes each → adds error handling → verifies → done
The agent plans and adapts internally — you don't need to describe each step.
Best Practices
- Be specific about the goal — "Add error handling to all route files in src/routes/" not "fix errors"
- Set realistic max iterations — 10 for medium tasks, 3 for small, 30+ only for bulk operations
- Reference existing patterns — mention files to follow as examples in the goal text
- Check in periodically — review intermediate results between iterations
- Stop early if needed — all progress from completed iterations is preserved