Agent Harness Loop Contract
The harness is the agent. The model is a coprocessor. This lesson freezes the loop contract you can wire any model into. Specify an agent harness loop as a deterministic state machine with explicit transitions. Implement ten lifecycle hook topics that operators wire policy, telemetry, and guardrails into. Define two pull points where the loop yields control back to the caller and resumes on a fresh input. Enforce per-session budgets (turns, tool calls, wall-clock) without leaking partial state on exceeding. Emit a typed stream of eleven event types so downstream UIs and tracers can subscribe without inspecting the loop directly. A coding agent that runs unattended for forty turns is not a chat loop. It is a state machine whose nodes the operator can intercept and whose edges the operator can audit. Once you write the contract down, swapping models, tools, or policies stops being a refactor. It becomes a registration call. This lesson builds that contract. We name six states, ten hook topics, two pull points, eleven event types, and a budget envelope. Everything else in the harness (tool registry, JSON-RPC transport, dispatcher, planner) plugs into this shape. The loop has six states. Five are active. One is terminal. IDLE is the only legal entry point. DONE is the only legal exit. AWAITINGTOOL is the only state that yields…
Agent Harness Loop Contract: The harness is the agent. The model is a coprocessor. This lesson freezes the loop contract you can wire any model into.
This free lesson is part of the AI Engineering from Scratch curriculum. Read the full explanation, run the lesson code, and verify the result in the interactive reader or from the repository source.
Browse the complete course catalog or open this lesson on GitHub.