GitHub - IsuruMaduranga/harness-engineering-101: Harness Engineering 101 — building AI agents from first principles. The LLM is the brain; the harness is the body.
Key Points
- 1"Harness Engineering 101" defines an LLM agent as a stateful harness—a program that manages and evolves the stateless JSON conversation array sent to an LLM API.
- 2The book breaks down agent development into first principles, using a modular approach to address common failures like context limits, tool execution, and loop synchronization.
- 3By developing a toy agent through sixteen progressive chapters, the author demonstrates how to build and maintain robust, specialized AI systems from the ground up.
"Harness Engineering 101" is a technical treatise that deconstructs the architecture of AI agents by defining them not as monolithic entities, but as "harnesses"—software programs designed to manage the stateless, episodic nature of Large Language Model (LLM) APIs. The core thesis posits that an LLM is merely a "brain" (a next-token prediction engine), while the "harness" functions as the "body," maintaining the state and context required to perform complex tasks.
Core Methodology: The Harness Pattern
The paper rejects the abstraction layers common in popular agent frameworks, instead advocating for a first-principles approach where an agent is simply a loop that maintains a JSON array representing the conversation history. Because LLM APIs are inherently stateless, the harness must manage the entire context window, tool-call execution, and state persistence across multiple turns.The development is structured into four pedagogical parts:
- The Wire: Establishes that interaction is fundamentally the maintenance of a JSON conversation buffer. It introduces tools as JSON-mapped function calls and defines the agent loop as the mechanism that iterates until the task is complete.
- Running Long: Addresses the entropy of state management. As the conversation history grows, the harness must account for budget constraints (context window limits), task branching (via subagents), and environmental drift (steering).
- The Ecosystem: Identifies existing agent frameworks as mere wrappers around the foundational "JSON-array-management" loop, emphasizing that the primary engineering challenge lies in externalizing capabilities through mechanisms like the Model Context Protocol (MCP).
- Trust and Domains: Examines the transition from raw agent loops to robust production systems through the implementation of reflex loops, guardrails, and Retrieval-Augmented Generation (RAG), framing RAG as a specific harness pattern for managing knowledge retrieval.
Technical Implementation
The author provides a "toy harness" in Python, demonstrating how to build an agent from scratch. The methodology relies on the following technical primitives:- Context Window Management: Since every request must contain the full history , the harness must implement truncation or summarization strategies once the total token count exceeds the model's budget :
- Tool Execution: The harness implements a pattern where the LLM outputs a JSON schema-compliant message, which the harness parses to execute local Python functions. The output of these functions is appended back into the JSON array as a
tool_resultmessage, closing the feedback loop. - Parallelism and Persistence: Advanced concepts include "Worktrees" and "Mode" management, where the harness enforces state machines (e.g., Plan Mode vs. Execution Mode) to prevent the model from drifting during multi-step coding tasks.
The paper concludes that "agents" are essentially a collection of patches applied to the primary interaction loop, with each patch representing a solution to a concrete failure (e.g., latency, cost, hallucination, or context loss). By developing the system from first principles, the author demonstrates that complexity in AI engineering is largely a result of managing the stateful requirements of real-world tasks within the constraints of stateless model endpoints.