Station 9 · Testing & Observability
Building an agent is one thing. Knowing whether it actually works — and seeing what it's doing when it doesn't — is a whole separate skill. This is the part that separates a demo from something you'd trust.
What you'll walk away with
Concept 1
A normal program is deterministic: same input, same output, every time. You write a test that says "given 2 + 2, expect 4," and it either passes or fails forever. Agents break both halves of that promise.
A failing agent you can't see inside is a black box — you know it crashed, but not why. Testing and observability turn it into a glass box. Think of a plane's flight recorder: nobody investigates a crash by re-flying the plane and hoping it happens again. They read the recorder — the exact sequence of what the pilot saw and did. Your agent's trace is that recorder.
Concept 2
Because one test isn't enough, you layer several. Each catches a different kind of problem — from "a single tool is broken" all the way up to "the answer is technically correct but unhelpful."
Did it reach the goal? How many steps did it take? How much did it cost in tokens? Slower and pricier over time is a real regression.
Test each tool alone. Does search_web return good results? Does the calculator return the right number? Broken tools mean a broken agent.
Does the agent chain steps correctly end-to-end — search, then read, then answer — without dropping the thread?
A person rates the outputs. Some things ("is this answer actually helpful?") only a human can score reliably.
You don't grade this by hand every time. Eval frameworks automate it — you give them a set of test cases and they score runs for you. A few worth knowing by name: LangSmith, Ragas, and DeepEval.
Concept 3
Observability is a fancy word for "can you see what your agent actually did?" The number-one habit that makes it possible is structured logging & tracing: record every Thought → Action → Observation so you can replay the exact path the agent took.
Log every step. If you save each Thought, each tool call, and each result the agent got back, then debugging becomes reading instead of guessing. You can see exactly which step went wrong — the bad tool result, the wrong turn — instead of re-running and hoping to catch it.
You could write logs by hand, but observability tools capture and visualize traces for you — every step, its tokens, and its cost, laid out as a timeline. Two common ones: Helicone and LangFuse.
# Goal: "How many gold medals did the host country win at the last Summer Olympics?" [step 1] Thought → "I don't know the latest host or medal count. Search." Action → search_web("most recent Summer Olympics host country") Observe → "Paris, France — 2024" · 214 tokens · 0.4s [step 2] Thought → "Now I need France's gold-medal total." Action → search_web("France gold medals 2024 Olympics") Observe → "France won 16 gold medals" · 198 tokens · 0.5s [step 3] Thought → "I have host + count. Answer." Action → finish() · 22 tokens # run summary → steps: 3 · tokens: 434 · cost: $0.006 · goal_reached: true
Concept 4
When an agent misbehaves, the instinct is to immediately start rewriting the prompt. Resist it. The trace already contains the answer to what went wrong — you just have to look.
Tweak the prompt, run again, cross your fingers. With a non-deterministic system you might just get lucky once and never learn the real cause.
Open the log. Find the first step where reality diverged from what you expected. That step — not the final answer — is your bug.
Checkpoint
Your agent gave a confidently wrong final answer. What's the best first move?
Because agents are non-deterministic and multi-step, re-running can accidentally "pass" without fixing anything. The trace is your flight recorder — reading it shows you the exact Thought or Observation where things went wrong, so you fix the real cause instead of guessing.
See it yourself — 5 minutes
Open any AI tool that shows its steps (ChatGPT with browsing, or Claude/Gemini running a multi-step task) and give it a research question it can't answer from memory:
Recap. Agents are hard to test because they're non-deterministic and multi-step, so pass/fail isn't enough. You evaluate them in layers — metrics, unit tests, integration tests, and human review (with frameworks like LangSmith, Ragas, DeepEval). And you make them debuggable with structured logging & tracing — recording every Thought → Action → Observation (Helicone, LangFuse) so a black box becomes a glass box. The habit that ties it together: when it breaks, read the trace first. Next up — the responsibilities that come with letting an agent act on its own.