Distillate

AI agentsLesson 2openfrom distillate

Inside the Agent Harness: Loops, Skills, Subagents & MCP

What happens step by step inside an agent harness, and how skills, subagents, MCP and sandbox tiers fit around the model.

In Lesson 1, we established that agents are goal-driven action loops rather than single-shot prompt completions or fixed pipelines. In this lesson, we dissect the internal machinery: what actually happens step-by-step inside the agent harness, how instructions turn into capabilities via skills, how work is divided across subagent boundaries, and how standard protocols like MCP decouple agent runtimes from tools and world state.

The Anatomy of an Agent Harness

The harness (or agent runtime / loop orchestrator) is the outer software environment enclosing the foundation model. The foundation model never directly executes system commands, opens sockets, or manipulates disk files. Instead, the harness operates a state machine known as the ReAct (Reason + Act) loop:

The ReAct Loop: Context Assembly (System + Active Skills + History + Tool Definitions) → LLM Inference → Decision Gate (Does model emit a tool call?) → If tool call: Harness validates policy/sandboxing → Tool executes → Tool output/observation appended to history → Model infers again until completion.

When an agent "thinks" or plans, it simply alternates between token generation and environmental feedback. The intelligence emerges entirely from the loop's ability to ingest feedback from failed tool calls and self-correct.

Skills: Dynamic Capability Packaging

A raw prompt asking an agent to "write good database migrations" produces inconsistent results across sessions. A Skill transforms vague instructions into an executable, repeatable operating procedure.

Under the hood, skills are standardized packages (typically a SKILL.md accompanied by helper scripts, reference templates, and schemas) loaded into context on demand:

The "Blackmail Skill" & Voodoo Prompting Anti-Pattern

In the early days of prompt engineering, users and tutorials resorted to desperate emotional leverage to prevent models from taking shortcuts:

In a well-engineered agent harness, superstitious prompts are replaced with structural verification:

Voodoo Prompt (Wishful Thinking)Engineering Equivalent (Harness & Skill)
"Make no mistakes."Mandatory verification step: run bun test or typechecker tool before returning.
"You are a senior developer."Skill with explicit architecture standards, lint rules, and error-handling constraints.
"People will die if you fail."Deterministic gating: sandboxed execution + human-in-the-loop approval before commit/push.
"I will tip you $200."Self-reflection loop: require the agent to generate and verify a checklist against the actual diff.

MCP (Model Context Protocol): Standardizing Tool Ecosystems

Before MCP, every AI platform invented its own proprietary tool-calling schema and plugin format. If an application wanted to expose a database, a code repository, or a review queue to Claude, OpenAI, or local agents, developers had to write bespoke wrappers for each.

MCP (Model Context Protocol) is an open specification that standardizes how LLM applications communicate with external tools, prompts, and resources over JSON-RPC (using standard I/O streams or Server-Sent Events):

MCP Architecture: Host/Agent Harness contains an MCP Client communicating via JSON-RPC (over STDIO or HTTP-SSE) with isolated MCP Servers. The Distillate MCP Server exposes tools (like capture_card) directly manipulating SQLite, while Git/Filesystem MCP servers expose local system operations.

PrimitivePurposeExample
ToolsExecutable functions that agents can invoke to perform side effects or query systems.capture_card, run_command, query_database
ResourcesRead-only contextual data, documents, or schema files exposed like URIs.distillate://cards/recent, file:///logs/app.log
PromptsPre-configured workflow templates parameterized for common user tasks.draft_lesson_from_solution, code_review

Subagents: Process Isolation & Parallel Work

Single-context agent architectures eventually hit two fundamental walls:

Modern harnesses resolve this via Subagents—hierarchical, decoupled worker instances spawned with their own isolated conversation context, tool subsets, and lifecycles:

Subagent Hierarchy: Lead Orchestrator delegates tasks to specialized subagents (Browser Subagent with DOM tools, Code Search Subagent with Grep tools). Heavy noise and logs stay trapped inside the subagent's local context window; only high-signal summary results are returned back to the orchestrator.

Sandboxing & The Autonomy Ladder

The most dangerous design mistake in building agentic systems is granting unconstrained host access without graduated boundaries. Modern production harnesses implement tiered autonomy:

Autonomy Ladder: Tier 0 (Pure Read) and Tier 1 (Sandboxed Local Mutation) execute automatically without interrupting the user. Tier 2 (Consequential / Outbound) requires an explicit Human Approval Gate. Tier 3 (Irreversible / Destructive) is blocked outright by harness security policies.

Quick Check

Why is writing "A human life is at stake, make no mistakes!" inside a prompt an anti-pattern for reliable agent workflows?

References & Deeper Reading