New Tool Radar

AI Agents & Automation

How to Add Structured Logging Fields to Agent Runs

Add structured logging fields to agent runs so every run can be searched by task, tool and outcome.

Schematic with three steps: Fix the field list before the first; Write the fields with every run event; Test by searching for a known failure.

A free-text log line is hard to search: to find every run where a tool failed, you have to read them all. Structured logging fixes that by giving every log line the same fields: run id, task, step, tool, outcome, and time. With those fields, finding the failing runs is a filter, not a reading exercise. LangSmith traces already carry this structure, recording what the agent did step by step, and your own logs should match that shape. Decide the fields once, use them everywhere, and never let a log line go out without the run id on it.

What you need

  • A list of the fields every log line must carry: run id, task, step, tool, outcome, time
  • A logging step that writes those fields with every run event
  • One sample failure to search for, to test the fields on

Step 1: Fix the field list before the first run

Decide the fields and their names: run id, task name, step name, tool name, outcome, and timestamp. Every log line carries all of them, in the same order, with the same names.

Step 2: Write the fields with every run event

At each step, tool call, and outcome, log one line carrying the fields. A line missing the run id cannot be traced back to its run, however detailed it is.

Step 3: Test by searching for a known failure

After a test run, search the logs by tool and outcome for the failure you know happened. If you cannot find it with a filter, a field is missing or misnamed.

Worked example: synthetic structured logging check

The table below is a synthetic example. It shows the expected result of structured logging; no logs were written.

Log line Run id? Tool and outcome?
Step 1, search Yes Yes
Step 2, lookup_order Yes Yes
Step 3, send_message failed Yes Yes
Failure found by filter Yes Pass

Expected result (UNTESTED). every log line carries the run id, tool and outcome, and the known failure is found with a filter. This check was not run live; the table shows the expected result for the synthetic example.

Limits

  • Fields only help if they are consistent; a renamed field splits the search in two.
  • Structured logs still need the message: fields without a readable line are hard to understand.
  • Logging every event costs storage, so log steps and outcomes, not every token.
  • A field that is sometimes empty is a field that cannot be trusted in a filter.

Sources

See all