Measure failures where the model sees them
Here is a tool call that answers well and still failed. The Todoist tool can’t reach Todoist for this asker, so it returns a sentence the model can pass on: { unavailable: 'Todoist cannot be reached for this asker right now.' }. The run tells the asker. Before the change, the tool span recorded that call as success: the tool had returned, and the span knew nothing else. A chart of tool outcomes stays green while every task question fails.
An agent fails in ways a web service doesn’t. A tool fails inside a successful result. The model sends arguments a schema rejects and recovers. Code throws away a finished answer. Count only exceptions and HTTP statuses, and none of this shows up.
What the article argues
Anthropic’s How we built our multi-agent research system has a section on production reliability. Trace runs, not conversations covered its first half, full production tracing. This post is about the second: beyond standard observability, the team monitors the agent’s decision patterns and interaction structures, and does it without reading the conversations.
For us, that means records Datadog can group and count. The service creates OpenTelemetry spans and metrics in process and writes them as JSON lines on standard output: otel.span.end for each ended span, otel.metric with the totals once a minute. Datadog reads that log. The records below are the ones the service writes on those lines: codes, IDs and numbers.
A failed tool can look like a success
When Todoist refuses the request with a 401 or 403, the Todoist tool returns the same sentence under failed, so the run can still answer. The { unavailable } form is for a missing credential.
if (status === 401 || status === 403) return { failed: TODOIST_NO_ACCESS.unavailable }
Either way, the asker reads the right sentence, but to the tool span a returned result meant success. An Automations refusal, a web page that wasn’t read, a failed search and a bulk write where Todoist refused some tasks all looked the same.
I let a toolkit attach a failure code to a result. The model still gets the same result. The tool span and the agent_core.tool.call metric record the call as failed, next to success and error (the tool threw). The test, trimmed:
it('records a call whose result reports a failure as failed, and still gives the model the result', async () => {
const unavailable = { unavailable: 'Todoist cannot be reached for this asker right now.' }
const { spans, metrics, tool, context } = setUp(async () =>
readResult({ result: unavailable, failure: 'http_status' }),
)
await expect(tool(READ).execute({}, context())).resolves.toEqual(unavailable)
expect(spanNamed(spans, 'agent_core.tool')?.attributes).toMatchObject({
'agent_core.tool.outcome': 'failed',
'agent_core.tool.failure': 'http_status',
})
})
Each toolkit names its own codes: Todoist’s http_status or items_failed, an Automations refusal’s reconnect_required, the web reader’s blocked_site.
Count failures where the model sees them
The tool span opens when a call reaches a tool, and some calls never do. The harness refuses arguments the tool’s schema rejects, a tool called more often than it allows, or a call after the run ran out of budget. The model got an error, and we got no record. Our spans showed input refusals for only one connector tool, because only that tool checked its arguments after its span had opened. Every other tool looked perfect.
I added agent_core.tool.error, which counts every tool call that ended in an error the model got. Its two labels are agent_core.tool.name and agent_core.tool.reason, such as invalid_tool_input, tool_calls_per_run or refused_before_run (the harness ended the call before the tool ran).
A harness test plays a scripted model against a tool allowed once per run. The model calls it twice (trimmed, from the test, not a run):
const limited = { ...limitedTool, definition: { ...limitedTool.definition, max_calls_per_run: 1 } }
const model = new ScriptedModelAdapter([
{ type: 'tool_call', calls: [call('limited-1')] },
{ type: 'tool_results', results: [{ tool_name: 'test.limited', tool_call_id: 'limited-1', is_error: false }] },
{ type: 'tool_call', calls: [call('limited-2')] },
{ type: 'tool_results', results: [{ tool_name: 'test.limited', tool_call_id: 'limited-2', is_error: true }] },
{ type: 'text', text: 'Done.' },
])
// ...
expect(toolErrors).toEqual([['test.limited', 'tool_calls_per_run']])
The first call counts nothing, the second counts once. Three choices keep the metric honest:
- A tool name the model made up is counted as
unknownwithunknown_tool. Otherwise every invented name would open a new series. - A read the server made on its own, before the model’s first turn, isn’t counted, and neither is a call a cancel ended. The model got no error from either.
- A refusal a tool returns as its result, such as
invalid_args, stays in the span’sagent_core.tool.failurefrom the previous section. A call that reached the product is also inagent_core.tool.call, so the two metrics are never added.
How long the asker waits
Total duration says little about what the asker felt. I put two waits on the agent_core.run span, both counted from the run’s creation: agent_core.run.first_status_ms, when the run published its first status, and agent_core.run.first_answer_ms, when the first answer text arrived. They already existed as OpenTelemetry histograms, which a log query can’t read. A plain number on a span can be charted.
That still didn’t explain a slow turn. Some reasoning turns that wrote a few words took far longer than usual, and the turn span had only its total duration. I split it in two, counted from the request:
agent_core.model.turn.response_started_ms: the provider opened its response.agent_core.model.turn.first_chunk_ms: the first chunk of thinking, text or a tool call arrived.
For example, a 100-second turn with response_started_ms: 95000 waited on the provider. One with response_started_ms: 400 and first_chunk_ms: 98000 was slow to generate. Either is absent when it never happened, as in a request that timed out before the provider answered.
Which product started the run
The same agent answers a mention in Comms and runs an automation’s daily check-in that nobody asked for. The run span said where the run was anchored, not which product asked, so we couldn’t count check-ins that ran, stayed silent or failed. I added agent_core.trigger.product: comms for a mention, automations for a run no post asked for, and nothing for a run the asker starts in a session. Grouping agent_core.trigger.product:automations by agent_core.run.outcome gives the check-ins by outcome.
Why an answer was refused
When code refuses an answer it can’t post safely, the asker gets the failure sentence. The model writes the answer, code delivers it shows that from the asker’s side. For measuring, the reply span said kind: failure and nothing else, so a stray link and a lost source looked the same.
I made each product’s check name the rule that refused the answer, from a fixed list of six, such as html or link_not_allowed. I also added a counter, agent_core.reply.outcome, with the same status, kind, reason and rule, so the share of replaced answers can be followed over time. Neither the span nor the log holds the answer or the link, only the rule’s name.
Keep content out of the logs
Every one of those lines goes through the same logger, which redacts any field whose name looks like a credential or private content: token, prompt, content, output, messages and a few more. Its test logs a line full of both (trimmed):
logger.error('Provider rejected Bearer live-session-token', {
run_id: 'run-1',
access_token: 'oauth-private-value',
tool_payload: { content: 'private thread text', comments: ['private comment'] },
prompt: 'full private prompt',
model_input_tokens: 42,
status: 'failed',
})
expect(serialized).not.toContain('private thread text')
expect(serialized).not.toContain('full private prompt')
expect(JSON.parse(serialized)).toMatchObject({
metadata: { run_id: 'run-1', status: 'failed', model_input_tokens: 42 },
})
The run ID, the status and the token count survive. The thread text, the prompt and the credential don’t.
A rule that matches names will also hide a measurement whose name happens to match. Token metrics leave the service through the log, so gen_ai.token.type was redacted and the input, output and cache series of agent_core.model.tokens looked identical. I allowed that one name, whose values are labels set by code: input, output, cache_read, cache_write. The wait times above were named around the rule: first_answer_ms and first_chunk_ms contain neither token nor output.
The fix that lasts is a test I added when I put the wait times on spans. It writes every attribute name the dashboard reads through the real logger and fails if the line contains [redacted] (trimmed):
const MEASUREMENTS = {
'agent_core.run.first_status_ms': 1_234,
'agent_core.run.first_answer_ms': 5_678,
'agent_core.capture': 'workspace_not_listed',
'agent_core.model.turn.first_chunk_ms': 48_000,
// ...
}
logger.info('OpenTelemetry span ended.', { ...MEASUREMENTS, event: 'otel.span.end' })
expect(record.metadata).toMatchObject(MEASUREMENTS)
expect(lines[0]).not.toContain('[redacted]')
A new dashboard field joins that list, and a name the logger would hide fails in CI instead of on the dashboard.
What I’d tell someone doing the same
- Give a tool’s failure a code, separate from its result. The model needs a sentence it can repeat. Your metrics need a word they can group by.
- Count errors where the model sees them, not where your code throws. The harness refuses calls before any tool runs, and those are the ones that show where the model sends wrong inputs.
- Put waits on spans as plain numbers, and split a slow turn. “Waited for the provider” and “slow to generate” call for different fixes.
- Record which product started a run. One agent behind several products is several workloads.
- Keep labels to fixed names set by code. A rule name, a reason code, a product. Never text the model or the asker wrote.
The trade-off: Datadog shows that code refused an answer for link_not_allowed, not which link. To see the answer itself, someone with access opens the trace in Langfuse, and only for conversations where content capture is on. For everything else, the codes are all there is, so they have to be precise.