agentsclimarketplace

Autonomous loop patterns

Skill jacob-balslev/skills/skills/agent-ops/autonomous-loop-patterns

Public Agent Skills library exported from skill-graph. Install: npx skills add jacob-balslev/skills

Install
npx -y skills add jacob-balslev/skills --skill autonomous-loop-patterns

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • 0 stars0 stars. Stars are a popularity signal and not a quality one, but at this level it is likely that nobody has read this closely except its author, and you would be relying on your own review.

What its author says it does

Copied from the file, not written here

Use when designing, reviewing, or debugging an autonomous AI agent loop: repeated agent execution, completion signals, checkpoints, supervisor respawn, stall detection, safety caps, and human handoff rules. Covers the core loop patterns from simple bounded runs through sentinel-based continuation, checkpoint-resume, and external supervisor loops. Do NOT use for choosing a specific agent product command (use agent-engineering or the product's docs), writing ordinary task instructions (use prompt-craft), or optimizing individual tool calls (use tool-call-strategy).

SKILL.md

21.7 KB, as published. Nobody here has run it

Autonomous Loop Patterns

Concept of the skill

An autonomous loop has six primitives: a trigger, a worker agent, a progress signal, a stop condition, durable state, and a safety cap.

Coverage

  • Core primitives of an autonomous agent loop: trigger, worker agent, progress signal, stop condition, durable state, and safety cap.
  • Pattern selection across bounded single-run loops, sentinel continuation loops, checkpoint-resume loops, and external supervisor loops.
  • Completion signal design: explicit done markers, tracker state, exit status, persisted status files, and observable progress evidence.
  • Safety design: iteration limits, consecutive-error limits, elapsed-time limits, budget limits, context-health exits, and human handoff thresholds.
  • Stall detection and recovery: heartbeat age, unchanged work state, repeated failures, repeated plan churn, and supervisor escalation.
  • Checkpoint and handoff contracts: what state must persist between runs and what state must never live only in agent memory.
  • Anti-patterns that make autonomous loops unsafe: unbounded retry, prompt-only reliability, hidden mutable state, and silent respawn storms.

Philosophy of the skill

An autonomous agent loop is not just an agent being told to continue. It is a control system. The agent is one component; the loop decides when to run it again, what evidence proves progress, what state survives a crash, and when a human must take over.

The smallest safe loop is usually better than the most powerful loop. A one-off task with a clear finish condition does not need a queue supervisor. A multi-session backlog should not rely on a single completion word. A long-running unattended process must not depend on the worker agent remembering its own state.

The quality bar is explicit termination plus recoverable state. If a loop cannot answer "why did this run again?", "what changed since the last iteration?", and "what stops it from running forever?", it is not an autonomous loop. It is an uncapped retry.

The Six Primitives

PrimitiveQuestion it answersExamples
TriggerWhat starts the next iteration?User request, queue item, scheduler tick, failed verification
Worker agentWho performs one unit of work?A coding agent, reviewer agent, data extractor, browser runner
Progress signalHow do we know anything changed?Commit, test result, status update, artifact write, metric delta
Stop conditionWhat means the loop is done?Empty queue, completion marker, passing gate, explicit human stop
Durable stateWhat survives crash or context reset?Checkpoint file, issue comment, job record, append-only log
Safety capWhat forces review when progress fails?Max iterations, max consecutive errors, elapsed-time cap, budget cap

Design the primitives first. Tooling choices come second.

Pattern Catalog

PatternBest forStop ownerState ownerMain risk
Bounded single-run loopOne clear task that should finish in one sessionRuntime limit or final verification gateThe current run plus final artifactAgent tries to continue after the task is already done
Sentinel continuation loopSmall repeated task with a precise done markerCompletion marker checked by a wrapper or hookTranscript plus optional counterCompletion marker appears accidentally or never appears
Checkpoint-resume loopMulti-session work where context may resetCheckpoint state and remaining-work countDurable checkpointStale checkpoint causes repeated or skipped work
Supervisor respawn loopLong-running unattended throughputExternal supervisorStatus files, queue, and logsRespawn storm after repeated failure
Human-gated loopRisky work with side effects or unclear requirementsHuman approval gateReview record and approved next actionLoop waits without making the escalation visible

Pattern 1: Bounded Single-Run Loop

Use this for a single task with a concrete finish condition. The prompt names the deliverable, the runtime enforces a hard limit, and verification decides whether the run is done.

Use when:

  • The work has one primary deliverable.
  • The done condition can be verified inside one run.
  • Failure is reviewable from the final artifact and logs.
  • Restarting from scratch would not lose meaningful progress.

Required safeguards:

  • A hard iteration or elapsed-time limit.
  • A final verification command or acceptance gate.
  • A clear final status: done, blocked, or failed.

Do not use this for long backlogs, stateful migrations, or tasks where partial progress must be resumed.

Pattern 2: Sentinel Continuation Loop

A sentinel loop repeats until the worker emits a precise completion marker, or until a wrapper decides the marker is absent and starts another turn. Some teams call this the Ralph Wiggum pattern: the runtime keeps going until the agent says the exact stop phrase.

Prompt contract:

Do the task described below.

Completion condition: all requested changes are implemented and verification passes.

When and only when the completion condition is true, output this exact marker:
TASK_COMPLETE_9F3A

If the task is blocked, output BLOCKED with the reason instead.
Do not output the completion marker in code, examples, logs, or explanations.

Use when:

  • The task is small enough that repeated turns stay understandable.
  • The completion condition is easy to state as a marker contract.
  • A wrapper can count iterations and stop after a cap.

Required safeguards:

  • Use an uncommon marker, not a word like "done".
  • Count iterations outside the model.
  • Stop on a blocked marker instead of continuing forever.
  • Keep the marker out of code snippets and examples.

Do not use this when the task spans many sessions, requires durable queue state, or has high-risk side effects.

Pattern 3: Checkpoint-Resume Loop

A checkpoint loop persists the state needed to resume later. The worker writes a checkpoint at the end of each run. The next run reads it, verifies it against current reality, and continues.

Minimum checkpoint contract:

{
  "objective": "short stable goal",
  "iteration": 3,
  "max_iterations": 10,
  "remaining_work": ["item-a", "item-b"],
  "completed_work": ["item-0"],
  "last_verified_evidence": "test name or artifact reference",
  "context_health": "ok | degraded | exhausted",
  "next_action": "the first action for the next run",
  "stop_reason": null
}

Use when:

  • The work cannot safely fit in one context window.
  • Partial progress must survive a restart.
  • The loop must decide whether work remains before starting another run.
  • A fresh run may need a compact handoff instead of full history.

Required safeguards:

  • Write checkpoints atomically where the platform supports it.
  • Treat checkpoint state as a cache; verify current reality before acting.
  • Stop when context health is exhausted, even if work remains.
  • Include the next action so the next run does not rediscover the plan.

Do not store the only copy of progress in model memory or chat history.

Pattern 4: Supervisor Respawn Loop

A supervisor loop runs outside the worker agent. It starts a worker, watches status and timeout signals, records the result, and decides whether to spawn another worker.

Use when:

  • Many independent work items need unattended throughput.
  • Each worker should start with fresh context.
  • The supervisor can own queue selection, timeout, and retry policy.
  • Workers may fail independently without ending the whole process.

Required safeguards:

  • Per-worker timeout.
  • Consecutive-error cap.
  • Queue item lock or claim before work starts.
  • Status write on success, failure, blocked, and timeout.
  • Supervisor log that explains every respawn decision.

Do not let a supervisor respawn a worker after repeated identical failures without changing state, backoff, or escalation.

Completion Signals Ranked

SignalReliabilityUse it forFailure mode
Authoritative tracker stateHighQueue and backlog loopsTracker update omitted or duplicated
Passing verification gateHighCoding, data, or document loopsGate is too shallow or not rerun
Explicit sentinel markerMedium-highSmall repeated tasksMarker appears accidentally or never appears
Durable checkpoint says no work remainsMediumCheckpoint loopsCheckpoint is stale
Process exit codeMediumSupervisor loopsExit code lacks semantic detail
Absence of new outputLowLast-resort stall hint onlyQuiet work and stalled work look the same

Prefer authoritative tracker state and verification gates when available. Use sentinel markers for small loops. Use absence of output only as a stall warning, never as proof of completion.

Safety Caps

Every autonomous loop needs at least one cap. Unattended loops usually need several.

CapPreventsTypical default
Max iterationsEndless continue loops5-15 iterations, lower for risky work
Consecutive errorsRespawn stormsStop after 3 repeated failures
Elapsed timeLong silent runsBased on expected phase duration
Work item lock ageZombie ownershipExpire only after evidence of worker death
Context healthLow-quality late-session changesStop and hand off at exhausted context
BudgetRunaway costSmall initial budget, staged increase

The cap must be enforced outside the worker when possible. A model instruction that says "do not loop forever" is not a cap.

Stall Detection

A loop is stalled when it keeps consuming iterations without improving the durable state.

Common stall signals:

  • Same work item repeated across several iterations.
  • No new durable artifact after an iteration that claimed progress.
  • Same verification failure appears repeatedly.
  • The worker rewrites the plan but does not execute it.
  • Heartbeat or status timestamp is older than the expected phase duration.
  • Supervisor respawns the same failing task without backoff or escalation.

Recovery sequence:

  1. Stop the current worker or refuse the next respawn.
  2. Preserve the latest checkpoint, logs, and verification output.
  3. Classify the stall: unclear requirement, failing dependency, repeated bug, or loop-control error.
  4. Escalate to human review when the next action requires judgment.
  5. Restart only after changing the state that caused the stall.

Do not recover from a stall by only increasing the iteration limit.

Pattern Selection

Use this decision table before implementing loop control.

SituationRecommended pattern
One task, one artifact, clear verificationBounded single-run loop
One task that may need a few more turnsSentinel continuation loop
Multiple related steps that may exceed contextCheckpoint-resume loop
Many independent queue itemsSupervisor respawn loop
Side effects, approvals, or unclear requirementsHuman-gated loop
Unknown done conditionDo not loop yet; define the stop condition first

The rule of thumb: choose the simplest pattern that can stop safely and resume correctly.

Implementation Checklist

Before shipping an autonomous loop, answer these questions in writing:

  • What exactly starts one iteration?
  • What exactly proves the iteration made progress?
  • What exactly means the whole loop is done?
  • Where is state written so it survives restart?
  • What cap stops repeated failure?
  • How does a human see why the loop stopped?
  • Which operation is safe to retry, and which requires approval?

If any answer is "the agent will remember", the design is not ready.

Anti-Patterns

Anti-patternWhy it failsSafer replacement
Unbounded continue promptThe model can retry forever without new evidenceExternal iteration cap plus blocked state
Prompt-only reliabilityThe model is both worker and watchdogRuntime or supervisor enforces caps
Hidden progress in chat historyRestart loses the work stateDurable checkpoint or tracker update
Completion by silenceQuiet output is indistinguishable from a hangExplicit done, blocked, failed, or timed-out state
Respawn without state changeRepeats the same failureBackoff, classify, and escalate
One giant worker contextContext rot degrades decisionsFresh worker per item or checkpoint handoff
Human gate buried in logsReview never happensExplicit approval state and visible stop reason

Verification

After applying this skill, verify:

  • The chosen pattern is the simplest one that can safely stop and resume.
  • The loop has an explicit stop condition and an explicit blocked condition.
  • At least one safety cap is enforced outside the worker agent.
  • Durable state records objective, iteration, remaining work, latest evidence, and next action.
  • Stall detection can identify repeated work, repeated failure, stale heartbeat, or no durable progress.
  • Completion is based on tracker state, verification output, or a precise marker, not silence.
  • Human handoff is visible when the loop reaches a cap or a judgment boundary.

Do NOT Use When

Use insteadWhen
agent-engineeringDesigning the full production agent system, including model routing, multi-agent coordination, and rollout policy
prompt-craftWriting the exact instruction for one agent run or one worker prompt
tool-call-strategyOptimizing how many tools one agent calls inside a single iteration
context-managementDeciding what information belongs in one worker's context
observability-modelingDesigning event names, spans, metrics, and trace attributes for the loop
Product-specific docsChoosing a slash command, IDE feature, or hosted-agent setting in a particular tool

Keep looking

Skills are one crate of 328,083. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.