Agent loop orchestrator
Each cycle runs four steps: triage, dispatch, monitor, report. This skill runs one cycle. Repetition comes from the harness, not from you.
Scheduling
Never sleep in a shell between cycles. Use the harness's recurring-run facility (Claude Code: /loop <interval> /agent-loop:resume, or the schedule skill). Without one, run one cycle, report, and tell the user how to rerun.
Cycle
- Triage. Follow
../agent-loop-triage/SKILL.mdfor the configured scope. It returns items classified asautonomous,needs_review,defer, orblocked. - Dispatch. Spawn one background subagent per
autonomousitem, at mostmax_concurrencyat a time. Give each one the item, the repo, and pointers to../agent-loop-autoreview/SKILL.mdand../agent-loop-browser/SKILL.md. Never batch two items into one worker. Workers touching the same repo must use separate branches or worktrees. - Monitor. Collect each worker's result:
merged,pr_opened,failed(retry at most twice), orneeds_human(with what blocks it). - Report. Update the state file, append a cycle summary to
.agent-loop/logs/, and print it: repo, counts per class, one line per worker result, duration.
Stop early if the state file has shutdown_requested: true. Let running workers finish, write final state, and print the summary.
Configuration
Flags, then env, then defaults: AGENT_LOOP_INTERVAL (300 s), AGENT_LOOP_MAX_CONCURRENCY (3), AGENT_LOOP_SCOPE (current, all, org), AGENT_LOOP_REPOS (git remote), AGENT_LOOP_STATE_FILE (.agent-loop/state.json).
State file
This is the single definition of the state file. All agent-loop commands read and write this shape.
{
"cycle": 42,
"started_at": "2026-10-19T00:00:00Z",
"last_cycle_end": "2026-10-19T03:30:23Z",
"shutdown_requested": false,
"items_processed": 87,
"items_autonomous": 34,
"items_needs_review": 28,
"items_deferred": 25,
"prs_merged": 15,
"active_threads": [3, 4],
"thread_history": [
{ "id": 1, "item": "GH-123", "result": "merged", "pr": "#456" },
{ "id": 2, "item": "GH-124", "result": "failed", "reason": "test flake" }
],
"last_error": null
}
Rules:
- Write atomically. Write to a temp file in the same directory, then rename.
- A valid state file parses as JSON and has
cycle,started_at, andthread_history. Missing counters default to 0. - Before overwriting or clearing state, copy it to
.agent-loop/backups/state-YYYY-MM-DD-HHmmss.json. Keep the newest 50 backups. - On load, any
active_threadsid with no running worker is orphaned. Record it inthread_historyasfailedwith reasonorphanedand remove it fromactive_threads.