What is Loop Engineering and Why It Matters for Agentic AI
AI · Agentic AI · Harness · Loop Engineering
Insight Report: Loop Engineering vs. Harness Engineering for AI Agents
Executive Summary
Harness engineering is the discipline of designing the runtime scaffolding around an AI agent: tools, prompts, memory, context policies, sandboxes, hooks, permissions, observability, tests, evaluators, and recovery paths.
In short:
Agent = Model + Harness
A model alone outputs text. A harness turns it into an operational system that can read files, call tools, execute code, persist state, observe failures, retry, and verify work. Addy Osmani describes harness engineering as treating this scaffolding as a real artifact that gets tightened whenever the agent makes a mistake.
Loop engineering is a newer layer above that. Instead of repeatedly prompting an agent yourself, you design recurring, self-driving loops that prompt, schedule, delegate, verify, and improve agent work on your behalf. Osmani describes it as replacing yourself as the person who prompts the agent and designing the system that does it instead.
The simplest relationship is:
textModel ↓ Harness Engineering = gives the model tools, memory, rules, permissions, tests, and observability ↓ Loop Engineering = makes the harnessed agent run repeatedly, autonomously, and improve over time
Harness engineering is the foundation; loop engineering is the operating model. You usually should not do serious loop engineering until you have a solid harness, because loops amplify whatever is inside them: good harnesses become productive automation, bad harnesses become expensive chaos.
1. What Is Harness Engineering?
Harness engineering means building the execution environment and control system around an LLM or agent so it can perform useful work reliably.
A raw LLM cannot persist state, execute code, access real-time data, install packages, inspect a repo, open a PR, or enforce safety rules by itself. LangChain’s harness explanation frames these as harness-level features: durable state, code execution, real-time knowledge, and environment setup.
A typical agent harness includes:
| Harness Component | Purpose |
|---|---|
| System prompts / AGENTS.md / CLAUDE.md / skill files | Encode project-specific rules and reusable procedures |
| Tool layer | Let the agent read files, search, run commands, call APIs, use browsers, query databases |
| Context policy | Decide what information enters the model context |
| Memory | Persist knowledge across sessions |
| Sandbox | Let the agent act safely |
| Hooks | Enforce rules before or after actions |
| Test runners / evaluators | Verify outputs |
| Observability | Record traces, costs, failures, latency, tool calls |
| Permissions | Prevent destructive or unauthorized actions |
| Recovery logic | Retry, rollback, escalate to humans |
Osmani’s harness article gives concrete examples: if the agent runs destructive commands, add a blocking hook; if it gets lost, split it into planner and executor; if it finishes broken code, wire typecheck failures back into the loop.
Harness Engineering Architecture
flowchart TD U[User / Task] --> H[Agent Harness] H --> C[Context Policy] H --> M[Memory / State] H --> T[Tools / MCP / APIs] H --> S[Sandbox / Permissions] H --> O[Observability / Traces] H --> V[Verification / Tests] H --> K[Hooks / Middleware] C --> LLM[LLM / Foundation Model] M --> LLM LLM --> A[Agent Action] A --> T A --> S A --> V V -->|pass| R[Result] V -->|fail| H O --> H
The harness is not just prompting. It is the full runtime substrate.
2. What Is Loop Engineering?
Loop engineering means designing systems that repeatedly run agents toward a goal, with feedback, verification, scheduling, delegation, and memory.
At the basic level, every agent already has a loop:
Think → Act → Observe → Think → Act → Observe → Done
Modern loop engineering goes beyond a single ReAct loop. It stacks loops:
- Agent loop: model calls tools until task is complete.
- Verification loop: output is checked, then retried if it fails.
- Event-driven loop: schedules, webhooks, tickets, or messages trigger new runs.
- Improvement loop: traces and failures are mined to improve the harness.
LangChain’s Art of Loop Engineering describes this stack: core agent loop, verification loop, event-driven loop, and a hill-climbing loop that improves the agent system itself.
Addy Osmani’s 2026 loop engineering article describes the loop as sitting one floor above the harness: the harness runs on a timer, spawns helpers, and feeds itself.
Loop Engineering Stack
flowchart TD E[External Trigger<br/>cron / webhook / issue / Slack / CI failure] --> L1[Loop 1: Agent Loop] L1 --> H[Harnessed Agent] H --> W[Work Product<br/>code / report / PR / decision] W --> L2[Loop 2: Verification Loop] L2 -->|fail with feedback| H L2 -->|pass| D[Deliver / Commit / Notify] D --> L3[Loop 3: Event-Driven Ops] L3 --> Q[Queue / Triage / Backlog] Q --> L1 L2 --> L4[Loop 4: Improvement Loop] L4 --> I[Analyze traces, failures, costs] I --> P[Improve prompts, tools, tests, skills, hooks] P --> H
Loop engineering is not merely running an agent in a while loop. It is about designing the feedback topology around agents.
3. Key Differences
| Dimension | Harness Engineering | Loop Engineering |
|---|---|---|
| Main question | What environment and guardrails does the agent need to succeed? | How should agents repeatedly work, verify, delegate, and improve without manual prompting each step? |
| Layer | Runtime substrate | Operating cycle |
| Core artifact | Tools, prompts, memory, permissions, hooks, tests, traces | Schedules, goal loops, verification cycles, task queues, sub-agent workflows, improvement loops |
| Primary goal | Make one agent run reliably | Make repeated agent work scalable |
| Failure mode | Agent cannot act, forgets, violates rules, produces unverifiable output | Agent loops forever, burns tokens, compounds mistakes, creates noisy automation |
| Analogy | Build the factory floor, machines, safety rails, sensors | Design the production line and feedback cycles |
| Best first investment | For almost every serious agent project | After harness basics are stable |
A useful mental model:
textHarness engineering = capability + safety + observability Loop engineering = autonomy + recurrence + delegation + improvement
4. Why These Terms Matter Now
The industry is moving from chat with an AI to managing AI workers. Business Insider reported in June 2026 that practitioners around Claude Code, Codex, and agentic coding are increasingly talking about loops instead of hand-written prompts, with examples such as goal-seeking agents, scheduled repo maintenance, and maker/checker agent splits.
At the same time, harness engineering has become a serious discipline because model quality alone does not determine agent performance. Osmani argues that a decent model with a great harness beats a great model with a bad harness, and describes the harness as prompts, tools, context policies, hooks, sandboxes, subagents, feedback loops, and recovery paths around the model.
So the shift is:
- 2023: Prompt engineering
- 2024-2025: Context engineering + tool use
- 2025-2026: Harness engineering
- 2026+: Loop engineering / loopcraft / agent operations
Prompting is not dead; it is now one part of a larger system.
5. Concrete Example: Coding Agent
Harness Engineering Example
You want a coding agent to modify a TypeScript repo.
You build a harness with:
- Repo access
- Git worktree isolation
- Bash execution
- TypeScript compiler
- Unit test runner
- Lint command
- File-edit tool
- Security policy: no force push, no destructive rm
- AGENTS.md with coding standards
- Trace logging
- Diff reviewer
- Human approval before merge
Now the agent can work safely and produce verifiable changes.
Loop Engineering Example
Now you design loops on top:
- Scan open GitHub issues each morning.
- Classify easy bug fixes.
- Spawn one agent per issue in separate worktrees.
- Run tests and lint.
- Ask a reviewer sub-agent to inspect the diff.
- Open PRs only if checks pass.
- Summarize results to Slack.
- Save failures into a harness-improvements backlog.
This is no longer just an agent. It is an autonomous workflow.
6. Pros and Cons
Harness Engineering: Pros
- Reliability improves at the root. Every mistake can become a harness improvement: a new rule, hook, evaluator, test, or permission boundary. Osmani calls this the ratchet.
- Lower risk than full autonomy. You can improve the environment without fully unattended runs.
- Better observability. A good harness provides traces, logs, cost data, tool-call history, and failure attribution.
- More portable than prompts. Harness assets can outlive any single model.
- Essential for production. If you cannot observe, constrain, and verify an agent, you probably should not automate it.
Harness Engineering: Cons
- Upfront engineering cost.
- Risk of overfitting to one model, repo, or workflow.
- Hidden complexity as the harness grows.
- Ongoing maintenance burden.
Loop Engineering: Pros
- Scales human intent by replacing repetitive manual prompting.
- Fits recurring work: triage, monitoring, regression checks, docs, CI analysis, and review.
- Enables maker/checker patterns.
- Enables autonomous improvement loops.
- Turns agents into operations connected to real triggers.
Loop Engineering: Cons
- Token and cost explosion.
- Error amplification if the underlying harness is weak.
- Autonomy risk for production-touching actions.
- Loop drift and metric over-optimization.
- Harder debugging due to timing, memory, verification, and tool side effects.
7. Side-by-Side Decision Matrix
| Use Case | Prefer Harness Engineering | Prefer Loop Engineering |
|---|---|---|
| First version of an agent framework | Strong yes | Not yet |
| Coding assistant for one repo | Strong yes | Later |
| Automated daily issue triage | Yes | Strong yes |
| One-off research task | Medium | Low |
| CI failure diagnosis | Yes | Strong yes |
| Autonomous PR creation | Strong yes | Strong yes |
| Production customer-support agent | Strong yes | Medium/strong, with strict controls |
| Internal knowledge assistant | Strong yes | Medium |
| Agent evaluation platform | Strong yes | Strong yes |
| Long-running multi-agent workflow | Strong yes | Strong yes |
| Highly regulated workflow | Strong yes | Only with human approval gates |
Rule of thumb:
- If the problem is agent unreliability, improve the harness.
- If the problem is manually driving repeated work, design a loop.
8. Maturity Ladder
Level 0: Prompt-Only
Human → prompt → model → answer
Good for exploration; weak for repeatability.
Level 1: Context Engineering
Human → curated context → model → answer
You improve input quality with examples, docs, retrieval, and schemas.
Level 2: Harness Engineering
Human → harnessed agent → tools/tests/memory/observability → verified output
The agent can act and self-check in a controlled environment.
Level 3: Loop Engineering
Trigger → harnessed agent loop → verification → delivery → trace analysis → next run
The agent becomes part of an operational system.
Level 4: Self-Improving Agent System
Loops generate traces → traces improve harness → improved harness improves future loops.
Powerful but risky. Requires strong review, evals, rollback, and cost controls.
9. Practical Architecture for a TypeScript LLM-Agent Framework
Given your interest in TypeScript hooks and non-invasive monitoring for LLM agents, this architecture is a practical baseline:
textCore agent runtime ↓ Harness layer - tool registry - context manager - memory adapter - permission engine - hook/middleware system - trace collector - evaluator interface - sandbox adapter ↓ Loop layer - scheduler - event triggers - task queue - retry policy - verifier loop - sub-agent orchestration - human approval gates - improvement backlog
10. Best Practices
For Harness Engineering
- Start from failures, not abstractions.
- Make success silent and failure verbose.
- Use deterministic checks wherever possible.
- Separate action from permission.
- Trace everything.
For Loop Engineering
- Never loop without a stop condition.
- Separate maker and checker.
- Prefer narrow recurring loops.
- Use work isolation.
- Require human approval for irreversible actions.
- Track loop economics.
11. Main Risks and Mitigations
| Risk | More Related To | Mitigation |
|---|---|---|
| Agent forgets project rules | Harness | Persistent memory, skill files, context policy |
| Agent runs unsafe command | Harness | Permission engine, command denylist, sandbox |
| Agent produces broken output | Harness + Loop | Tests, verifier loop, reviewer agent |
| Agent loops forever | Loop | Max iterations, timeout, budget cap |
| Costs explode | Loop | Token budget, cheaper model for triage, deterministic checks |
| Bad output gets shipped repeatedly | Loop | Human approval, staged rollout, regression tests |
| Debugging is impossible | Harness | Structured traces and run replay |
| Multi-agent conflicts | Loop | Task ownership, isolated workspaces, merge protocol |
| Evaluation becomes subjective | Harness | Rubrics plus deterministic assertions |
| System becomes over-engineered | Both | Add harness features only after real failures |
12. Strategic Conclusion
Harness engineering and loop engineering are not competitors. They are two layers of the same agent-systems discipline.
- Prompt engineering asks: How do I ask the model better?
- Context engineering asks: What information should the model see?
- Harness engineering asks: What system around the model lets it act safely and reliably?
- Loop engineering asks: How do I make that reliable agent operate repeatedly, autonomously, and improve?
For most teams, the right sequence is:
- Build a minimal agent.
- Add harness features when real failures appear.
- Add observability and verification.
- Only then add recurring loops.
- Use traces from loops to improve the harness.
The biggest insight: loop engineering without harness engineering is premature automation. Harness engineering without loop engineering is a powerful tool that still depends on human steering. The best systems combine both: a strong harness for reliability, and carefully bounded loops for scale.