Lesson 50.3 · 3 of 4 · 4 min read · Reviewed 24 Nov 2026
Reliability and debuggability
By the end, you can
- Weigh reliability and debuggability between architectures.
- Build observability in from the start.
Reliability by shape
| Architecture | Predictability | Typical failures |
|---|---|---|
| Workflow | High | A step’s prompt or tool breaks; easy to find |
| Single agent | Medium | Loops, drift, wrong tool choice (46.3) |
| Multi-agent | Lower | Bad delegation, lost context in handoffs, duplicated work, cost blow-ups |
Make failures visible
- TraceTrace: A record of everything that happened during one request or agent run, as a tree of timed steps. everything: inputs, outputs, tool calls, timings, tokenToken: The unit a model reads and writes: a word, part of a word, a space or a symbol, mapped to an integer id. counts (chapter 67).
- Structured errorsStructured error: An error returned to the model with a type, a message and whether retrying might help.: tools return clear, typed errors so agentsAgent: A system where a model decides its own next steps, calling tools in a loop until the task is done. and people can reactReAct: An agent pattern that interleaves reasoning steps and actions (tool calls), using each observation to plan the next step. (chapter 34).
- Propagate failures: workers report what failed instead of guessing (43.4).
Rules in code
| Rule type | Where |
|---|---|
| “Never do X” | Permissions, or a hook that blocks the call (chapter 44) |
| “Always do X before Y” | Code that gates Y on X’s result (33.5) |
| “Output must be shape Z” | Schema validation and retry (chapter 14) |
| Style and tone | The prompt |
Test it
Agent evalsEval: A repeatable test that measures how well an AI system performs on a set of cases with defined success criteria. (chapter 19) check not just the final answer but the path: did it call the right tools, respect limits, and stop when it should?
Key points
- Fixed workflows are the most predictable; open agents trade predictability for flexibility.
- Every extra agent and handoff adds a place where errors can start or get hidden.
- Debuggability needs full traces: every prompt, tool call, result and decision.
- Put hard rules in code (permissions, validation, hooks), not only in prompts.
Turn a prompt rule into a code gate
Enforce an ordering rule in code and use a full trace to find the run where it would have failed.
You will have: A gated balance tool and a printed trace of the first conversation that tried to skip verification.
Steps
- Run the starter: a few of 500 conversations show a balance without verification.
- Gate get_balance() so it refuses unless the session is verified.
- Run it again and read the trace of the first conversation that tried to skip the check.
- Note how the refusal message tells the model what to do next.
Done when
- The starter leaks a balance in a handful of the 500 conversations.
- The gated version leaks 0.
- The printed trace shows get_balance refused, with no verify_identity before it.
Open in the Playground No API key needed.
Starter code (Python)
# Turn "always verify before showing a balance" from a prompt rule into a code gate, and trace failures.
import random
def simulated_agent(r):
"""The model usually verifies first, but not always."""
steps = ["greet"]
if r.random() < 0.99:
steps.append("verify_identity")
steps.append("get_balance")
return steps
def get_balance(session):
# TODO: gate it in code: refuse unless session["verified"] is True
return "balance: 1,240 credits"
def run(n=500, seed=7):
r = random.Random(seed)
leaks, first_bad = 0, None
for i in range(n):
session, trace = {"verified": False}, []
for step in simulated_agent(r):
if step == "verify_identity":
session["verified"] = True
out = "verified"
elif step == "get_balance":
out = get_balance(session)
else:
out = "hello"
trace.append(f"{step} -> {out}")
if "balance:" in trace[-1] and not session["verified"]:
leaks += 1
first_bad = first_bad or (i, trace)
if "refused" in trace[-1] and first_bad is None:
first_bad = (i, trace)
return leaks, first_bad
leaks, bad = run()
print(f"balances shown without verification: {leaks} of 500")
if bad:
print(f"trace of conversation {bad[0]}:", " | ".join(bad[1]))
Show a solution
# Turn "always verify before showing a balance" from a prompt rule into a code gate, and trace failures.
import random
def simulated_agent(r):
"""The model usually verifies first, but not always."""
steps = ["greet"]
if r.random() < 0.99:
steps.append("verify_identity")
steps.append("get_balance")
return steps
def get_balance(session):
if not session["verified"]:
return "refused: verify identity first"
return "balance: 1,240 credits"
def run(n=500, seed=7):
r = random.Random(seed)
leaks, first_bad = 0, None
for i in range(n):
session, trace = {"verified": False}, []
for step in simulated_agent(r):
if step == "verify_identity":
session["verified"] = True
out = "verified"
elif step == "get_balance":
out = get_balance(session)
else:
out = "hello"
trace.append(f"{step} -> {out}")
if "balance:" in trace[-1] and not session["verified"]:
leaks += 1
first_bad = first_bad or (i, trace)
if "refused" in trace[-1] and first_bad is None:
first_bad = (i, trace)
return leaks, first_bad
leaks, bad = run()
print(f"balances shown without verification: {leaks} of 500")
if bad:
print(f"trace of conversation {bad[0]}:", " | ".join(bad[1]))