Skip to content

Debug an agent from its trace while the interviewer watches

Given a trace of a run that went wrong, read forward to the first step whose input does not support its output, name the failure class, and propose two things: the fix in the harness or tool, and the evaluation case that would catch it again. Say each hypothesis out loud before checking it.

21 MIN

By AIAgentInterviews · Updated

TL;DR: Read the trace from the top and stop at the first step that its inputs do not justify. Name the failure class (ignored error, repeated call, claim without evidence, wrong target), fix it where the model cannot override the fix, and turn the trace into an evaluation case. Narrate each hypothesis before you check it.

Where you are. Module two, lesson two. You can build an agent. This round gives you someone else's broken one.

The shape of a debugging round

A debugging round hands you evidence and asks what went wrong: a trace, a log, a transcript, sometimes code and a failing evaluation. It tests whether you read evidence in order, form hypotheses you can check, and fix causes rather than symptoms. This lesson assumes a printed or shared trace of one run and about thirty minutes. With code and a test suite instead, the method is the same; the evidence is different.

In plain language. A hypothesis predicts what evidence you should find if a cause is true. A symptom is the observed failure. A minimal reproduction retains the conditions needed to cause it while removing irrelevant detail.

Read forward, stop at the first unsupported step

The temptation is to jump to the final answer, because that is where the visible damage is. Resist it. The final answer is usually the last link in a chain, and fixing it alone (with a prompt instruction, for example) leaves the cause in place. Start at the top and ask of each step: do the inputs to this step support what it did?

Here is a trace from a support agent asked about a refund, and a check that does what you will do by eye.

import re

TRACE = [
    {"step": 1, "kind": "tool", "name": "ticket_get", "args": "T-88",
     "result": "customer=Ines refund_id=RF-31 status=pending"},
    {"step": 2, "kind": "tool", "name": "refund_status", "args": "RF-31",
     "result": "error: timeout after 5s"},
    {"step": 3, "kind": "tool", "name": "refund_status", "args": "RF-31",
     "result": "error: timeout after 5s"},
    {"step": 4, "kind": "answer",
     "text": "Hi Ines, refund RF-31 was paid on 21 November."},
]

def anomalies(trace):
    found, seen = [], set()
    results = " ".join(e.get("result", "") for e in trace)
    for e in trace:
        if e["kind"] == "tool":
            key = (e["name"], e["args"])
            if key in seen:
                found.append(f"step {e['step']}: repeated {e['name']}")
            seen.add(key)
        if e["kind"] == "answer":
            last_tool = [x for x in trace if x["kind"] == "tool"][-1]
            if last_tool["result"].startswith("error"):
                found.append(f"step {e['step']}: answered after an unresolved error")
            for claim in re.findall(r"\b(paid|\d{1,2} [A-Z][a-z]+)\b", e["text"]):
                if claim not in results:
                    found.append(f"step {e['step']}: '{claim}' not in any tool result")
    return found

found = anomalies(TRACE)
print(found[0])  # => step 3: repeated refund_status
print(found[1])  # => step 4: answered after an unresolved error
print(len(found[2:]), found[3])  # => 2 step 4: '21 November' not in any tool result

Out loud, the reading goes like this. Step one is fine: the ticket lookup used the ticket id and returned a pending refund. Step two timed out; that is the environment, not the agent. Step three retried the same call once, which is reasonable. Step four is the first unsupported step: the agent told the customer the refund was paid on a specific date, and nothing in any result says "paid" or gives a date. The only evidence says pending. The agent filled the gap left by the error with a plausible answer.

Name the class, then fix it where the model cannot argue

The failure class is "answered after an unresolved error", which produced a "claim without evidence". Naming the class matters because the fix belongs to the class, not the instance. Three fixes, in order of strength:

  • The tool result for a timeout says what the model may and may not say: {"error": "timeout", "status_unknown": true, "hint": "Tell the customer the status could not be checked and will follow up."}.
  • The harness checks the final answer against tool results before sending: specific claims (amounts, dates, statuses) must appear in some result, or the answer is held for a person. That is the check in the code above, made strict.
  • The step limit and retry policy give the status tool a longer second attempt, because an identical retry the moment after a timeout often meets the same slow service.

A prompt instruction ("never guess the refund status") can go in too, but say out loud that it is the weakest of the four, because the model can ignore it in exactly the situation it is meant for.

Trace
T-88: the first unsupported step is the answer
  1. 01toolticket_get(T-88 -> RF-31 pending)
steps 0tool calls 1writes 0context 0 tok
1/3

Step 1 is supported

The ticket says refund RF-31 is pending.

End with the evaluation case

The last thing to say is how this stays fixed. The trace becomes an evaluation task: a scripted run where the status tool times out, graded on whether the final answer avoids claiming a status. It joins the incident cases with zero tolerance. Offer the evaluation case even if the interviewer seems ready to move on once you state the fix: it shows you think about the next release as well as this one.

Thinking out loud, usefully

Say each hypothesis before you check it ("I think the error was ignored; checking whether the answer contains anything the results don't"), and say what would prove it wrong. If a hypothesis fails, say so and move on. The interviewer is assessing your method as much as your conclusion, and an abandoned hypothesis stated clearly is evidence of method.

Test two explanations for the same bad answer

A synthetic trace ends with “Your booking is confirmed,” but the booking tool returned pending. Two hypotheses fit the symptom: the completion checker accepts pending receipts, or the adapter converted pending into completed before the checker saw it.

Do not change the prompt yet. Inspect the raw tool result, the normalized adapter output and the completion decision for the same operation ID. If the adapter output already says completed, the first corrupted boundary is the adapter. If it preserves pending and the checker accepts, the checker is responsible.

EvidenceWhat it distinguishes
Raw result paired with call IDService observation
Normalized result and revisionAdapter interpretation
Completion predicate resultHarness decision

Create a minimal fixture with one pending receipt and one final completion proposal. It should fail the incorrect claim without requiring a live service or a nondeterministic model. After fixing it, add a completed-receipt fixture so the repair does not block all answers.

Explain the limits of your diagnosis. If raw results were not recorded, the available trace may not distinguish the two causes. Name the missing observation and the instrumentation needed rather than inventing certainty.

What if · interview follow-ups

Change one condition

The final answer claims confirmation while the service observation is pending.

  1. Start here

    Should you start by telling the model to be more careful?

Do this before moving on

Take a trace from your own agent where the outcome was wrong, or write one in the format above. Give yourself twenty minutes: read it forward, find the first unsupported step, name the class, write three fixes in order of strength, and write the evaluation case. Say it aloud, or to a colleague, while you do it.

Review your result. State each hypothesis before inspecting its evidence. Deliver a minimal failing fixture, the corrected boundary and a valid case that still passes. Explicitly label any unresolved causal ambiguity.

Go deeper

Key takeaways

  • Read the trace forward and stop at the first step its inputs do not support.
  • Name the failure class and fix the class, strongest fix first, prompt instructions last.
  • Turn the trace into an evaluation case so the fix stays fixed.
  • State each hypothesis and what would disprove it before checking.

Check yourself

Answer aloud or on paper before revealing. Producing the explanation unaided is exactly what a panel listens for.

  1. 1The final answer contains a claim no tool result supports. Where should you start reading the trace?

  2. 2Rank these fixes for 'answered after an unresolved error' from strongest to weakest: a prompt instruction, a final-answer check against tool results, an error result that says what may be claimed.

  3. 3You have stated the fix and the interviewer looks ready to move on. What is worth adding?

Sign in to track which lessons you have finished.