Skip to Content
Levain LabsLevain Labs
Platform

Harness

The loop that runs your agent.

The harness is the component that executes the agent. It reads the agent's next intended action, dispatches it, records the result in the session, and loops.

The cycle

  1. Decide. The agent chooses what to do next, given its instructions and the session so far.
  2. Act. The harness executes the action: a tool call, a resource read, or a write to the workspace.
  3. Observe. The result is appended to the session as an event.
  4. Repeat until the agent reports it's done, or a bound is hit.

Every iteration is auditable, every state transition is durable, and every effect is bounded.

Bounds

The harness enforces three hard limits on every run:

  • Wall-clock timeout. The run halts when it's reached.
  • Budget in USD. Token spend is tracked in real time; the run halts when the threshold is crossed.
  • Step count. The run halts at a maximum number of iterations.

These bounds are enforced by the platform and cannot be lifted by the agent.

Execution engines

Each agent step runs on an execution engine inside the sandbox. Two are available:

  • Claude Agent (default) — the engine behind every recipe unless stated otherwise.
  • Hermes Agent — a self-learning engine. Beyond answering, it curates its own memory and authors skills: reusable procedures it writes down when it solves something worth repeating, reviewed and pruned from the dashboard.

The engine changes how a step thinks, not how it's governed: both run in the same sandbox, use the same tools and integrations, meter through the same billing pipeline, and respect the same bounds. Memory written by either engine lands in the same store.

Recipe kinds

A recipe is one of two kinds, set by kind under [tool.levain] in its pyproject.toml:

  • Graph (the default): a PlusCal spec, graph.tla, plus one Python function per node. The graph runs inside the sandbox, a node at a time, and checkpoints its state after each step; a node that pauses for input hands the turn back, and the next message resumes it where it stopped.
  • Harness: one engine session, declared in [tool.levain.harness]. There is no graph and no Python: the package holds its settings, a system prompt and, for Claude Code, the skills and project files it ships. Pick it when the agent is one conversation with tools rather than a fixed sequence of steps.
[tool.levain]
kind = "harness"

[tool.levain.harness]
engine = "claude_code"            # or "hermes"
model = "claude-sonnet-4-6"
effort = "high"
prompt = "prompts/system.md"
tools = ["Read", "Glob", "Grep", "Edit", "Write", "Bash"]
mcp_servers = ["levain-wiki", "levain-artifacts"]

[tool.levain.harness.state]
task = { type = "string", description = "What to work on." }
summary = { type = "string", description = "One paragraph on what was done." }
result = { type = "dict", file = "out/result.json" }

state declares the fields a run takes in and hands back, with the same types and reducers as a graph's variables, plus dict for a JSON object of the recipe's own shape. Every harness recipe also carries messages, the conversation, without declaring it.

The engine sets a field with the set_result tool, or, when the field names a file, by writing that file in the workspace: the platform reads it when the turn ends, as text for a string field and as JSON for any other, up to 1 MiB. A result the recipe already writes as a file needs no declared schema: give it a dict field and the file's path.

Skills, instructions and settings

A claude_code recipe can ship Claude Code's project files with its package, each declared by a path inside it:

[tool.levain.harness]
engine = "claude_code"
skills = "skills"                 # skills/<name>/SKILL.md, one directory per skill
instructions = "instructions.md"  # the project instructions
settings = "settings.json"        # project settings, a JSON object

At the start of every turn the platform copies them into the agent's workspace:

KeyLands at
skills.claude/skills/<name>/
instructionsCLAUDE.md
settings.claude/settings.json

The version's copy wins. A workspace file at one of those paths, or a skill of the same name, is replaced every turn, so edits to it don't last. Skills under other names stay as they are, whoever wrote them. When a newer version stops shipping a skill or a file, the next turn removes it from the workspace. Publishing a version updates the files everywhere the agent runs, a self-hosted runtime included. The workspace stays the session's working directory.

Each path must stay inside the package and exist, and each skill directory must hold a SKILL.md. A version that breaks one of these fails validation.

In a harness recipe the engine owns the control flow: which tools it calls, in what order, and when the work is done. In a graph recipe the graph does. Either way the recipe runs in the sandbox, one turn per message, and the platform keeps everything around it: the sandbox, credentials and integrations, the session record, the bounds above, messages you send while a run is working, calls to other agents, and what happens after a run ends. Every turn continues the same session, so a paused session resumes with its context.

To start from a complete harness recipe, create an agent with "template": "code_assistant" (POST /api/v1/agents).

Observability

While a run is in progress, the harness writes each step to the session. GET /runs/{id}/logs returns:

  • The action the agent chose.
  • The tool call it dispatched.
  • The result that came back.
  • Intermediate cost and token counters, updated live.

This is the primary surface for inspecting and optimizing agent behavior.

On this page