Engineering

·

LOG-029

What to trace in an agent run

What to trace in an agent run

What to trace in an agent run

Jonah Weiss

Engineering, Tracing

Three things customers asked for most this year: run last week’s traffic against today’s prompt, stop a deploy that fails its evals, and answer every agent’s question from one place.

When a customer asks why an agent refunded them twice, you have about four minutes before the question becomes a complaint. In that time you need to find the run, see each step it took, and point at the one that went wrong. Everything in this post comes from building for those four minutes.

The run is the unit

A run starts when something asks the agent to act, a ticket, a message, a schedule, and ends when the agent answers, hands off or gives up. Everything the agent does in between belongs to that run, under one id. If a run calls another agent, the second run is a child of the first, not a new story.

This sounds obvious until you look at a system where the model calls are logged in one place, the tool calls in another and the handoffs nowhere at all. Joining them after the fact is the slowest part of every incident we have seen.

Give the run's id to everything the agent touches: the ticket it answered, the email it sent, the refund it made. When the question arrives from the other end, that id is how you find the run in seconds instead of searching by timestamp.

Record every step, not only the model

The model is rarely the step that fails. Of the incidents our customers traced last quarter, 41% started in a tool: a search that returned nothing, a lookup on the wrong customer, an API that answered slowly and was retried twice. Trace the tools with the same care as the model calls.

Every step becomes a span, and every span carries five fields:

  • A name a person can read: tool · crm.lookup, not fn_call_3.

  • The input and the output, as the step saw them, redacted at the edge where they must be.

  • When it started and how long it took.

  • What it cost: tokens and dollars for a model, the price of the call for a paid API.

  • What it decided: the branch it took, the guard it passed, the reason it gave.

from talos import trace

@trace.span("tool", name="crm.lookup")
def lookup(customer_id: str) -> dict:
    record = crm.customers.get(customer_id)
    trace.note(found=record is not None, plan=record and record["plan"])
    return record
from talos import trace

@trace.span("tool", name="crm.lookup")
def lookup(customer_id: str) -> dict:
    record = crm.customers.get(customer_id)
    trace.note(found=record is not None, plan=record and record["plan"])
    return record
from talos import trace

@trace.span("tool", name="crm.lookup")
def lookup(customer_id: str) -> dict:
    record = crm.customers.get(customer_id)
    trace.note(found=record is not None, plan=record and record["plan"])
    return record

Two lines are enough for a function to appear on the trace with its arguments, its answer, its time and its errors. The note adds the one fact you will want to filter on later, here whether the customer was found and which plan they are on.

Record the decision, not only the output

An output says what the agent wrote. A decision says why it went one way and not another. When the triage agent sends a ticket to billing, record the route, the confidence and the rule that settled it. When a guard lets a step through, record that it ran and what it checked. A trace with decisions on it can be searched for every run that took the same wrong turn, which turns one incident into a list of the customers it touched.

What to leave out

Not everything belongs in a trace. Keys and tokens never do: strip them before the span is written, not after. Personal data should be masked at the edge with a rule you can show an auditor, and kept only as long as you need it to debug. On Talos, redaction runs in the SDK, inside your process, so the raw value never leaves your servers.

Retention matters as much as redaction. Keep full traces for as long as incidents take to surface, usually 30 days, then keep the decisions and the costs and drop the inputs and outputs.

If you cannot explain a run to the customer it happened to, you did not trace enough. If the trace would need explaining to your security team, you traced too much.

The tracing team's rule of thumb

Three questions every trace should answer

Before shipping an agent, open one of its traces and try to answer three questions in under a minute. What did it do? Why did it do it? What did it cost? If any answer needs a second tool, a search through logs or a guess, the trace is missing a field. Add it now, while nobody is waiting on the answer.

Keep reading

Two more
from the log.

Two more
from the log.

Two more
from the log.

Product
LOG-031
Talos 3.0: replay, eval gates and the review desk
Talos 3.0: replay, eval gates and the review desk
Talos 3.0: replay, eval gates and the review desk

Three things customers asked for most this year: run last week's traffic against today's prompt, stop a deploy that fails its evals, and answer every agent's question from one place.

Nadia Brandt
4 min read
Engineering
LOG-030
How to write evals for an agent
How to write evals for an agent
How to write evals for an agent

An agent that passed yesterday can fail today, and nobody notices until a customer does. A small, honest eval suite is how you notice first. Here is the one we would write again.

Rafael Duarte
3 min read
Free for your first 10,000 runs

Put your first agent
on shift tonight.

Put your first agent
on shift tonight.

Put your first agent
on shift tonight.

Talos
1,284 agents on shift
UTC 07:44:53

Create a free website with Framer, the website builder loved by startups, designers and agencies.