What they’re really asking
If you only remember one thing, say this in the first minute: “First I map each box in the diagram to the function that implements it. Then I run one scripted conversation per path in the diagram, using a fake model that returns fixed outputs, so failures are repeatable and point me at a file. Then I check the boundaries where agent code usually breaks: the output format the parser accepts, whether tool results reach the next prompt, whether every branch ends, and whether the hand-off can fire. I fix in code, add a test per fix, and narrate as I go.”
The rest of this page explains each part of that answer.
You get a small codebase that implements an AI agent, a diagram of how it should behave, and a timer. Your job is to find where the code and the diagram disagree.
Why is this different from debugging an ordinary service? An agent is a loop around a large language model
(LLM), a program that reads text and writes text. Each round, the code sends the model the conversation so far;
the model replies either with an answer or with a tool call, a structured request such as
{"tool": "lookup_order", "args": {"id": 42}}. The code runs the tool, adds the result to the conversation, and asks
again.
Two things make this hard to debug. First, a real model gives different output each run, so a bug may not repeat. Second, many bugs live at the boundary between the prompt (the text instructions telling the model what format to use) and the code that parses the reply. Neither side looks wrong on its own. Both have to agree.
A first-hand Sierra account describes “a small codebase (around 4-5 files) that implements an agent”, a diagram of how it should work, and “about 3 bugs to find”, run and iterated in a CoderPad terminal gaijineer.co. Speed matters, and so does saying what you check before you change anything.
Clarify first
- Is the diagram the source of truth when code and comments disagree? “I’ll assume yes.”
- Can I run the agent, and is the model real or scripted? If real, ask: “Can I use a fake model for repeatable tests?”
- Are there tests? “If not, I’ll write one per diagram path.”
- Do bugs include prompt problems, or only code? “I’ll assume both are fair.”
Answer
Words you need first
- Fake (scripted) model: a stand-in for the LLM that returns fixed outputs you choose, like a mock in a unit test. It makes every run identical and costs nothing.
- Observation: the tool’s result, added back to the conversation so the model sees it on the next call.
- Hand-off: passing the conversation to a human agent.
- Format contract: the agreement between the prompt (“reply with this JSON shape”) and the parser that reads the reply.
The agent you are reading
A typical diagram, with the boundaries worth checking marked:
receive message
│
▼
build prompt ── system prompt + history + tool results ◄── (B) is the observation added, with the right role?
│
▼
call model
│
▼
parse reply ── answer? tool call? hand-off? ◄── (A) does the parser accept the prompt's format?
│
┌────┼─────────────┐
▼ ▼ ▼
answer call tool hand off ◄── (D) can this branch fire?
│
▼
observe result ── update state ── loop back to build prompt ◄── (C) does every branch reach a stop?
Step 1: map the diagram to the code (first five minutes)
For each node in the diagram (receive message, decide, call tool, observe, answer, hand off), find the function that implements it. Missing or extra branches show up right here. Say: “Before I change anything, I want to know where each box lives.”
Step 2: run one scripted conversation per path
With a fake model returning fixed outputs, run each path: a direct answer; a tool call then an answer; a tool error; a hand-off; a repeated tool call. A failing path points you at a file before you read line by line.
Step 3: check the boundaries where agents usually break
- (A) Format contract. Does the parser accept exactly what the prompt asks the model to write?
- (B) Observation plumbing. Is the tool result added to the context, with the right role, before the next call?
- (C) Termination. Does every branch reach a stop: answer, hand-off or budget? Is a loop limit an exception instead of the diagram’s hand-off?
- State updates. Is state updated on failure, or only on success? Is the same content sent twice?
- (D) Reachability. Can the hand-off branch actually fire?
Follow one debugging session through it
The agent-framework lab has real versions of these bugs, so it makes a good worked example. The clock is illustrative:
| Clock | What you do | What you find | What to say in the interview |
|---|---|---|---|
| 0–5 min | Map diagram nodes to functions. | The loop, a parser, a tool registry, memory. | ”I’m mapping boxes to functions before reading closely.” |
| 5–10 min | Script a fake model that returns a tool call in the exact format the system prompt asks for: {"type":"function","function":{...}}. | The tool never runs. The raw JSON comes back to the user as the answer. | ”The tool path fails, so I’m looking at the parser.” |
| 10–15 min | Read the parser. | Its regex can’t match nested braces, so every tool call falls through to “treat output as answer”. | ”The prompt and the parser disagree about the format. Neither looks wrong alone.” |
| 15–20 min | Fix with a real JSON parser (for example json.JSONDecoder.raw_decode), add a round-trip test. | The tool path passes. | ”This test would have stopped the bug shipping.” |
| 20–25 min | Script a model that asks for the same tool every time. | The loop ends in a MaxStepsExceeded exception, not a hand-off, after all ten steps. | ”The diagram says hand off; the code crashes. And there’s no repeated-call check.” |
| 25–30 min | Read how the async agent builds its prompt. | It sends a separate history string as well as the memory, so the prompt carries the same content twice. | ”Same content twice wastes tokens and confuses the model.” |
In that lab, the format bug is how 2 of its 15 tests fail.
Step 4: fix, then prove
Fix in code first. Add a test per fixed path, rerun all paths, and say what you’d add to the regression test set. Change the prompt only when the prompt is the actual bug. Narrate as you go: interviewers can credit a method even if the third bug runs out the clock.
Senior vs Staff
Debugging against a diagram
Senior
- Maps nodes to code, runs a scripted path per branch, and finds format, plumbing and termination bugs.
Staff
- Also names the missing guardrail that let each bug ship (a format round-trip test, a path test) and adds it.
Small-team version
On a small team, this is how you review an agent that a coding assistant generated. Write the scripted-model path tests first, because they catch the bugs that look fine on a read-through.
Keep a fake-model harness in the repo, so every prompt or parser change runs all the paths in CI. It costs no tokens, because no real model is called. Say: “One round-trip test of the tool-call format is the cheapest insurance an agent codebase can have.”
Pitfalls
- Reading every file top to bottom before running anything. The clock runs out; a failing path would have pointed you at the right file.
- Changing the prompt to fix a parser bug. The model may comply today and drift tomorrow; the parser is still wrong.
- Fixing a symptom without a test that reproduces it. You can’t show it is fixed, and it can come back.
- Going quiet. The round grades the method you narrate as much as the bugs you find.
Go deeper
- Family walkthrough: Customer-facing support agent, “Debugging the agent against its flow”.
- Rehearse on Build Your Own Agent FrameworkPartial: two of its three failing tests come from the format-contract bug above (the third is a sandbox import problem).
- Related: eng-029, an agent that loops forever.