Chapter 19: Step logging

Write one JSON line per model call and per tool call. Each line holds the run id, step number, kind, tool name, arguments, token counts, duration, and stop reason. A failure is easy to find when you search by run id.

Figure 19.1. Both kinds of call write to the same log. Because every line carries the run id, one search returns the whole run in step order.

An illustrative pair of lines, one per kind. The field names are an example; the chapter fixes the content, not the spelling.

{"runId":"run-42","step":1,"kind":"model","tool":null,"args":null,"tokensIn":812,"tokensOut":41,"durationMs":930,"stopReason":null}
{"runId":"run-42","step":1,"kind":"tool","tool":"countErrors","args":{"service":"checkout","minutes":15},"tokensIn":0,"tokensOut":0,"durationMs":4,"stopReason":null}
docs