Skip to main content
T3 · engineering: for_each + agent: is the swarm pattern. Every changed file gets its own mini-agent with read-only tools (default-deny means exactly that), a turn budget and a token budget. jq flattens the typed findings; one model writes the summary.

The job

Big PRs get shallow reviews because attention doesn’t scale. Here it does: each changed file is reviewed in isolation by an agent that can READ and nothing else, in parallel, four at a time. A deterministic nika:grep sweep counts the TODO debt beside the LLM pass, and the final REVIEW.md ends with a verdict.
Limit on macOS in 0.124.3. The sandbox confines exec: git to the workflow’s declared filesystem boundary, which grants no read of .git or of git’s global configuration. The confined git exits with status 128, even inside a real repository, so changed takes its recover: value: no file reaches the swarm, no agent runs, and the summary says the diff was unavailable instead of calling the branch clean. See Known limits.

The shape

The graph starts with the human gate, then independent branches run in parallel behind it. The agent fans out mid-graph, and the join waits for both branches before summary.

The file

pr-review-fanout.nika

How it works

1

exec output becomes a collection

git diff --name-only is a string; the jq split("\n") turns it into the array the fan-out iterates. Workflows turn ANY tool output into a collection this way.
2

Each agent is least-privilege

tools: ["nika:read", "nika:done"]: the reviewer can read source and end its loop. It cannot write, fetch, or wander. Budgets (max_turns: 6, max_tokens_total: 30000) bound the worst case.
3

Typed findings merge deterministically

Every agent returns {file, findings[]} per its schema. The jq fan-in flattens and sorts: blockers surface first in REVIEW.md.

Constructs you just used

Run it

What it needs: A Git repository with changes under ./src and a const.base_ref that exists, plus a local model (Ollama serving qwen3.5:4b). Git is refused on macOS in 0.124.3, so there the diff is reported unavailable and no agent runs (Known limits).
1

Rehearse it

A mock model answers and nothing is written in your folder. It stops at the approve gate, as a real run does.
2

Get your own copy

Save the file above as pr-review-fanout.nika at the root of the repository you want reviewed. It reads no sample file.
3

Check it, then run it

The run writes REVIEW.md.It asks at the approve gate before anything else runs. On a terminal you answer; in a script it pauses (exit 4) and prints the --resume line that continues it, or you answer up front with --answer approve=true.Any other model works: pass --model <provider>/<name> with its key, and cap a cloud model with --max-cost-usd.

Make it yours

  • Specialize the swarm: route *.rs files to a Rust-prompted agent and *.sql to a migrations-prompted one with two filtered fan-outs.
  • Let reviewers read blame and history (still no write): declare a Git MCP server in .nika/mcp_servers.json, pin its tools with nika mcp approve <server>, and add its read tools to the agent’s tools: and to permits.tools.
  • Fail CI on blockers: end with nika:assert on size() of the blocker slice.

Level up · T4 epic

Final tier: multi-stage pipelines. A plan, a budgeted agent, a synthesis, and human gates where effects begin.