Loop engineering — autonomous agents that run on their own
Agents that own recurring work — triaging bugs, merging Dependabot PRs, turning Sentry into GitHub issues — with hard budgets, escalation, and a live trace you can audit step by step.
Crew AI showed how one prompt can build a workflow. Loops show how a workflow can run itself — over and over, on a schedule or a webhook, with a budget, a success condition, and a place to page a human when reality drifts from the plan.
The problem with most “automation”
Most automation is brittle if-this-then-that wiring. Every branch is hard-coded, every edge case lives in its own node, and any drift in the upstream system means a Saturday-morning page. The deeper problem: the system has no goal — only a graph. So whenever a tool returns something it wasn’t told to expect, the automation either silently misroutes or fails open.
We tried building a “smarter if-this-then-that” more than once. It doesn’t generalise. The honest reframing was to put the goal back at the centre, give the agent the tools it needs, and let it decide.
What an agent loop is
A loop is three nodes wired in a row: a trigger (cron or webhook), an agent node with tools, and an optional success/failure branch. Each fire is one autonomous run — the agent thinks, calls tools, observes results, and stops when its success condition holds or its budget runs out.
The first loop we built ourselves was the obvious one: a cron-triggered triager that pulls open Linear bugs older than 30 minutes, assigns them to the on-call engineer, and posts a heads-up in #eng-triage. It’s five lines of prompt, two tools, and a $0.05/run cost cap. It just runs.
Budgets are the unlock
Loops aren’t novel. Letting one run for a month without burning the corporate card is. Every loop in RunMyCrew enforces four budgets at the agent’s edge, checked before every LLM call:
maxIterations— max reasoning turns.maxSeconds— wall-clock against the run’s start.maxInputTokens— sum of every prompt’s input tokens.maxCostUsd— per-model pricing across every LLM call.
The system clamps each user value at hard caps (100 iterations, 1 hour, 5M tokens, $50). The moment any one trips, the loop short-circuits with a budget_exhausted status and the configured failure policy fires. The worst case is you wake up to a Slack message that says “loop X gave up after $0.50; here’s the last tool call.”
Stop conditions, not exit nodes
The agent’s final response is parsed as JSON when possible. The successWhen field is a JSONata expression run against that object. Truthy → done. Falsy → one more turn with a synthesised re-evaluate message. The expression is validated at save-time, so a typo fails the editor instead of failing the cron at 3 AM.
This sounds small. In practice, it’s the difference between “the loop ran 30 turns and gave up” and “the loop ran 4 turns, met its goal, and stopped.”
Concurrency + cron drift
Cron fires don’t always land on time — workers crash, queues back up, deploys eat a tick. Two policies per workflow, settable in the inspector:
- Concurrency —
skip,queue, orreplacewhen fire N+1 lands before fire N finishes. - Cron drift —
latest,catchup, orskipwhen the worker wakes up late and finds missed ticks.
Under the hood: a Redis SETNX + Lua CAS-release mutex keyed on the workflow id, and one Celery payload per fire the scheduler decides to honour.
Escalation
When a loop fails and the failure policy is escalate, the workspace’s escalation channel gets a structured payload: run id + link, status, failure reason, usage totals, and a five-step trace summary. Channels supported today: Slack (Block Kit), generic webhook, and email.
The live trace
The editor’s Logs panel grew a new tab. Pick an agent node mid-run; the Trace tab shows each tool call as a step the moment it starts, with status, arguments, result, and duration. Steps update in place — running flips to success/failed without re-layout, without a refresh. It’s the “debugger view” for agents.
What ships today
- Agent loop hardening — budgets, success conditions, failure policy.
- Workflow-level concurrency mutex + cron drift policy.
- Per-tool registry polish — tags, dangerous flag, rate-limit hook.
- Live trace timeline in the logs panel.
- Escalation to Slack / webhook / email.
- Three starter loop templates — triage Linear bugs, Dependabot auto-merge, Sentry → GitHub.
How to try it
Open the workflow editor, drop a Cron trigger and an Agent node, set a maxCostUsd, write a one- sentence prompt, pick a couple of tools, and hit Run. Or start from one of the bundled templates — they’re a good shape for whatever your version of recurring grunt work looks like.
Full design notes: /docs/agent-loops.