Skip to content

Foundations

The Four Layers

Prompt → context → harness → loop: each layer wraps the one before it and catches a failure the inner layers simply cannot see.

Prompt → context → harness → loop: each layer wraps the one before it and catches a failure the inner layers simply cannot see.

The hook

Your agent keeps botching the same refactor. So you sharpen the prompt — no change. You paste in more files — now it's worse. The real fix turns out to be a permission setting (harness) plus a stopping condition (loop). You were debugging on the wrong layer the whole time. This page is the map that ends that particular kind of afternoon.

The stack (plain English)

  1. Prompt — the words you send. Fails by ambiguity: the task can be read two ways.
  2. Context — everything the model sees in one turn: files, history, rules. Fails by starvation or drowning: the key fact is missing, or it's buried under noise.
  3. Harness — the code around the model: tool execution, permissions, hooks, error handling. The inner loop lives here. Fails by capability: the agent can't — or, worse, can — do something it shouldn't.
  4. Loop — the outer cycle: what the system works on, when it starts, how it knows it's done. Fails by management: wrong task, wrong time, no real stop.
Diagram

The move that saves you: name the failure signature before you fix. When a loop misbehaves, don't reach for the layer you happen to be typing in — ask which layer's signature is this? (ambiguity, starvation/drowning, capability, or management) and fix there.

Where you configure each layer

# Claude Code — live docs: https://docs.claude.com/en/docs/claude-code
# 1 Prompt:   what you type (or the /loop prompt)
# 2 Context:  CLAUDE.md, @file mentions, /context
# 3 Harness:  /permissions, hooks in .claude/settings.json
# 4 Loop:     /loop, Cron tools, skills like this repo's LOOP.md discipline
# OpenCode — live docs: https://opencode.ai/docs
# 1 Prompt:   the message (or the scripted run prompt)
# 2 Context:  AGENTS.md, attached files
# 3 Harness:  opencode.json permissions & mcp
# 4 Loop:     cron / GitHub Actions driving `opencode run`, capped `for` loops

[!NOTE] Going deeper: the four layers come from the Panaversity backbone (S1); Step 02 (Day 2) spends a whole lesson here, including how the layers line up with the LangChain 4-loop stack (S6).

Check yourself

Q: A nightly loop cheerfully "fixed" the same test five nights running; each morning the fix gets reverted in review. Which layer is failing?

Answer

Layer 4, the loop. Prompt, context, and harness all did their jobs — work got done every night. What's missing is management: a spine that remembers the rejection, and a no-progress stop (or an escalation) after repeated reverts. No amount of prompt wording fixes a memory problem.

Try With AI

Take the last time an agent genuinely disappointed you, and ask it:

"Here's what I asked, what you saw, what you could do, and what happened: [paste]. Which of the four layers — prompt, context, harness, loop — most likely caused the gap, and what's the smallest fix at that layer?"

Then grade its self-diagnosis against the failure signatures above.

When it goes wrong

SymptomLayerFix
Two readings of the task, agent picked the wrong onePromptRestate with one checkable meaning
Agent "forgot" a critical constraint mid-runContextMove it to the rules file; shrink the noise
Agent edited a file it should never have touchedHarnessNarrow write permissions; add a hook
Right work, wrong task — or no idea when to stopLoopDeclare the six parts; write the three stops

Glossary terms used on this page: harness, loop, inner loop, spine — see glossary.md.

Sources: the four-layer stack comes from Panaversity's Loop Engineering: A Crash Course (S1), and the mapping to stacked loops from Sydney Runkle's The Art of Loop Engineering (S6). Full attribution: ../../resources/sources.md.