Harness Engineering 101: Building Resilient Autonomous Agent Runtimes from First Principles
A new open-source guide demystifies AI agents by modeling the LLM as a stateless brain and the harness as the state-preserving body. It unpacks the synchronous loop, MCP integrations, and worktree isolation across 16 chapters.

Why it matters
Study this architecture to stop relying on bloated opaque agent frameworks and build custom, deterministic runtime loops with isolated Git worktrees and strict rate limits.
TL;DR
- 01LLMs are strictly stateless; all persistent agency stems from harness-level conversation array management.
- 02Frameworks are fundamentally wrappers handling token overflow, retries, and tool execution failures.
- 03Git worktrees provide clean filesystem isolation when executing multiple coding sub-agents in parallel.
Key facts
- Code size
- ~300 lines of Python for toy harness
- Book chapters
- 16 progressive chapters plus 4 appendices
- Code license
- MIT License
- Text license
- CC BY-NC-ND 4.0
The Core Agent Mental Model
LLM APIs are completely stateless: each turn requires submitting the entire conversation history as a JSON array. An agent harness is simply the state machine that constructs, prunes, and safeguards that array. Complex agent frameworks represent collections of bug fixes wrapped around this primitive turn loop.
Progressive Architectural Patterns
The guide spans 16 structured chapters with working Python implementations:
- Part I & II (The Loop Under Pressure): Handling conversational state decay, token eviction strategies, and reconciling asynchronous tool execution with synchronous model completions.
- Part III (Ecosystem Extensions): Interfacing with Model Context Protocol (MCP), deferred skill loading, and harness-enforced operational hooks.
- Appendices (Production Plumbing): Model routing across price tiers, state isolation using Git worktrees, plan-vs-execution mode enforcement, and streaming wire protocols.
Local Setup and Rendering
The prose is released under CC BY-NC-ND 4.0, while the harness code is MIT licensed.
Try it in 2 minutes
# Clone and preview the interactive guide locally
git clone https://github.com/IsuruMaduranga/harness-engineering-101.git
cd harness-engineering-101
cargo install mdbook mdbook-mermaid
mdbook serve --openbash
✓ When to use
- Use when debugging subtle state-loss bugs in agent loops that standard high-level frameworks obfuscate.
- Use to build lightweight, zero-dependency coding agents tailored to your personal developer workflow.
✕ When NOT to use
- Do not use when you only need a quick one-off CLI script that performs a single direct LLM completion call.
- Do not adopt for complex enterprise setups if your team already has hardened, compliant production orchestrators.
What to do today
- Clone the repository to inspect the progressive stage-by-stage Python agent implementations.
- Refactor custom agent loops to separate tool-calling logic from context pruning routines.
- Isolate destructive parallel coding scripts into temporary Git worktrees.
What the community says
“Can’t recommend making your own harness enough. Even a trivial toy harness will clarify a lot of concepts that I see people confuse all the time (especially here on HN).”
“I gave myself three days to see if I could make a harness that was complete enough to work on my own projects. It was usable in less than a day. I love using it, because I know exactly what its boundaries are.”