Problem
Autonomous multi-agent loops that run across many cycles (minutes, hours, or days) need a way to reliably transfer context, decisions, and next actions between cycles. In-memory state is lost on crash or restart. Generic checkpoint files don't encode the structured reasoning — what was decided, why, and what comes next — that agents need to make good decisions in subsequent cycles.
Without a structured relay mechanism, autonomous loops suffer from:
- Drift: each cycle restarts without awareness of prior decisions
- Repetition: agents re-debate already-settled questions
- Stalls: no convergence signal — agents loop indefinitely without shipping
Solution
Each agent cycle reads a consensus relay document at the start, executes its work, then writes an updated consensus document at the end. The document is not just a checkpoint — it's a structured handoff that encodes current phase, completed actions, active decisions, open questions, and the single most important next action for the following cycle.
The relay document is written to a temp file and atomically renamed to prevent partial-write corruption. Every field is a deliberate relay signal, not just a log.
Core pattern:
# auto-loop.sh — the minimal autonomous loop
while true; do
# Each cycle reads the relay baton, executes, writes a new one
claude -p "$(cat PROMPT.md)" \
--context "$(cat memories/consensus.md)"
sleep $CYCLE_INTERVAL
done
Relay document structure:
# Relay Consensus
How to use it
Best for:
- Long-running autonomous agent loops (multi-cycle, multi-day execution)
- Multi-agent systems where context and decisions must survive restarts
- Teams of agents where shared understanding of "what we've decided" matters
- Any system where you want convergence toward shipping rather than endless discussion
Implementation steps:
-
Define your relay document schema — every field should serve the next cycle, not just log the current one:
Trade-offs
Pros:
- Agents resume with full context even after crash, restart, or long pause
- Structured relay prevents context drift across cycles
- Open questions create forward pressure — cycles don't stall in comfort
- Convergence rules can be encoded directly in the relay document
- Human-readable: anyone can inspect the relay and understand the workflow state
- Git-friendly: diffs show exactly what changed between cycles
Cons:
- Schema discipline required — a poorly structured relay document degrades agent reasoning
- Relay grows over time; needs periodic summarization / archival of old decisions
- Single-file relay is a bottleneck for high-frequency loops (>1 cycle/minute)
- Context window limits constrain how large the relay can grow
- Sensitive state (API keys, credentials) must never be written to the relay file
Operational considerations:
- Keep the relay document under ~2000 tokens to leave room for agent reasoning
- Archive old cycles to
memories/archive/when the relay grows unwieldy - Use atomic writes (write to temp, rename) to prevent partial-write corruption
- Commit the relay to git after each cycle for full audit trail
- Define what "done" looks like in the relay — open-ended phases create drift
References
- Anthropic Engineering: Effective harnesses for long-running agents
- BabyAGI — early task-loop example with persistent task artifacts
- Related: Filesystem-Based Agent State — for checkpointing within a single cycle
- Related: Proactive Agent State Externalization — for agents that self-initiate state writes
- Related: Initializer-Maintainer Dual Agent Architecture — for session handoff artifacts across repeated work cycles