Defending AI Agents
עברית Join waitlist
Menu

E3 · Lesson 09

How far can a loop go? Compounding error, code actions and the time horizon

Everything so far makes one run more robust. The expert question is about length: how many steps can an agent take before it goes wrong, why that number is moving fast, and which design choices move it. Three lines of research meet here, and they do not all agree.

Compounding, and why a small gain is a large one

If each step succeeds independently with probability s, an n-step task succeeds with probability s^n. The length at which success falls to one half, the 50% horizon, is

H_{50} = \frac{\ln 0.5}{\ln s} \approx \frac{0.69}{1 - s} \quad \text{for } s \text{ near } 1.

The horizon is inversely proportional to the per-step error rate. Going from 99% to 99.5% per step looks like a rounding error on a short benchmark and doubles the horizon, from 69 steps to 138. Sinha et al. (2025) make this argument against claims of diminishing returns: short-task benchmarks hide gains that become large on long tasks. They then measure something the formula leaves out. Per-step accuracy falls as a run goes on, and not only because the context is long: models become more likely to err when the context holds their own earlier errors. They call this self-conditioning. It breaks the independence assumption in the pessimistic direction, so the real horizon is shorter than 0.69/(1-s). In their experiments, thinking mitigates it and scale alone does not.

The statistical twin is a Markov chain (a process that moves between states with fixed transition probabilities) with an absorbing failure state, one the chain never leaves, except that here the probability of entering it depends on the chain's own history. It is why lesson 2's error messages matter more than they look: a run that recovers cleanly from a refused call has an error in its context that it has dealt with, and one that flails has several it has not.

The time horizon, measured

Kwa et al. (2025) turn the horizon into a benchmark statistic. They time skilled people on software tasks, fit each model's success probability against the human time with a logistic curve, and report the human time at which the model succeeds half the time. For frontier models in early 2025 that was about 50 minutes, and it had doubled roughly every seven months since 2019. At that rate, 50 minutes becomes about nine hours in two years (50 \times 2^{24/7} \approx 540 minutes).

Read it with the caveats its authors give. The tasks are software tasks with automatic scoring. The fit is one logistic per model, so the horizon inherits that fit's uncertainty. And extrapolating a doubling time is extrapolating a trend fitted on a few years of a field that changes its methods every year. External validity is the open question: whether "a task that takes a person an hour" means the same thing in your domain, and whether success at 50% is the operating point you care about. For an agent that sends e-mail, you care about something nearer 99%, and the horizon at 99% is far shorter than at 50%.

Reliability across tries: pass^k

A rate measured once per task hides inconsistency. τ-bench (Yao et al., 2024) reports pass^k, the probability that all of k independent tries of the same task succeed. The state-of-the-art function-calling agents of mid-2024 solved under half its tasks, and pass^8 in the retail domain was under 25%. Module 1 lesson 9 derives the estimator. On the twenty lab tasks, E3's loop had pass^1 = 0.550 and pass^3 = 0.450 (the build), while (\text{pass}^1)^3 would be 0.166. Per-task success rates p_i differ, so the mean of p_i^3 exceeds (\bar p)^3. That is Jensen's inequality: for a convex function such as x^3 on [0, 1], the mean of the function is at least the function of the mean. Here the tasks split into ones the model nearly always solves and ones it nearly never does. A fleet's reliability depends on the spread of task difficulty, not only its mean.

Code as action, and what it costs

Lessons 2 to 4 assume the model acts through JSON calls to named tools. CodeAct (Wang et al., 2024) lets it write Python instead, executed in an interpreter: a loop over files, a filter, three tools composed in one action. Across 17 models it reported up to 20% higher success than JSON or text actions. SWE-agent (Yang et al., 2024) showed the other side of the interface question: a purpose-built agent-computer interface (file viewer, editor and search commands designed for a model, not a person) took SWE-bench to 12.5% pass@1 (the share of tasks solved at the first try), then far ahead of non-interactive approaches. How the model acts is a design variable with a measured effect.

The cost of code actions is the security course's subject. A JSON call to send_email can be checked field by field at a gateway (Modules 3 and 13). A code action is a program, and checking a program before it runs is the shell problem (Module 3 lesson 5, "the hardest door"). Code actions need a sandbox (E8, Module 12), and the capability gain is bought with inspectability. Teams argue about this trade, and should: the measured gain comes from benchmarks without an adversary, and the cost appears only when there is one.

Open problems

  • What limits the horizon? Sinha et al. locate it in execution, not reasoning. The time-horizon trend credits reliability and error recovery. Neither settles whether longer contexts, better recovery prompts or training is the cheapest lever for a given model.
  • Is the trend a law? Seven-month doubling is fitted on one task family. Whether it holds for e-mail, ledgers and the long tail of enterprise tools is unmeasured.
  • Can code actions be made inspectable? Restricted languages, typed tool APIs called from code, and information-flow tracking on the interpreter (Module 11's CaMeL) are attempts. None yet gives both CodeAct's flexibility and a JSON call's checkability.

Check yourself

  1. Per-step success rises from 98% to 99%. By what factor does the 50% horizon grow, under independence?
  2. Self-conditioning means P(\text{error at } t \mid \text{an earlier error}) exceeds P(\text{error at } t \mid \text{none}). Does that make the true horizon longer or shorter than 0.69/(1-s), with s measured on first steps?
  3. Why is the 50% time horizon the wrong operating point for an agent that sends e-mail on your behalf, and which way does the right one move the horizon?
Answers
  1. It doubles: 0.69/0.02 \approx 34 steps becomes 0.69/0.01 \approx 69. Exactly, \ln 0.5 / \ln 0.98 = 34.3 and \ln 0.5 / \ln 0.99 = 69.0.
  2. Shorter. The per-step error rate rises after the first error, so failures cluster and success decays faster than s^n once a run has gone wrong. The formula, fed with a first-step s, overstates the horizon.
  3. A 50% success rate means half the e-mails are wrong or missing. You want the length at which success is, say, 99%: \ln 0.99 / \ln s, about 0.01/(1-s), roughly 69 times shorter than the 50% horizon for the same s.