A control plane for loop side effects
One egress point for every model and tool call a loop makes: loop-aware retries, idempotency, budgets, approvals and a state sink. What exists, what's missing.
The problem
A loop that only edits files in a sandbox can be thrown away and re-run. A loop that touches the outside world can't. Once a loop places phone calls, writes to a CRM, sends Slack or email messages, opens tickets or charges a card, every external call needs the same things:
- Credentials, scoped to the loop and revocable.
- Retries with backoff, and a decision about when to stop retrying.
- Rate limits, both the provider's and your own.
- A budget, in dollars, not only tokens. SMS, voice minutes and data-enrichment lookups cost money too.
- Idempotency. If the iteration crashes after sending the email but before recording that it did, the next iteration must not send it again.
- An audit trail tying each action to the goal that caused it.
- Somewhere to write state, so the loop can resume after an interruption.
Today each loop builder wires this up per tool and per harness. Loops make it worse in two specific ways:
- Iterations repeat by design. A goal loop that continues after a crash, or a Ralph loop restarting with fresh context, will happily re-execute side effects it has no memory of.
- Loops fail quietly. An agent that loops or drifts still returns 200 with normal latency, so standard monitoring doesn't fire (Morph, OptScale). secondary reporting
What already exists
The plumbing exists, in slices. Each layer sees part of a loop's traffic and none of it knows it's a loop.
| Layer | Examples | Covers | Doesn't cover |
|---|---|---|---|
| LLM gateways | OpenRouter, Portkey, LiteLLM, Cloudflare AI Gateway, Helicone | Model routing, fallbacks, retries, caching, spend caps, request logs | Tool calls and their side effects; any notion of goal or iteration |
| Tool integration platforms | Composio, Arcade, Nango | Managed OAuth, pre-built tools for CRMs, messaging and SaaS APIs; some offer syncs and webhooks | Model spend, cross-tool budgets, loop semantics |
| MCP gateways | Cloudflare MCP Portals, Zuplo, Workato and others (Zuplo, MintMCP) | Central auth, per-agent and per-tool rate limits, audit logs tied to a person | Model calls, state, retries across iterations |
| Durable execution | Temporal, Inngest, Restate, DBOS (overview) | Retries, step-level checkpoints, durable sleep and wait-for-event, pausing for human approval | Requires rewriting the loop as workflow code; no integrations or model routing included |
A few market notes, all secondary reporting from 2026 gateway comparisons (Future AGI, Eden AI, dupple):
- Gateways are consolidating into security vendors. One comparison reports that Palo Alto Networks completed its acquisition of Portkey in May 2026, folding it into its agent-governance offering. Another reports Helicone in maintenance mode after an acquisition in March 2026.
- Integration vendors are mostly reviewed by each other. Much of the Composio, Arcade and Nango comparison material is written by one of the three. Treat the verdicts as marketing.
- Durable execution is being re-pitched as agent infrastructure. Its pause, resume and wait-for-event primitives are exactly what waiting goals lack, but adopting it means restructuring your loop.
The gap: loop semantics
None of these layers can answer: "Is call #4 of iteration 17 of the goal 'follow up with every stale lead' the same action as call #4 of iteration 16?" That question is the whole difference between a safe retry and a duplicate message to a customer.
What's missing is a layer that understands the loop's own structure:
- Goal
- The long-lived objective. Owns the budget, the credentials scope and the audit trail.
- Run
- One attempt at the goal, from start to stop (achieved, budget-limited, abandoned).
- Iteration
- One pass of the loop. The unit that gets retried, resumed or thrown away.
- Intent
- A side effect the loop means to cause ("email lead 4711 about renewal"). The key for idempotency.
The proposal: one egress for every loop
A proxy that every model call and every tool call goes through, speaking an OpenAI-compatible API for models and MCP for tools, so existing harnesses only need a base URL change. Each request carries goal, run and iteration ids, mapped onto the OpenTelemetry GenAI conventions (invoke_agent and execute_tool spans) where possible (Dash0).
Before executing a side-effecting tool call, the proxy derives an intent key (goal + tool + normalized target). If that intent already succeeded in this goal, it returns the recorded result instead of acting again. The loop sees "already done", not an error. This is the single most valuable feature for loops that talk to people.
Retry transient failures within an iteration. Across iterations, count identical failures: after N, trip a breaker and hand the loop a structured stop ("escalate: CRM rejects writes with 403 since iteration 12") instead of letting it thrash. See stuck loops.
Dollar budgets per goal that count model tokens, SMS segments, call minutes and paid API lookups together. A goal that's cheap in tokens but expensive in phone calls is still expensive.
Ingest webhooks (CI finished, customer replied, payment cleared) and wake the loop, rather than letting it re-read its context every few seconds to check. This is the pacing problem solved outside the harness.
An append-only event log per goal: state transitions, intents executed, judge verdicts. The loop can write to it and resume from it; the operator can export it to their own warehouse. It's a concrete answer to the idea board's minimum resumable state question, and it keeps loop state out of an uncommitted local file.
Hold selected intents (outbound calls, payments, messages to new recipients) for human approval, with the evidence attached. The loop keeps working on other things while it waits.
The low-hanging version
Tag and log only. An OpenAI-compatible and MCP proxy that forwards everything unchanged and records each call with its goal and iteration. Zero behavior change, so zero risk to adopt. It immediately feeds loop-native reporting.
Budgets and breakers. Per-goal dollar caps and identical-failure breakers. Both are policies over the log you already have.
Idempotency for a handful of dangerous tools. Email, SMS, voice calls and CRM writes first. These are where duplicates hurt.
Webhook-to-wake. Replace polling for the two or three events loops wait on most.
Build on, not against. There's no reason to rebuild hundreds of OAuth connectors: credentials and connectors can come from an integration platform, model routing from an existing gateway, and durable execution can be an optional backend. The value is the loop semantics on top.
Risks and open questions
- One egress is one target. Concentrating every credential a loop uses in one service is a security trade-off, not a free win. It needs the same scrutiny as any secrets store.
- Latency. Gateways add milliseconds per call; vendor benchmarks claim anywhere from 1 to 40 ms contested. Negligible for loops, but it adds up for chatty inner tool loops.
- The harnesses may absorb it. Hermes has gateway spending limits and Codex has per-goal token budgets. If harness vendors add idempotency and wake-on-event, the standalone case shrinks to cross-harness and multi-tool users.
- Crowded market, thin moat. Routing and auth are commodities. If loop semantics aren't clearly valuable, this is just another gateway.
Further reading
- What the best MCP gateways do in 2026 (Zuplo, vendor)
- Durable execution for agents (AgentWiki)
- Runaway agents: detecting loops, drift and recursion (OptScale)
Remedies we're exploring
Three proposals for problems this guide documents: a control plane for loop side effects, off-peak token routing and loop-native reporting. Not products.
Off-peak tokens and arbitrage
Much of what a loop does could wait. Who sells cheaper tokens for deferrable work in late 2026 (flex tiers, batch, off-peak), and a deadline-aware router.