Loop nodes let a single DAG node run an AI prompt repeatedly until a completion condition is met. Each iteration is a full AI agent session that can read files, write code, run commands, and produce output—giving you autonomous multi-step execution that adapts based on what it finds on disk. This page covers every configuration field, completion signal formats, theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/coleam00/Archon/llms.txt
Use this file to discover all available pages before exploring further.
$LOOP_PREV_OUTPUT and $LOOP_USER_INPUT variables, and the patterns used in Archon’s own bundled workflows.
Quick start
.archon/workflows/iterate-until-done.yaml
How it works
A loop node iterates until one of these conditions is met:- LLM completion signal — the AI outputs
<promise>SIGNAL</promise>where SIGNAL matches theuntilvalue - Deterministic bash check — an optional
until_bashscript exits with code 0 - Max iterations reached — the node fails with a clear error
$nodeId.output is the last iteration’s output only—not a concatenation across all iterations.
Configuration fields
prompt
The prompt sent to the AI each iteration. Supports all standard variable substitution plus loop-specific variables:
| Variable | Value |
|---|---|
$ARGUMENTS / $USER_MESSAGE | Original user message |
$ARTIFACTS_DIR | Workflow artifacts directory |
$BASE_BRANCH | Repository base branch |
$WORKFLOW_ID | Current workflow run ID |
$nodeId.output | Output from upstream (non-loop) nodes |
$LOOP_USER_INPUT | User feedback from an interactive gate pause |
$LOOP_PREV_OUTPUT | Cleaned output of the previous loop iteration (empty on first iteration) |
$LOOP_PREV_OUTPUT is particularly useful for fresh_context: true loops—the agent has no memory of prior iterations, so injecting the previous iteration’s output lets it focus on what failed and why without carrying the full session history.
until
The completion signal string. The executor checks each iteration’s output for:
- Tag format (recommended):
<promise>COMPLETE</promise>— case-insensitive, whitespace-tolerant. Prevents false positives from the AI mentioning the signal word in prose. - Plain signal (fallback): The signal at the very end of output (trailing whitespace and punctuation tolerated) or on its own line.
<promise> tags are automatically stripped from output sent to the user and to downstream nodes.
max_iterations
Hard safety limit. If the loop reaches this count without a completion signal, the node fails (not succeeds). Choose based on work scope:
| Work type | Suggested range |
|---|---|
| Simple refinement / fix loop | 3–5 |
| Multi-story implementation | 10–15 |
| Long-running autonomous agent | 15–20 |
fresh_context
Controls session continuity between iterations:
| Value | Behavior | Use when |
|---|---|---|
true | Each iteration starts a fresh AI session. No memory of prior iterations. | Work state lives on disk. Prevents context window exhaustion on long loops. |
false (default) | Sessions thread — each iteration resumes the prior conversation. | Iterative refinement where the agent needs to remember what it tried before. |
until_bash
Optional bash script executed after each AI iteration. If it exits with code 0, the loop completes—even if the AI didn’t emit the completion signal:
prompt.
interactive and gate_message
Set interactive: true to pause the loop between iterations and wait for human input. After each non-completing iteration, the executor:
- Sends the
gate_messageto the user along with the run ID and a/workflow approvecommand - Pauses the workflow run
- Waits for the user to run
/workflow approve <id> <feedback>
$LOOP_USER_INPUT.
Patterns
Stateless agent (Ralph pattern)
Each iteration reads state from disk, does one unit of work, writes state back. The prompt explicitly tells the agent it has no memory:Retry-on-failure with $LOOP_PREV_OUTPUT
When fresh_context: true is needed but the agent benefits from knowing what the previous pass said—typical of implement→validate or generate→review loops:
$LOOP_PREV_OUTPUT is an empty string. Iterations 2+ receive the previous iteration’s cleaned output (with <promise> tags stripped).
Accumulating context
For iterative refinement where the agent needs to remember what it tried before:Deterministic exit with until_bash
Combine LLM work with a deterministic completion check to prevent false claims of completion:
Interactive PIV loop (from bundled archon-piv-loop)
The bundled archon-piv-loop workflow uses interactive loops for explore, plan refinement, and validation phases. Here is the explore phase:
.archon/workflows/defaults/archon-piv-loop.yaml
Implementation loop with $implement-setup.output
From the same PIV workflow, the implementation phase shows how to pass upstream bash node output into a fresh-context loop:
What is NOT supported on loop nodes
| Unsupported field | Notes |
|---|---|
retry | Rejected at parse time — workflow fails to load |
context: fresh | Silently ignored — use fresh_context inside the loop: config instead |
hooks | Per-node SDK hooks not passed through to iterations |
mcp | Per-node MCP server configs not loaded for loop iterations |
skills | Skill preloading not applied to loop iterations |
allowed_tools / denied_tools | Tool restrictions not enforced on loop iterations |
output_format | Structured JSON output not supported |
provider and model are accepted and forwarded to the loop executor—they set the provider/model for each iteration.
If you need hooks, MCP, skills, or tool restrictions, use a command: node that wraps the iterative logic in a command file.
Output and data flow
A loop node’s$nodeId.output is the last iteration’s output only—not a concatenation of all iterations.
To accumulate results across iterations, write them to files in $ARTIFACTS_DIR and have the downstream node read from there:
Error handling
| Scenario | Behavior |
|---|---|
| Iteration throws an error | Node fails immediately — no more iterations |
| Max iterations exceeded | Node fails with descriptive error |
| Workflow cancelled | Detected between iterations — node stops cleanly |
idle_timeout reached during iteration | Iteration completes with whatever output was collected; loop continues |
retry: set on loop node | Workflow fails to load at parse time |
Interactive loop vs approval with on_reject
Both primitives handle human-in-the-loop iteration. Choose based on your pattern:
| Interactive loop | Approval + on_reject | |
|---|---|---|
| YAML key | loop.interactive: true | approval.on_reject: { prompt } |
| User input variable | $LOOP_USER_INPUT | $REJECTION_REASON |
| Best for | Conversational iteration — explore, refine, review cycles | Gate-then-fix — approve to proceed, or reject to trigger a specific corrective action |
| Completion signal | AI detects user intent in output | User explicitly approves or rejects via button/command |
on_reject.
Related pages
Authoring Workflows
Full workflow YAML reference including DAG, conditions, and retry.
Approval Nodes
Human-in-the-loop gates with approve/reject and
on_reject rework.Variable Reference
Complete list including
$LOOP_USER_INPUT, $LOOP_PREV_OUTPUT, and $REJECTION_REASON.Workflow Schema
Full YAML schema including
loopNodeConfigSchema.