← Back to Blog
How Do I Debug an AI Agent Workflow When the Final Client Deliverable Is Wrong?

How Do I Debug an AI Agent Workflow When the Final Client Deliverable Is Wrong?

November 26, 2026·6 min read

You debug the trace, not the deliverable. The wrong output is the last thing that happened, not the reason it happened, and the reason is usually sitting three or four steps upstream in a handoff nobody looked at. Open the run log, read it in order, and compare what each step received against what it was supposed to receive.

Why Is the Deliverable the Worst Place to Start Debugging?

Because the deliverable is a symptom wearing a costume. By the time a wrong number shows up in a client deck, it has passed through four or five steps, and every one of them said yes.

When I started running agentic workflows inside my own companies, I did what most people do: I reread the bad output and re-prompted the last step. Sometimes that worked. It also taught me nothing, and the same bug came back two weeks later wearing a different shirt.

The fix is structural. Every step needs to write down what it received and what it produced, in a place you can read without asking the model to explain itself. That is the difference between a chat and an AI agent operating system. A chat forgets. An OS keeps receipts.

I run 45 AI employees across my businesses now. When a client deliverable comes out wrong, I do not open the deliverable. I open the run.

How Do I Find Which Step Actually Failed?

Two moves, and you can do both in an afternoon.

The first is replay. Take the recorded input for each step and run that step alone. If a good recorded input produces a bad output, the step is broken: the prompt is wrong, the tool is wrong, or the model is wrong. If that same input produces a good output, the step is fine and your handoff is broken. That one distinction kills most of the guessing.

I have been teaching people how software breaks since 1998, and the instinct never changes: you find the boundary where good data turns into bad data.

The second move is bisect. Cut the pipeline in half, run the first half, and look at the artifact at the midpoint. Does it look like something a competent junior would hand you? If yes, the bug is downstream. If no, it is upstream. Keep halving. Five steps takes three runs.

You need a trace to do either one. Langfuse, LangSmith, and Braintrust all handle this. So does a boring Postgres table with columns for runid, step, input, output, modelversion, and timestamp. The boring one is what I started with, and I still trust it more. Most AI for founders and operators fails at the seams between steps, not inside the model, and the seams are only visible if you logged them.

If you cannot print the exact input a step received, you are not debugging an AI agent workflow. You are guessing with extra steps.

Why Is the Failure Usually Context, Not the Model?

What's becoming clearer to me the longer I do this: almost no step fails because the model is dumb. Steps fail because they got the wrong context, too much context, or context from last Tuesday.

Context engineering for founders comes down to three rules. Name every source explicitly in the prompt so the step knows which pricing sheet, which client, which document. Cap the size so you know what got cut. Pin the version so a document edit does not silently change yesterday's output.

I watched a proposal step pull the wrong pricing sheet because two clients had similar names and the retrieval matched on the wrong one. The model did exactly what it was told. The context was a lie.

Truncation is the silent version. If a step takes 40,000 tokens of context and your retrieval or model window cuts at 8,000, the step will happily invent the rest and sound confident doing it. Log token counts per step, not just text.

Build a context envelope for every step. Client name, document ids, retrieved chunks, timestamp, prompt version. Print it in the trace. If it is not printed, it is not real.

What If the Failure Only Happens Sometimes?

Nondeterminism. Annoying, and the hardest kind to debug because your replay will not reproduce it.

Set temperature to 0 for any step that extracts or transforms data. Log the full model version string, not the model name, because providers update models under the same name and your workflow changes underneath you. Log timestamps, because half of intermittent bugs are a tool call that timed out and returned an empty result nobody checked.

Then run the same step 20 times on the same input. If it fails 2 out of 20, you have a flaky step with a real bug. If it fails 0 out of 20, the step is fine and the problem is in the handoff. Go back to bisect.

After you fix it, save the failing input as a test case. Every bug becomes a permanent test. Before I ship any change to a workflow that touches client work, I run the whole eval set. It takes a minute, and it has saved me more than one Friday.

FAQ

How long should debugging an agent workflow take?

An afternoon if every step is instrumented, a week if it is not. That ratio is why I instrument first and build second now, even when it feels slow. The first wrong client deliverable pays for the logging ten times over.

Do I need a tracing platform?

No. One JSON file per run, written at every step, is enough to debug most failures. Platforms like Langfuse and LangSmith save setup time and give you a UI, and I use them. But the platform is not the point. The trace is.

Should I just switch to a better model?

Not as a debugging strategy. Most wrong deliverables come from bad inputs, bad context, or a step that swallowed an error and returned nothing. A better model will fail on those inputs more fluently, which is worse, because now the client believes it.

Debugging gets a lot easier when the workflow was built to be debugged. If you want the architecture I actually use, the one where every step logs its context and every failure becomes a test, I wrote the full playbook for this. How to Build Your Own AI Agent Operating System walks you through the exact architecture I use, step by step. You can get it at a.mastermindshq.business/ai-os-book.

Build your AI operating system from the book

Get Joe Che's AI OS book and turn these ideas into a practical operating system for your work.

Prefer to build it live with Joe? Join the AI Business Mastermind