Skip to content
AI.info

AI agents

Agent Loops, Harnesses, and Runtimes

Understand the runtime that turns model calls, tools, state, budgets, and policies into a multi-step agent.

By the end you can

Example

Successful runs finished at a median of $1.21; the failures averaged $2.52

Every attempt got a hard ceiling of $4. When a run crossed it, the harness submitted whatever edits existed at that moment. SWE-agent, published in 2024, states the reason plainly: "Due to budget constraints, we set the per-instance budget to $4; if a run exceeded this budget, existing edits were submitted automatically."

The runs that worked never came close to that ceiling. Successful GPT-4 runs finished at a median of $1.21 and 12 steps. Unsuccessful ones averaged $2.52 and 21 steps. 93.0% of resolved instances were submitted before exhausting the budget, against 69.0% of instances overall. The authors traced one failure mode to agents inspecting every search hit exhaustively until the cost budget or the context window was gone.

Read the asymmetry rather than the averages. Agents succeed quickly and fail slowly. Twice the steps and twice the spend do not signal twice the effort. They signal a loop that has stopped making progress and has nothing inside it that can notice. The stop came from the harness. It did not come from a model deciding it was finished.

  • Decision at stake: Understand the runtime that turns model calls, tools, state, budgets, and policies into a multi-step agent. That is the layer that submitted SWE-agent's existing edits automatically when a run crossed the $4 per-instance budget.
  • Hidden assumption: An agent loop is safe if the model is instructed to stop when finished. But 69.0% of instances overall were submitted before exhausting the budget, against 93.0% of the resolved ones. Self-report is not what stopped the rest.
  • Primary control question: Unbounded loops convert small uncertainty into runaway cost. A failing run averaged 21 steps and $2.52 where a successful one took a median of 12 steps and $1.21. The extra steps bought nothing.
  • Evidence to collect: A run can be resumed without reconstructing hidden model context. The step count and cost of every attempt can be read off the recorded log, not inferred from the final answer.

A harness that depends on one model's habits is not stable

An agent loop repeatedly assembles context, asks the model for a decision, validates the proposal, executes an allowed action, records the result, and decides whether to continue.

That pattern is not folklore, and it is not new. ReAct measured it in 2022 and reported the gain in absolute points: "On two interactive decision making benchmarks (ALFWorld and WebShop), ReAct outperforms imitation and reinforcement learning methods by an absolute success rate of 34% and 10% respectively, while being prompted with only one or two in-context examples." Thirty-four and ten absolute percentage points, from one or two examples. The gain came from the shape of the loop around the model, not from more supervision inside it.

The harness owns this sequence and should remain inspectable outside the model. The model supplies judgment within the loop. The runtime supplies durability, policy enforcement, retries, budgets, tracing, and lifecycle control.

Durability, budgets, retries and tracing belong to the runtime; a loop that leans on the model for them keeps no record to inspect afterwards.

Case

Epoch AI describes its own loop before it reports a score

The harness is part of the result, so it gets written down. Epoch AI's SWE-bench Verified methodology page describes the benchmark as a human-validated subset of 500 samples drawn from GitHub issues in 12 open-source Python repositories. Then it states: "Unless otherwise specified, our scaffold is a simple loop where models can take an individual action (e.g. reasoning and tool call), then see any output. After each turn, the model is reminded of its remaining token budget."

Two design decisions sit in those two sentences. The loop is action-then-observation: one action, then whatever the environment returns, and nothing else in between. And the budget is not merely enforced somewhere outside the model. It is put back in front of the model after every turn. That is a choice about context, not only about accounting.

The sample list moved too. Epoch evaluates on the remaining 484, after excluding 16 samples that do not run reliably on its infrastructure: tests needing network access, and repo versions incompatible with the sample's declared dependencies. That exclusion belongs to the infrastructure rather than to the benchmark. It changed the denominator before any model was measured. A score quoted without its scaffold and its sample list does not measure the model alone.

Position

The score belongs to the loop as much as to the model

The controlled version of this claim already exists. SWE-agent held the base model fixed at GPT-4 Turbo and changed only the interface around it. On SWE-bench Lite the same model resolved 2.67% of tasks driven by BM25 retrieval-augmented generation, 11.00% driven by a shell-only agent, and 18.00% (54/300) driven by SWE-agent. On the full test set it resolved 12.47% (286/2,294), against 3.8% for the previous best non-interactive retrieval-augmented system. The paper's own summary: "We evaluate SWE-agent on SWE-bench and HumanEvalFix, achieving state-of-the-art performance on both with a pass@1 rate of 12.5% and 87.7%, respectively, far exceeding the previous state-of-the-art achieved with non-interactive LMs."

Nothing about the weights changed between 2.67% and 18.00%. The interface did. So a pass rate is a measurement of a system: a model, a loop that assembles context and validates each proposal, a tool set, and a sample list. Quoted without them, it becomes a claim about the model that nobody tested.

The benchmark's own owners solved this by fixing the loop rather than by adding a caveat. The SWE-bench Verified leaderboard carries a bash-only mode: "To make an apples-to-apples comparison of LMs easier, we evaluate all LMs using mini-SWE-agent in a minimal bash environment. No tools, no special scaffold structure; just a simple ReAct agent loop." The full leaderboard mixes simple agent loops, RAG systems and multi-rollout review systems. That is a listing of results, not a comparison of models.

The workable test is the one the bash-only mode implements, and the one this lesson's harness is designed for. Swap the model and hold the loop, and the two numbers can be compared. Swap both, and a second experiment has been run.

Ask which scaffold and which samples produced a pass rate before setting it beside another one.

Example

Indicators of healthy agent runtime design

The first thing a healthy harness demonstrates is that a run can be resumed without reconstructing hidden model context. A second and independent check is that every loop consumes a visible budget and records a state transition. You read that off the log rather than infer it from the output.

The last two claims only prove themselves under repetition, and repetition has a published price. τ-bench, published in 2024, introduced pass^k: the chance that all k i.i.d. trials of a task succeed, averaged across tasks. Its abstract: "Our experiments show that even state-of-the-art function calling agents (like gpt-4o) succeed on <50% of the tasks, and are quite inconsistent (pass^8 <25% in retail)."

Hold on to the per-domain figures behind that average. gpt-4o with function calling scores roughly 61% pass^1 on τ-retail and roughly 35% on τ-airline. Its retail score collapses to about 25% at pass^8. Running the same task eight times costs it about two thirds of its retail score. One green trace is therefore not evidence that a stopping rule or a policy check works. It is one draw from a distribution that pass^8 is designed to expose.

  • Signal 1: A run can be resumed without reconstructing hidden model context — stop the process, restart from the record, and see whether it continues.
  • Signal 2: Every loop consumes a visible budget and records a state transition, the way Epoch AI's scaffold puts the remaining token budget back in front of the model after each turn.
  • Signal 3: Repeated or non-progressing actions trigger a deterministic stop, tested by repetition rather than by a single run. Pass^1 near 61% on τ-retail and about 25% at pass^8 is what a single run hides.
  • Signal 4: Policy checks remain enforceable even when the model proposes otherwise. That is a property of the validating code, not of the instruction the model was given.

Visual

Each loop stage fails in its own way

Assemble context: select instructions, state, observations, and available actions. Propose: the model returns a structured next action or final response. Validate: code checks schema, authority, policy, budget, and task state. Execute: a tool or service performs the permitted operation. Record and decide: the harness stores results and either continues, escalates, or stops.

The loop is worth tracing one stage at a time. Each stage fails differently, and execution and the record-and-decide step need separate owners and separate tests.

The last stage is the one people treat as free, and two production runtimes price it. An AWS Step Functions Standard workflow execution may run for up to 1 year. The quota on its history is explicit: "25,000 events in a single state machine execution history. If the execution history reaches this quota, the execution will fail." Temporal draws the same line in its own units. It terminates a Workflow Execution whose Event History exceeds 51,200 Events or 50 MB, and warns from 10,240 Events or 10 MB.

Two independent vendors, two different numbers, one shared conclusion: the resumable record is a bounded resource. A harness that never trims, checkpoints, or summarises its history does not fail gracefully at the ceiling. In Step Functions the execution fails outright. In Temporal it is terminated. Bounding the record is what makes resumption and a deterministic stop implementable rather than aspirational.

FigureProcess · 5 steps
  1. 1

    Assemble context

    Select instructions, state, observations, and available actions.

  2. 2

    Propose

    The model returns a structured next action or final response.

  3. 3

    Validate

    Code checks schema, authority, policy, budget, and task state.

  4. 4

    Execute

    A tool or service performs the permitted operation.

  5. 5

    Record and decide

    The harness stores results and either continues, escalates, or stops.

Key idea

Unbounded loops convert small uncertainty into runaway cost

Without progress measures, duplicate detection, and hard budgets, the agent can oscillate between actions or repeatedly replan. A fluent trace may hide that no external state has improved.

SWE-agent's authors named the concrete shape of this: agents inspecting every search hit exhaustively until the cost budget or the context window was gone. Nothing in that behaviour is irrational from inside a single turn. Each next hit might be the relevant one. The stop has to come from outside the turn. That is why the $4 per-instance cap submitted the existing edits automatically on overrun, rather than waiting for the agent to conclude.

The measured asymmetry justifies a hard limit rather than a soft one. Successful runs finish at a median of 12 steps and $1.21. Unsuccessful ones average 21 steps and $2.52. So continued spending is evidence against success, not for it. A step, time, token, cost, and retry limit set near the successful median costs little and truncates the long tail of failures.

Enforce those limits in the harness. Stop when progress cannot be demonstrated. Define progress as a change in external state, not as another paragraph of reasoning.

A trace that reads well while nothing outside the agent has moved is the most expensive failure available, because nothing inside it ever asks you to stop.

Steps

Design a minimal agent harness

Design the smallest harness that still carries one real workflow from start to stop. Define the state object: goal, observations, pending actions, evidence, budgets, and status. Specify transition guards that validate every proposed action before execution. Record immutable events — model decisions, tool calls, results, approvals, and errors. Measure progress by choosing task-specific state changes that justify another loop. Implement terminal states: success, partial success, escalation, refusal, cancellation, and failure.

Two of those five steps are not engineering taste in the EU. The AI Act makes them duties for high-risk systems. Article 12(1): "High-risk AI systems shall technically allow for the automatic recording of events (logs) over the lifetime of the system." Over the lifetime of the system — not for the duration of a debugging session. Article 14(4)(e) requires that the people assigned human oversight be able to interrupt the system through a stop button or an equivalent procedure that brings it to a halt in a safe state.

Read those two together and the exercise acquires an acceptance test. "Record immutable events" means a log that survives the run. "Implement terminal states" means at least one terminal state reachable by a human at any moment, ending in a safe state rather than mid-transaction.

Then push the harness until runaway cost stops being an abstraction and shows up in your own run log. Set a budget near your successful median and watch what gets truncated. Finally, stop the process mid-task and restart it from the recorded state. What that restart produces is your evidence that resumption actually works.

FigureProcess · 5 steps
  1. 1

    Define the state object

    Include goal, observations, pending actions, evidence, budgets, and status.

  2. 2

    Specify transition guards

    Validate every proposed action before execution.

  3. 3

    Record immutable events

    Log model decisions, tool calls, results, approvals, and errors.

  4. 4

    Measure progress

    Choose task-specific state changes that justify another loop.

  5. 5

    Implement terminal states

    Support success, partial success, escalation, refusal, cancellation, and failure.

A runtime you cannot restart from its own record is unfinished

The harness should remain useful when the underlying model changes. If the loop depends on hidden habits of one model, the architecture is not yet stable. The SWE-bench team built the test for that into its own leaderboard, where every language model runs through the same mini-SWE-agent bash environment precisely so that the loop stops being a variable.

A review of the runtime that never looks at looping cost has skipped the expensive part. That is where a small per-step uncertainty turns into a bill nobody budgeted for: 21 steps and $2.52 for the runs that failed, against 12 steps and $1.21 for the ones that worked. And where the record itself is the thing you are relying on, check its ceiling before a long-running agent discovers it for you — 25,000 events in Step Functions, 51,200 Events or 50 MB in Temporal.

The review should end with a working restart. Stop a run, bring it back from what the harness recorded, and confirm it carries on without the model's hidden state. If it cannot, the record was a transcript, not a state.

Tie the loop to one model's habits and every upgrade turns into a rewrite, paid for by whoever inherits the runtime.

Key takeaways