Skip to main content

Loop Engineering — from skills to autonomous feedback loops

"A skill answers a question. A loop closes it."

Harness Engineering constrains what an agent can do. Loop Engineering defines what an agent keeps doing — autonomously, cyclically, and with explicit feedback edges that turn individual skills into self-correcting systems.

Relationship to Harness Engineering​

Loop Engineering does not replace the harness — it builds on top of it. It is the outermost layer in a progression that contains all prior layers:

Prompt Engineering (2022–2024)
└─ Context Engineering (2025)
└─ Harness Engineering (early 2026)
└─ Loop Engineering (2026)

Each layer wraps and contains the ones before it. You still write prompts, you still curate context, you still build a harness. Loop engineering is the part where all of that gets put into motion and given a rhythm — designing a cycle you trust enough to walk away from.

LayerResponsibilityArtifact
PromptWording of individual instructionsPrompts within SKILL.md
ContextEverything the model sees at inference time.omao/ state, ontology, retrieved docs
HarnessSafety of individual tool callspolicies, enforce.py, PreToolUse hooks
LoopOrchestration of skill sequences into autonomous cyclesloops: section in *.oma.yaml

The Triple Feedback Loop, realized​

The ontology-engineering document defines three nested loops conceptually. Loop Engineering makes them executable:

LoopCadenceOMA implementationSkills involved
Quality Loop1h + event-drivenloops.quality-loopcontinuous-eval, self-improving-loop, autopilot-deploy
Incident Loopevent-drivenloops.incident-loopanomaly-detection, root-cause-analysis, automated-remediation, slo-management
Cost Loop6h + event-drivenloops.cost-loopcost-governance, anomaly-detection, predictive-scaling, slo-management

Anatomy of a loop​

Every loop follows the same structural pattern:

┌─────────────────────────────────────────────────────────┐
│ LOOP DEFINITION │
├──────────┬──────────────────────────────────────────────┤
│ mode │ continuous (monitoring) or event-driven (goal)│
│ cadence │ When does the loop tick? (cron/duration) │
│ trigger │ What events start it outside cadence? │
│ steps │ Ordered skill sequence with dependencies │
│ feedback │ Explicit edges forming the cycle │
│ gate │ Where does a human approve? (severity-based) │
│ exit │ When is the loop done? (verifier.passes) │
│ budget │ How much can it spend? (tokens/cost/time) │
│ breaker │ When does the loop halt itself? │
│ escalate │ Where does it hand off when stuck? │
└──────────┴──────────────────────────────────────────────┘

Steps follow Discovery → Triage → Modify → Verify​

Each loop's steps map to this 4-phase pattern (based on the "4단계 순환 휠"):

  1. Discovery — Automation wakes up, checks state files, collects signals
  2. Triage — Analyzes signals, determines if action is needed. If no actionable items → skip remaining, idle until next tick
  3. Modification — Executes the change in an isolated worktree (sub-agent writes code, never in main)
  4. Verification — Sub-agent reviews, runs checks, creates PR if passing

The feedback edge (verify -> discover) closes the loop: after verification, the next discovery cycle begins.

The critical design principle: "이 단계들 중 어느 것에도 직접 프롬프트를 던지지 않았다." (You designed this once. You don't manually prompt any of these stages.)

Termination model — layered exits​

Loop engineering's hardest problem is knowing when to stop. OMA implements layered termination with multiple independent exit paths:

# Pseudocode equivalent of OMA's termination model
state = init_state(goal)

for iteration in range(max_iterations): # hard cap
result = run_iteration(state, steps)

if result.skip_remaining: # Triage said "nothing to do"
sleep_until_next_cadence()
continue

state = update(state, result)

if exit_when_satisfied(state): # verifier.passes
return success(state)

if no_progress(state): # same error N times
return escalate_to_human(state)

if budget_exhausted(state): # tokens/cost/time
return escalate_to_human(state)

return escalate_to_human(state) # max_iterations exceeded

The 5 exit paths​

Exit pathTriggerBehavior
Normal successexit_when condition satisfiedLoop returns to idle (continuous) or completes (event-driven)
Early skipskip_remaining_if on Triage stepThis iteration ends early, loop sleeps until next tick — NOT a termination
No progressSame state repeated N timesEscalation to human with trace
Budget exhaustedToken/cost/time limit hitEscalation with partial progress
Max iterationsHard cap reachedEscalation — prevents infinite loops
Circuit breakerConsecutive failuresLoop halted, cooldown period, then retry

Continuous vs Event-driven​

Aspectmode: continuousmode: event-driven
StartsOn cadence tick (e.g. every 1h)On trigger event (alert, signal)
"Exit" meansSkip this iteration, sleep until next tickLoop run is complete, go idle
exit_whenPauses until next cadenceFully terminates the run
Typical useQuality monitoring, cost monitoringIncident response
Never truly stopsCorrect — it's a monitoring daemonCorrect — it's a task runner

skip_remaining_if — the Triage gate​

This is the most common "exit" in practice. Most iterations of a continuous loop find nothing actionable:

steps:
- id: discover
skill_ref: continuous-eval
skip_remaining_if: "no_regression_detected" # ← 90% of iterations end here
- id: triage
skill_ref: self-improving-loop
depends_on: [discover]
skip_remaining_if: "no_actionable_proposal" # ← most of the rest end here
- id: modify
...

This means the full Modify → Verify cycle only runs when there's genuinely something to fix. The loop stays cheap and fast in the common case.

Severity-based gating​

The Modify step uses a severity-based gate to balance autonomy with safety:

gate:
type: severity-based
auto_approve_below: medium # low/medium auto-approve
timeout_minutes: 30 # wait for human if high/critical
notify: ["slack:#approvals"]
SeverityExample actionGate behavior
lowAdd index hint to slow queryAuto-approve
mediumRestart unhealthy podAuto-approve (if auto_approve_below: medium)
highScale down production fleetPause, notify, wait for human
criticalModify IAM policy, deploy to prodPause, escalate, require explicit approval

This preserves OMA's Tier-0 approval model: humans retain authority over high-impact decisions while low-risk operational actions flow automatically.

Isolation — worktrees for safe modification​

The Modification step runs in an isolated git worktree, not in the main working directory. This prevents:

  • Collisions between parallel loops modifying the same repo
  • Half-finished changes polluting the main branch
  • Accidental side effects from failed modifications
steps:
- id: modify
skill_ref: autopilot-deploy
isolation: worktree # creates WORKTREE: ISOLATED-PATCH-{id}
gate:
type: severity-based
auto_approve_below: low

The worktree is created as ISOLATED-PATCH-{loop-id}-{iteration}, changes are committed there, and only after Verification passes does a PR get created from that branch. If Verification fails, the worktree is discarded — no cleanup needed in main.

Circuit breaker​

Every loop has a circuit breaker to prevent runaway execution:

circuit_breaker:
consecutive_failures: 3 # open after 3 failures
cooldown_minutes: 120 # stay open for 2 hours
notify: ["slack:#alerts"] # alert the team

This is the harness pattern "Circuit Breaker" (previously on the roadmap) realized through loop-level enforcement rather than per-call enforcement.

DSL syntax​

Loops are declared in the loops: section of a v2 *.oma.yaml file:

version: 2
plugin: agenticops

loops:
quality-loop:
description: "Continuous quality improvement cycle"
mode: continuous
cadence: "1h"
trigger_on:
- slo_breach: "faithfulness < 0.82"
- skill_signal: "continuous-eval.regression"
exit_when:
- manual: true
max_iterations: 20
budget:
max_cost_usd: 10.0
max_wall_clock_minutes: 90
no_progress_detection:
repeated_state_count: 3
action: escalate
steps:
- id: discover
skill_ref: continuous-eval
skip_remaining_if: "no_regression_detected"
- id: triage
skill_ref: self-improving-loop
depends_on: [discover]
skip_remaining_if: "no_actionable_proposal"
- id: modify
skill_ref: autopilot-deploy
depends_on: [triage]
isolation: worktree
gate:
type: severity-based
auto_approve_below: low
- id: verify
skill_ref: continuous-eval
depends_on: [modify]
feedback:
- "verify -> discover"
circuit_breaker:
consecutive_failures: 3
cooldown_minutes: 120
escalation:
notify: ["slack:#ops-alerts"]
create_issue: true

Compiler validation​

The compiler validates loops at build time:

  • Every skill_ref must resolve to a skill directory under the plugin's skills/
  • Every depends_on reference must name a step id in the same loop
  • Every feedback edge must reference valid step ids in the format "source -> target"
  • At least one feedback edge must exist (otherwise it's a workflow, not a loop)
  • Steps must form a valid DAG (ignoring feedback edges) — no forward cycles within a single iteration

Loop state​

Each loop maintains state in .omao/state/loops/:

.omao/state/loops/
├── quality-loop.state.json
├── incident-loop.state.json
└── cost-loop.state.json

State schema (per loop):

{
"loop_id": "quality-loop",
"mode": "continuous",
"status": "running",
"current_step": "triage",
"iteration": 47,
"last_started": "2026-07-26T10:00:00Z",
"last_completed": "2026-07-26T09:12:34Z",
"consecutive_failures": 0,
"circuit_breaker": "closed",
"pending_approval": null,
"budget_consumed": {
"tokens": 142000,
"cost_usd": 3.42,
"wall_clock_minutes": 12
},
"no_progress": {
"last_state_hash": "a3f2c1",
"repeat_count": 0
},
"history": [
{
"iteration": 46,
"started": "2026-07-26T09:00:00Z",
"completed": "2026-07-26T09:00:34Z",
"result": "skipped",
"exit_reason": "skip_remaining_if: no_regression_detected",
"steps_executed": ["discover"],
"steps_skipped": ["triage", "modify", "verify"]
},
{
"iteration": 45,
"started": "2026-07-26T08:00:00Z",
"completed": "2026-07-26T08:12:34Z",
"result": "success",
"exit_reason": "iteration_complete",
"steps_executed": ["discover", "triage", "modify", "verify"],
"steps_skipped": []
}
]
}

Loop Controller runtime — decision deferred​

The Loop Controller is responsible for executing loops at the defined cadence, listening for event triggers, managing state transitions, and enforcing circuit breakers. The runtime implementation is intentionally deferred — the loop definitions (schema, DSL, state) are designed to be runtime-agnostic.

Options under consideration​

OptionDescriptionProsCons
EventBridge + Step FunctionsAWS-native orchestrationBuilt-in scheduling, event routing, state management, retry logicAWS dependency, cost, IAM complexity
GitHub Actions (scheduled)CI/CD-based executionFree for public repos, easy setup, git-nativeLimited event routing, cold start, 5-min minimum schedule
Local cron + hook.omao/ state file + harness hooks check periodicallyWorks offline, zero infra, good for dev/demoNot production-grade, single-machine
Kubernetes CronJob + Argo WorkflowsK8s-native orchestrationAlready have EKS infra, powerful DAG engineHeavy for simple loops, cluster dependency

Selection criteria (for future decision)​

  • Deployment target: Personal tool → local cron. Team platform → Step Functions. OSS sample → GitHub Actions.
  • Event richness: If loops need sub-minute reaction to alerts → EventBridge. If hourly is fine → cron/GHA.
  • State durability: Production → DynamoDB/S3-backed state. Dev → .omao/state/ files.
  • Cost: GitHub Actions is free for public repos. Step Functions bills per state transition.

The key design constraint: the loop definition in *.oma.yaml must not change regardless of which runtime is chosen. The controller reads the compiled loop spec and executes it — the spec is the contract.

Skill interface contract​

Skills participating in a loop declare their inputs and outputs via frontmatter:

# In SKILL.md frontmatter
loop-interface:
accepts-from:
- continuous-eval.report
- incident-response.rca
emits-to:
- autopilot-deploy.artifact
- self-improving-loop.proposal
emits-signals:
- continuous-eval.regression
- cost-governance.anomaly

This enables the compiler to validate that loop steps are properly connected: a step's accepts-from must include something emitted by at least one of its depends_on predecessors.

Migration from standalone skills​

Existing skills continue to work as standalone invocations. Loop membership is additive — a skill can participate in a loop AND be invoked independently.

The migration path:

  1. Add loop-interface frontmatter to skills (non-breaking)
  2. Define loops in *.oma.yaml referencing existing skills (non-breaking)
  3. Deploy a Loop Controller runtime (new infra)
  4. Shift from manual invocation to loop-driven execution (operational change)

Steps 1–2 are what this PR delivers. Steps 3–4 are future work.