Why AI Agents Crash and How Harness & Loop Engineering Make Them Run Autonomously
The article explains why AI agents frequently fail in production, identifies four core runtime failure modes, and shows how a two‑layer architecture—Harness for stability and Loop engineering for autonomous scheduling—combined with concrete configurations, memory tiering, and verification loops can keep agents running reliably.
Key concepts
Framework provides standardized building blocks such as tool interfaces, prompt templates, orchestration primitives and routing. Examples: LangChain, CrewAI, AutoGen.
Harness assembles those blocks into a long‑running, self‑correcting system with state persistence, sandboxed tool execution, layered memory and checkpoint recovery. It solves the "how to avoid crashes" problem.
Loop runs on top of the Harness and automates discovery, dispatch, verification and state recording of work. It solves the "how to make the system run by itself" problem.
Four production failure modes
Context overflow – long conversations cause the model to forget earlier instructions.
Tool‑call avalanche – a single tool error propagates to subsequent calls.
Sub‑agent loss of control – parallel agents operate without awareness of each other.
State loss – process crashes erase intermediate results.
These failures are unrelated to model intelligence and require a robust outer layer.
Configuration example (YAML)
# ~/.hermes/config.yaml (core snippet)
model:
default: gpt-5.5
provider: openai
agent:
max_turns: 90 # limit tool calls per turn, prevents avalanche
gateway_timeout: 1800 # prevent indefinite hanging
api_max_retries: 3 # auto‑retry on tool failure
tool_use_enforcement: auto # strategy when tool fails max_turnscaps context growth, api_max_retries recovers from tool errors, gateway_timeout avoids endless hangs, and the Harness enforces sandboxed execution.
Harness core responsibilities
State persistence and checkpointing.
Sandboxed tool execution.
Layered memory (short‑term, structured, core insights).
Budget calculation before each model call to prevent context overflow.
Quote: "The model is just the middle function; the surrounding layer is what makes the agent reliable. Switching frameworks only changes the outer layer's implementation style. Changing the model only swaps that middle function."
Tiered memory design
# memory_tiered.py core structure
# L1 session summary: short‑lived, fast decay (avg_decay_score: 0.83)
# L2 structured knowledge: stable facts, 143 items, 15 categories (avg_decay_score: 0.278)
# L3 core insights: long‑term immutable (14 items)The system loads only the needed skills on demand (3‑5 active items out of 78 total), keeping token cost proportional to actual usage. A Context Engine decides each round which memory tier to read, performs pre‑model compression and then passes the result to the model.
Verification loop
Because agents cannot judge the quality of their own output, human‑defined acceptance criteria (e.g., concrete title benefits, no filler content) are encoded so the system can self‑check, log failures and trigger remediation.
Loop engineering
A minimal Loop consists of five steps: Goal → Plan → Execute → Check → Fix . The Loop replaces manual prompting with autonomous scheduling.
Example: daily memory‑distillation Loop
Trigger: cron schedule at 02:00.
Isolation: separate process and context.
Skill: memory_tiered.py script.
Connector: SQLite read/write + Obsidian markdown write.
Sub‑agents: distillation, compression, cleanup scripts.
External memory: three‑tier SQLite + markdown files.
Exit condition: script exit code with logging.
Another Loop monitors system health every five minutes, checking gateway liveness, auto‑restarting if needed, verifying WebSocket connections and generating health reports. This implements a Plan‑Execute‑Verify pattern.
Building a minimal Loop
Create AGENTS.md (the Harness constitution) with project rules, tool usage and boundaries.
Create PROGRESS.md (state file) to record attempts, results, open items and next steps.
Write a simple Loop script, e.g., a cron that scans a notes folder and lists files not updated for 30 days.
Add verification: filter the list to only those notes containing unfinished TODOs.
This yields a complete Plan‑Execute‑Verify Loop.
Pitfalls and checklist
Define explicit exit conditions to avoid endless loops.
Separate maker and checker agents.
Enforce strict context management with external files.
Monitor cost; use hard limits like max_turns: 90.
Start with small, narrow tasks before scaling.
Keep a human in the loop for critical decisions.
Common failure modes include vague goals (token explosion), missing exit conditions (infinite loops), weak verification (low‑quality output), lack of parallel isolation (state corruption) and over‑looping (removing creative human input).
Evolution of AI engineering (2023‑2026)
2023: focus on prompt writing.
2024: focus on agent orchestration.
2025: add a runtime layer (Harness).
2026: automate the runtime itself (Loop Engineering).
Frameworks such as LangChain explicitly separate the three layers: LangGraph is the graph runtime (Framework), create_agent is a minimal Harness, and DeepAgents provides a full‑feature Harness. Claude Code’s /loop and /goal, as well as Codex Automations + Triage Inbox, exemplify the Loop layer.
References
LangChain, CrewAI, AutoGen – framework examples.
LangGraph – graph runtime.
Claude Code (Boris Cherny) – Loop implementation.
Addy Osmani – definition of Loop Engineering.
Geoffrey Huntley – Ralph Loops concept.
Cobus Greyling – Loop Engineering Playbook.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
