Agent loops

Agent loops

Agent loops turn one-shot AI agent work into bounded cycles with a trigger, objective, verifier, stop condition, budget, and safe output.

Abstract network of bounded AI agent loops with evidence checkpoints

Answer-first definition

An agent loop is a reusable operating cycle around an AI agent. It defines what starts the work, what evidence the agent must check, what it may touch, how much budget it can spend, and what requires human approval.

The practical version is not open-ended autonomy. It is a leash with a verifier.

Agent loop anatomy

FieldQuestion
TriggerWhat starts the next run or turn?
ObjectiveWhat should be true when it is done?
StateWhere does progress survive outside the chat window?
VerifierWhat evidence proves success?
BudgetWhat hard cap prevents token bonfires?
Approval boundaryWhat must a human review first?
Details

Useful starting patterns

LoopCategoryDifficultyCadenceVerification
API Contract DriftEngineeringIntermediateAfter API changes or SDK releasesServer behavior, client types, examples, and docs agree on request/response contracts.
Architecture Rubric RefactorEngineeringAdvancedWhen architecture work has a defined scopeScoped module meets the written rubric, tests pass, and unresolved objections are explicit.
CI OptimizationEngineeringAdvancedMonthly or when CI is painfulCI p50/p95 improves against the same workflow without weakening tests or hiding failures.
Claude Code Repo ReadinessEngineeringBeginnerBefore major agent workRepo has agent instructions, documented commands, architecture notes, risk areas, and a docs/loops scaffold.
Cold Load TrimEngineeringAdvancedWhen first visit feels heavyInitial screen downloads fewer bytes while screenshots and behavior remain unchanged.
Fresh Clone OnboardingEngineeringIntermediateBefore onboardingA clean machine reaches the documented ready state using only the README.
Project Docs FreshnessEngineeringBeginnerNightly or after meaningful code changesChanged behavior, APIs, CLI commands, config, and workflows are reflected in docs. Docs checks pass.
Test Flake StabilizerEngineeringIntermediateWhen tests are inconsistentThe repaired test and full suite pass for the required consecutive-run streak.
Test and Logging CoverageEngineeringIntermediateWeekly or before releaseCritical flows have useful tests and structured logs for representative success and failure paths.
Adversarial PR ReviewEvaluationAdvancedFor meaningful PRsAn independent critic approves the unchanged version or only accepted findings remain.
Browser Quality StreakEvaluationIntermediateBefore releaseN realistic scenarios pass consecutively, and earlier failures have regression coverage.
Open Loop and Stale Memory CleanupKnowledgeBeginnerWeeklyNo current open loop is contradicted by recent daily or project notes.
Research to ArtifactKnowledgeIntermediateWhenever research must support a decisionThe artifact meets acceptance criteria, traces important claims to sources, and states uncertainty plainly.
Source Library Ingestion QAKnowledgeIntermediateAfter each source captureMetadata complete, transcript/article state honest, useful takeaways present, and qmd retrieval verified or refreshed.
Agent Handoff ContinuityOperationsIntermediateBefore pausing or switching agentsA new agent can state goal, current state, proof, blockers, and next action without reading the whole transcript.
Agent Toolchain Health CheckOperationsBeginnerWeekly or before a heavy agent runCritical tools authenticate, return sane output, and have a known fallback or blocker owner.
Living StoryOperationsIntermediateWeekly or per project windowEvery prior thread is carried forward, closed with evidence, or flagged stale/needs-review.
Production Error SweepOperationsAdvancedDaily or after incidentActionable errors are fixed with reproduction or tests, or explicitly classified as noise.