The Agent Harness
3 minute read
Builds on Agentic AI. The model is the engine; the harness is everything around it that turns a single model call into a working agent. This page is how one is built.
What the harness owns
flowchart LR
subgraph Harness
Loop[Agent loop]
CtxM[Context manager]
ToolR[Tool executor]
Mem[Memory]
Guard[Guardrails / permissions]
end
Harness --> Model[Model API]
Harness --> Tools[Tools]The loop
At its core the harness runs one loop until the task is done:
flowchart TD
In[User goal] --> Ctx[Assemble context]
Ctx --> M[Call model]
M --> Dec{Tool call?}
Dec -->|no| Out[Return answer]
Dec -->|yes| G[Check guardrails / permissions]
G --> Ex[Execute tool]
Ex --> Up[Append result, update memory]
Up --> CtxEach turn: assemble the context, call the model, and if it returns a tool call, execute it, append the result, and loop — until the model answers or a stop condition fires.
The hard parts
- Context management — the window is finite; as the loop grows you must summarize or trim old tool results, or the run breaks. This matters most on a retry: carrying the whole failed transcript forward wastes the window and re-anchors the model on its own dead ends. Keep the lesson, the current state of the artifact, and the criteria it has to meet — drop the rest.
- Tool execution — validate arguments, gate risky actions behind approval, run parallel calls, and return errors as results the model can recover from.
- Memory — carry facts across turns (and sessions) without stuffing everything into the window.
- Stop conditions — max steps, loop detection, and a token/time budget, so a stuck agent ends gracefully instead of spinning. A real-world set: stop after 20 steps or 100k tokens; stop if the same tool is called with the same arguments twice in a row; on stop, summarize progress instead of failing silently.
- Guardrails — apply input/output checks and security on every turn, not just the first.
One harness runs one agent’s loop. Designing the loops themselves — validators, closed loops, orchestration of many workers — is the next page: Loop engineering.
Skills — packaged procedures
Beyond tools, mature harnesses support skills: packaged instructions for a specific kind of task (a deploy checklist, a review procedure, a report format) that load into context when that task comes up. Tools give the agent capabilities; skills give it procedures — the difference between handing someone a terminal and handing them the runbook.
Build vs. buy
You rarely hand-write all of this:
- Write your own loop — full control; the most work. Lab 2 builds one from scratch in eight steps.
- Use a framework / SDK — the loop, tool handling, and context management come built in.
- Managed service — a provider hosts the loop and the tool sandbox for you.
Choosing among these is the Tooling & frameworks topic, coming next.