Any task involving repeated automated execution, retry logic, autonomous pipelines,
or self-repairing agent workflows. Also activates when implementing circuit breakers
or provider-aware fallback chains.
Mandatory actions when this skill is active
Before implementation
Define the loop's termination condition explicitly. No infinite loops without escape.
Set a maximum iteration count (default: 10 for code changes, 50 for data processing).
Identify the checkpoint mechanism — how will state be preserved between iterations?
Loop Patterns
Sequential Pipeline:
Task 1 -> Task 2 -> Task 3 -> ... -> Complete
Each task must succeed before the next starts
On failure: log, checkpoint state, halt with context for resumption
Use when: tasks have strict ordering dependencies
Circuit Breaker Pattern:
Attempt -> Success? -> Continue
| No
Failure count++
|
Count >= threshold?
| Yes
OPEN circuit -> wait -> half-open -> retry once
Threshold: 3 consecutive failures opens the circuit
Backoff: exponential (1s, 2s, 4s, 8s, max 60s)
Half-open: after backoff, allow ONE request through
If half-open succeeds: close circuit, resume normal operation
If half-open fails: re-open circuit, double backoff
Provider-Aware Fallback Chain:
Primary Model -> Timeout/Error? -> Fallback Model -> Timeout/Error? -> Degrade gracefully
Always try primary model first (respects cost-aware-routing tier)
On timeout (>30s) or error: switch to fallback
Fallback models: same tier or one tier down
Log every fallback with reason in AUDIT
Never silently degrade — always inform user of fallback
After 3 failed self-repair attempts: STOP and escalate to user
Each repair attempt must be DIFFERENT from the previous
Log each diagnosis and attempted fix
During implementation
Every loop MUST have: max iterations, checkpoint logic, escalation path
Never catch-and-swallow errors in loop bodies — always log with context
Track iteration count in AUDIT entries
Use SHARED_TASK_NOTES.md for cross-iteration context (see cross-iteration-bridge.md)
After implementation
Verify the loop terminates under all test conditions
Verify the circuit breaker opens and closes correctly
Confirm escalation path works (simulate max-retries-exceeded)
Self-check before task completion
Did I define explicit termination conditions for every loop?
Did I set maximum iteration limits (no unbounded loops)?
Did I implement checkpoint/state persistence between iterations?
Did I verify the escalation path works when max retries are exceeded?
1---2name: agent-loops3description: Skill — Agent Loops4---56# Skill — Agent Loops78## When this skill activates9Any task involving repeated automated execution, retry logic, autonomous pipelines,10or self-repairing agent workflows. Also activates when implementing circuit breakers11or provider-aware fallback chains.1213## Mandatory actions when this skill is active1415### Before implementation161. Define the loop's **termination condition** explicitly. No infinite loops without escape.172. Set a **maximum iteration count** (default: 10 for code changes, 50 for data processing).183. Identify the **checkpoint mechanism** — how will state be preserved between iterations?1920### Loop Patterns2122**Sequential Pipeline:**23```24Task 1 -> Task 2 -> Task 3 -> ... -> Complete25```26- Each task must succeed before the next starts27- On failure: log, checkpoint state, halt with context for resumption28- Use when: tasks have strict ordering dependencies2930**Circuit Breaker Pattern:**31```32Attempt -> Success? -> Continue33 | No34 Failure count++35 |36 Count >= threshold?37 | Yes38 OPEN circuit -> wait -> half-open -> retry once39```40- Threshold: 3 consecutive failures opens the circuit41- Backoff: exponential (1s, 2s, 4s, 8s, max 60s)42- Half-open: after backoff, allow ONE request through43- If half-open succeeds: close circuit, resume normal operation44- If half-open fails: re-open circuit, double backoff4546**Provider-Aware Fallback Chain:**47```48Primary Model -> Timeout/Error? -> Fallback Model -> Timeout/Error? -> Degrade gracefully49```50- Always try primary model first (respects cost-aware-routing tier)51- On timeout (>30s) or error: switch to fallback52- Fallback models: same tier or one tier down53- Log every fallback with reason in AUDIT54- Never silently degrade — always inform user of fallback5556**Self-Repair Loop:**57```58Execute -> Verify -> Pass? -> Done59 | No60 Diagnose -> Fix -> Re-verify (max 3 attempts)61```62- After 3 failed self-repair attempts: STOP and escalate to user63- Each repair attempt must be DIFFERENT from the previous64- Log each diagnosis and attempted fix6566### During implementation67- Every loop MUST have: max iterations, checkpoint logic, escalation path68- Never catch-and-swallow errors in loop bodies — always log with context69- Track iteration count in AUDIT entries70- Use SHARED_TASK_NOTES.md for cross-iteration context (see cross-iteration-bridge.md)7172### After implementation73- Verify the loop terminates under all test conditions74- Verify the circuit breaker opens and closes correctly75- Confirm escalation path works (simulate max-retries-exceeded)7677## Self-check before task completion78- [ ] Did I define explicit termination conditions for every loop?79- [ ] Did I set maximum iteration limits (no unbounded loops)?80- [ ] Did I implement checkpoint/state persistence between iterations?81- [ ] Did I verify the escalation path works when max retries are exceeded?
Run npx skillmds@latest add sairam0424/agent-loops in your terminal (requires Node.js), paste this page's agent-chat prompt into Claude, Cursor, or any MCP-connected agent, or download the SKILL.md file and copy it into your agent's skills directory.
Skill — Agent Loops It is listed under AI & ML on SkillMD.
This skill has not completed SkillMD's automated safety review yet. SkillMD never runs a skill's scripts for you; review the SKILL.md before installing.
This skill is tagged as working with Claude Code, Claude.ai, OpenAI Codex. SKILL.md is an open format, so most agents that read a skills directory can load it too.
Yes. Installing skills from SkillMD is free, and the skill stays under its author's original license.
sairam0424 (@sairam0424) published this skill. Their other Agent Skills are listed on their SkillMD profile.