Skip to content
mentoor

Topic 2 of 5 · 4 min read

Monitoring agent runs and trajectories

Goal: Read run-level metrics and pick out the runs that are looping, drifting or unusually expensive.

Monitor an agent by the run, not by the request: a run is the whole trajectory of model calls and tool calls toward one task, and most agent problems only show up across the trajectory.

Check yourself · 1 of 3

Why is a request-level dashboard not enough for an agent?

Choose one answer

Why it matters

Request-level dashboards show latency and error rates for each model call. An agent can pass every one of those checks and still fail: each call returned 200, but the run searched the same page six times, then answered from memory. Only a run-level view shows that.

What to record and watch

  1. One trace per run. Give each run an id, and record each model call and tool call as a span under it. OpenTelemetry has conventions for agent and tool-call spans, so any compatible backend can read them.
  2. Task success rate. Did the run achieve the goal? Use an outcome signal you trust: a user confirming, a ticket staying closed, a check in code. Not the model saying "done".
  3. Steps, tokens and cost per run. Chart the distribution. The median tells you the normal cost, the 95th and 99th percentiles tell you where the waste is.
  4. Tool error rate per tool. A tool failing 20 percent of the time drives retries and wasted steps in every run that uses it.
  5. The long tail. Sort runs by cost. A handful of runs often account for a large share of spend. Read those first.
  6. Replay. Store the inputs and tool results of each step so you can step through a bad run in order and see where it went wrong.

Before and after

Before: the dashboard shows average cost per run rising from 0.04 to 0.06 dollars. Nobody knows why. After: the run table shows the median unchanged, but a new tail of runs with 25+ steps, all using the search_orders tool, whose error rate rose after a schema change. One fix to the tool brings the average back.

run steps cost tool errors outcome
r-1041 5 0.03 0 success
r-1042 27 0.31 11 cancelled
r-1043 7 0.04 1 success

Run r-1042 is the one to open: 11 tool errors in 27 steps looks like a loop.

What goes wrong

  • Averages only. The mean hides a small group of very expensive runs.
  • Success measured by the agent's own claim. Agents report success on failed work. Check the outcome independently.
  • No stored step data. Without tool inputs and outputs you can see that a run was bad, not why.
  • Logging full user data. Trajectories hold personal data. Redact before storing, and set a retention period.

Examples

Finding a drifting run

A booking agent's success rate fell from 91 to 84 percent in a week. The run table showed no change in cost, but a rising count of runs where the tool "get_availability" was called with the previous month's dates. Replaying one run showed the agent reading a stale date from an earlier step and never refreshing it.

A tail that costs money

Sorting one day's runs by cost showed the top 20 runs, out of several thousand, made up a quarter of the spend. Eighteen were the same loop on a rate-limited API. The fix was a retry limit on that tool, not a cheaper model.

Key points

  • Trace each run as one tree of model and tool spans, so problems across steps are visible.
  • Measure task success with an outcome signal, not the agent's own claim of being done.
  • Watch the distribution of steps and cost, and read the most expensive runs first.
  • Track error rate per tool, because one flaky tool inflates every run that uses it.
  • Store step inputs and tool results so a bad run can be replayed in order.

Common mistakes

  • Watching only per-request latency and errors, which miss loops and wrong answers.
  • Reporting average cost per run and never opening the most expensive ones.
  • Taking the agent's final message as the success label.
  • Storing trajectories with raw personal data and no retention limit.

Check yourself · 2 of 3

Which signal is the most trustworthy label for task success?

Choose one answer

Check yourself · 3 of 3

Average cost per run rose from 0.04 to 0.06 dollars while the median stayed the same. What is the best next step?

Choose one answer

Practice items, not counted towards your mastery.

Start here