> ## Documentation Index
> Fetch the complete documentation index at: https://docs.open4rena.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic workflows

> Have the agent write a workflow script that runs helper agents in parallel, then approve it once.

A dynamic workflow is a short TypeScript script that the agent writes for one
request. The script splits the work into steps, sends independent steps to
helper agents in parallel, and checks each helper's answer against a schema
before the next step uses it. o4 shows you the plan as a step map first, and
nothing runs until you approve it.

Use a workflow when a task splits into many similar, independent pieces, such
as reviewing every changed file, checking each module against a rule, or
gathering facts from many places and then summarizing them. For a single
focused change, ask the agent directly.

## Start a workflow

```text theme={null}
/workflow review every file changed on this branch and summarize the risks
```

`/workflow <request>` starts an ordinary turn. The agent loads the bundled
`dynamic-workflows` skill, picks a helper layout for the request, and calls
`create_workflow` with a script. Your request goes to the agent word for word.

You can also just describe a task that splits this way. The agent may choose
to write a workflow, and the same approval applies.

`/workflow` with no text opens the run list (see [The run list](#the-run-list)).
It works while a turn is running.

Before anything runs, o4 analyses the script. If the script has errors, the
agent gets the diagnostics with line and column and nothing is executed; it
fixes the script and submits it again.

## The step map

A valid script opens the step map for your approval, for example (shortened):

```text theme={null}
Workflow approval
  Run workflow: Review changed files
  3 phases
  Max concurrency: 7

  Phase 1: Survey the change
  Participant: workspace
  certain world-read: git-changed-files HEAD~1 (workspace); result: string[];

  Phase 2: Review each changed file in parallel
  Participant: reviewer (many)
  may ask: reviewer (reviewer); result: Finding[]; repeats: stack

  Phase 3: Summarize for the user
  Participant: summarizer
  certain ask: writer (summarizer); result: string;

  Handoffs and ordering
  Handoff: reviewer [Review each changed file in parallel] gives Finding[] to
  summarizer [Summarize for the user]

  Commands it may run: none
  Sandbox tier: guarded
  Sub-agents act without asking. Your deny rules and the guarded sandbox still
  apply.
  Rough estimate: $0.06 + unknown x $0.09 per item (not a limit)
```

It lists each phase in order with its participants (`(many)` marks a fan-out
with one helper per item), what each step reads and returns, how results pass
between phases, every shell command the script may run, the sandbox tier, and
a rough cost estimate. The estimate is not a limit.

| Key | Action |
| - | - |
| `Enter` | Run the workflow once |
| `s` | Run it, and don't ask again for workflows in this session (never saved to settings) |
| `v` | View the script, read-only with line numbers (`Esc` returns to the map) |
| `Esc` | Decline: nothing runs |

## While it runs

An approved workflow runs in the foreground by default. A progress block in
the chat shows:

* the run's state, elapsed time, tokens, cost and how many helpers are working
  at once;
* each phase as done (✓), running (◐) or waiting (○), with counts of done,
  running, queued and failed steps;
* the helpers that are working, waiting (for example after a rate limit) or
  repairing an answer;
* the script's last log lines, and the reports and deliverables published so
  far.

| Key | Action |
| - | - |
| `Ctrl+B` | Move the running workflow to the background. The main agent continues and is told when the run finishes. |
| `Esc` | Stop the workflow. It ends as `stopped (user)` and can be resumed later. |

A background run appears in the agent list and in Ringside with its helpers.
When it finishes, the chat gets one line, for example:

```text theme={null}
Workflow 'Review changed files' completed in 6m12s · 3 deliverables · 128k tokens · $1.04 — /workflow to open.
```

The main agent also receives the run's result, reports and deliverables, so
it can tell you what was produced.

Each helper answer is checked against the schema derived from the script's
types. A wrong answer is sent back for repair up to three times before the
step fails. A helper that ends its turn without submitting an answer is
reminded once.

## Resume an interrupted run

Every step is saved to a journal as it finishes. If o4 exits or is killed
while a run is live, the run is marked `stopped (interrupted)`. The next time
o4 starts in that project it offers to resume:

```text theme={null}
Workflow 'Review changed files' was interrupted after 9 of 14 steps. Open /workflow to resume it later.
  [ Resume 'Review changed files' ]  [ Dismiss 'Review changed files' ]
```

A resumed run replays its finished steps from the journal without running
them again, and continues with the unfinished ones. It needs no new approval,
because it runs the script you already approved. Your permission rules and
hooks still apply.

A run can be resumed when it is `stopped`, for any reason other than
`superseded`. A completed run has nothing to resume, and an errored run needs
a corrected script in a new run.

## The run list

`/workflow` with no text opens the Workflows pane with this project's runs,
newest first:

```text theme={null}
● Review changed files   stopped (interrupted) · 2h ago · 41k · $0.38 · resumable
```

| Key | Action |
| - | - |
| `Enter` | Show the run's details and its script |
| `r` | Resume the run (resumable runs only) |
| `x` | Stop the run (running runs only) |
| `o` | Open the run's folder |

The agent can inspect runs too, with `list_workflow_runs`, `get_workflow_run`
and `resume_workflow_run` (see the [tools reference](https://docs.open4rena.ai/reference/tools.md)).

## Print mode

`o4 -p` runs workflows to the end:

```bash theme={null}
o4 -p "/workflow review the changed files and list the risks"
```

* In the `auto` (the print default) and `bypass` permission modes, a workflow
  starts without a step map, because nobody is there to approve one. In every
  other mode a workflow is refused with "workflows need approval; run with
  \--permission-mode auto or bypass" and print stops at once.
  `/workflow <request>` is then refused before the model is asked, and a
  `create_workflow` call from a plain prompt ends print without the model
  continuing.
* After the main turn ends, print waits for every run it started, with no
  timeout. Each finished run is given to the agent as a follow-up turn.
* stdout carries only the agent's final answer. stderr gets one line per run
  event:

  ```text theme={null}
  workflow 'Review changed files' started
  workflow 'Review changed files' phase 2/3 · 3 running · 41.2k tokens
  workflow 'Review changed files' log: 12 files to review
  workflow 'Review changed files' completed in 6m12s · $1.05
  ```

  A resumed run says `resumed` instead of `started`. A progress line also
  counts repairing and failed steps when there are any. Progress lines are
  throttled to one every 400 ms across all runs, while start, log and settle
  lines always print. A run settles as `completed`, `errored` or
  `stopped (<cause>)`, where the cause is `user`, `model`, `provider`,
  `interrupted` or `superseded`, and its settle line gives the time and cost.
  A run that ends without a settled result prints
  `workflow '<name>' ended without a result`.
* `o4 -p "/workflow"` prints this project's runs (at most 20) without a model
  turn.

Exit status:

| Status | When |
| - | - |
| `0` | Every run completed, or no run was started |
| `1` | A run errored or was stopped, a workflow was refused for needing approval, the main turn failed, or the run journal could not be read |
| `130` | `Ctrl+C` after a run started. Live runs are stopped as `stopped (interrupted)` within about five seconds and stderr says `interrupted`. A second `Ctrl+C` exits at once. |

## Settings

Workflow settings live under `workflow` in your user settings
(`~/.o4/settings.json`). They are user-only: a project's `.o4/settings.json`
cannot change them, so a cloned repository cannot turn workflows on or switch
off the script's confinement. `/config` shows the current values on its Agents
tab.

```json theme={null}
{
  "workflow": {
    "enabled": true,
    "child_heap_mb": 256,
    "confine_child": true,
    "start_in_background": false
  }
}
```

| Setting | Default | Effect |
| - | - | - |
| `workflow.enabled` | `true` | When `false`, no workflow tool is offered, `/workflow` is not reserved (a plugin or custom command may use the name), and no resume is offered |
| `workflow.child_heap_mb` | `256` | Memory limit of the workflow script process in MiB, clamped to 64–2048 |
| `workflow.confine_child` | `true` | Run the workflow script process inside the OS sandbox (see [Permissions](#permissions)) |
| `workflow.start_in_background` | `false` | Start approved workflows in the background instead of showing the progress block |

## Permissions

Approving the step map is your consent for the whole run. Helpers then act
without asking for each tool call. What still applies:

* **Deny rules.** Your permission rules still block matching tool calls. An
  `ask` rule is treated as allow, because nobody is there to answer, so use a
  deny rule to stop an action.
* **PreToolUse hooks** still run for helper tool calls.
* **The sandbox tier** in force when the run (or its resume) starts applies
  to helper shell commands for that run. Changing the tier later does not
  change a running workflow.
* **Commands.** A script can only run the commands listed on the step map.
  They run with a fixed argument list, never through a shell string, and are
  checked against your deny rules like `bash` calls.

Helpers can't ask you questions, start other agents or campaigns, or create,
inspect or resume workflows of their own.

The workflow script itself runs in a separate process that has no file,
network, environment or clock access of its own. It reaches the workspace
only through the steps it declares, which o4 carries out. With
`workflow.confine_child` on, o4 also runs that process inside the OS sandbox:
`sandbox-exec` on macOS, or bubblewrap on Linux when it is installed.
Elsewhere it runs unconfined and o4 logs that.

## Limits

| Limit | Value |
| - | - |
| Helpers at once | The machine's CPU cores minus 2, at least 1 and at most 16. The agent can ask for fewer. |
| Repairs per answer | 3, plus 1 reminder when a helper ends without an answer |
| Reports per run | 256, at most 32 KiB each |
| Deliverables per run | 32, up to 16 versions each. Markdown up to 256 KiB, files up to 20 MiB |
| File reads | `files.glob` up to 2,000 files, `files.read` up to 1 MiB, `files.grep` up to 2,000 matches or 256 KiB |
| Git reads | `git.diff` up to 512 KiB, `git.log` up to 100 entries (20 by default) |
| Commands | 5-minute default timeout, at most 256 KiB of stdout and of stderr |
| Script memory | `workflow.child_heap_mb`, 256 MiB by default |

A read or command that goes over its limit fails that step. Nothing is
silently cut short. Too many reports fails the run.

Deliverables are stored under `.o4/workflow-runs/<run id>/` in the project.
That folder is ignored by Git. The run journal lives in `~/.o4/sessions.db`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.