r/LangChain • u/Ok_Potential591 • 10d ago
Discussion How do you debug a multi-step AI agent workflow when only the final result is wrong?
/r/u_Ok_Potential591/comments/1y02mw2/how_do_you_debug_a_multistep_ai_agent_workflow/
1
Upvotes
1
u/BraveWillow9801 10d ago
log the output of every step to a file on each run, then diff a good run against a bad one. usually the bad step is the one where the input already looked slightly off.
1
u/oyren-ai 10d ago
langsmith traces fit this: the docs say each model call and tool invocation is recorded as a run, the runs for one operation are collected into a trace, and a trace holds every run with full inputs and outputs. for replaying, langgraph checkpointers save state at each step, and its time travel docs say you can replay from a prior checkpoint or fork one with modified state.
1
u/locbuilds 10d ago
add a schema check right after each tool call so a step that "succeeded" with an empty or wrong-shaped payload fails loudly. most of my silent wrong-answer bugs were a tool returning 200 with garbage that just flowed downstream.
1
u/LLM-logs 9d ago
A practical approach is record-replay bisection. Log the inputs and outputs of every step with run IDs, and when a run goes wrong, replay from the midpoint with the recorded inputs. If the midpoint state already looks wrong, the fault is upstream; if it looks right, the fault is downstream. Two or three rounds of that localize the bad step without reading the whole trace. It only works if steps are replayable, which is its own argument for keeping model calls and side effects behind interfaces you can stub. The schema checks others mentioned pair well with this: they tell you which step, replay tells you why.
1
u/Senior-Assumption864 7d ago
do you save the intermediate state on every run or only when something looks off?