# Agent trace: replay a real AI agent fixing this site

Agent demos usually show a tidy success. This is a real run, recorded on this site on 20 November 2026: the release check refused to publish because of one broken link, and an AI coding agent was asked to find out why and make sure it could not happen again. Every step is shown as it happened, including the guess that turned out wrong.

<div data-sim="trace"><p>Interactive simulation. It needs JavaScript; the text below explains what it shows.</p></div>

## What you are looking at

The run is a loop of three kinds of steps. **Think** steps are the agent's reasoning between actions. **Act** steps are tool calls: a shell command, a file edit, a test, a database query, a deployment that a human ran. The box under each action is what came back, shortened but not rewritten. Red marks the two places where the run went wrong: a hypothesis that a later query disproved, and a query that failed because it used the wrong variable names.

The bar above the steps is the whole run; click any segment to jump to it. On the right, the tool-call counts and the run's numbers update as you play.

## Things to try

- Play the whole run once, then untick thinking and read only the actions: that is the audit trail you would review in a real team.
- Stop at step 5 and decide for yourself what you would check next before reading step 6.
- Compare step 9, the test, with step 18, the second test: the first checks the safety net, the second checks the root cause.

## How it works in real systems

Agent platforms record exactly this: each model turn, each tool call with its arguments and result, timings and token counts, often as OpenTelemetry spans in tools such as Langfuse, LangSmith or Arize Phoenix. Teams read traces to debug failures, to spot loops and wasted calls, and to build evaluation sets from real runs. The habits visible here, testing a fix on a copy, reading the error rather than guessing, and fixing both the symptom and the cause, are what separate a useful agent run from a lucky one.







<!-- simx:start -->
## Key formulas

$$a_t=\pi(\text{task},\,o_{1:t-1}),\qquad o_t=\text{tool}(a_t)$$

An agent loop: choose an action from the task and everything observed so far, run it, observe.

$$\text{stop when } \pi \text{ returns an answer, or } t=t_{\max}$$

Every real agent needs a stopping rule and a step budget.

## Common mistakes

- Trusting an agent's summary without reading its tool calls: the actions are the evidence.
- Treating a first hypothesis as a finding: here the first guess was wrong and only a query showed it.
- Letting a tool error end the run: a good loop reads the error, adjusts and retries once.

## Real-world numbers

- This run: 19 steps, 11 tool calls, one failed query and one wrong hypothesis on the way to the fix.
- ReAct (2022) introduced the think, act, observe loop used by most agents today.

## Further reading

- [ReAct: Synergizing Reasoning and Acting in Language Models](https://arxiv.org/abs/2210.03629)
- [Building effective agents (Anthropic)](https://www.anthropic.com/research/building-effective-agents)

<!-- simx:end -->

## Code lab

A minimal agent loop with a step budget and a trace, in plain Python.

<div class="cl-start"></div>

### Step 1 · Tools and a trace

```python
import subprocess, json, time
TRACE = []
def log(kind, **kw):
    TRACE.append({"t": round(time.time(), 2), "kind": kind, **kw})
def shell(cmd):
    out = subprocess.run(cmd, shell=True, capture_output=True, text=True, timeout=60)
    return (out.stdout or out.stderr)[-2000:]
TOOLS = {"shell": shell}
```

### Step 2 · The loop

```python
def run(task, policy, max_steps=20):
    obs = []
    for step in range(max_steps):
        action = policy(task, obs)                 # an LLM call in a real agent
        if action["type"] == "answer":
            log("answer", text=action["text"]); return action["text"]
        log("act", tool=action["tool"], input=action["input"])
        try:
            result = TOOLS[action["tool"]](action["input"])
        except Exception as e:
            result = f"error: {e}"                  # errors are observations too
        log("observe", output=result[:300]); obs.append((action, result))
    log("stop", reason="step budget reached")
```

### Step 3 · Read the trace

```python
from collections import Counter
print(Counter(e.get("tool") for e in TRACE if e["kind"] == "act"))
print(sum(1 for e in TRACE if e["kind"] == "observe" and str(e["output"]).startswith("error")), "errors")
print(json.dumps(TRACE[-3:], indent=2))
```

<div class="cl-end"></div>

## More simulations

[All AI Simulations](/ai-simulations) · [ReAct and tool calling →](/ai-simulations/react-tool-calling) · [From 0 to 100 →](/ai-simulations/zero-to-hundred)
