Agentic Engineering from First Principles All chaptersLecturesLabDownload the book
Part V · Engineering Reliable Agents

Chapter 23: Observability

Central questionHow do we reconstruct what an agent actually did, and attribute quality, latency, cost and failure to the steps that caused them?

Lecture

Chapter principle

Observe causality, not just activity. A useful agent trace explains which decision caused which work, what that work consumed, how state changed, and where quality or failure emerged.

Key takeaways

Experiments

Every experiment in the book is small, runnable and printed with its real output. In the Lab you can replay a recorded real run of each one, with no programming, and watch what the model and the agent do.

Experiment 41: Tracing an agent run

How do you see which step caused which work?

A real model gets a task: find the price of product X, then add 10%. It can use two tools: a price lookup and a calculator. While the agent works, a tracer records each piece of work as a span: a named step with its duration, its details, and a link to the step that started it. At the end the spans are printed twice: as a tree that follows those links, and as a flat list without them. This is a recorded run of a real model; the times will differ in a new run.

Experiment 42: Adding up cost and time

How much did a run really cost, and what made it slow?

The program makes three real model calls of very different length: a one-word answer, a 40-word answer and a 150-word answer. It times each call and counts its tokens, which serve as the measure of cost because prices change. First it runs the three one after another under a whole-run span that records the total; then it sends all three at the same time. This is a recorded run of a real model; times and tokens will differ in a new run.

All the code for this chapter: github.com/agentic-engineering-book/code

This is Chapter 23 of Agentic Engineering from First Principles: thirty chapters, a case study and fifty-nine executable experiments, from a single model call to controlled, self-improving agents.
Download the bookBrowse all chapters
← Chapter 22: EvaluationChapter 24: Failure and Recovery →