AI agent debugging workflow
Use an AI agent to debug by proving the root cause before editing files or guessing fixes. Build a focused loop from symptoms to evidence, patch and regression check.

Put it into practice
What you will produce
A minimal reproduction, an evidence-backed root cause, the smallest fix and a regression check tied to the failure.
- 01
Freeze the failing case
Capture command or interaction, input fixture, observed output, and environment needed to reproduce.
Expected result: Evidence is separated from interpretation.
- 02
Reproduce on the baseline
Run the smallest reproduction before edits and locate the first divergence from expected behavior.
Expected result: A baseline failure and narrowed path are recorded.
- 03
Test one causal hypothesis
Choose the smallest diagnostic that distinguishes the leading cause from alternatives; avoid broad cleanup.
Expected result: Evidence supports or rejects a specific cause.
- 04
Replay the regression after fixing
Apply the smallest proven fix, rerun the original case and nearby checks, then inspect scope.
Expected result: The original failure passes and the correction stays bounded.
A bounded brief for root-cause investigation
Failure:
[exact error and the action that triggers it]
Expected / observed:
[observable expected result] / [reproducible actual result]
Starting state:
[commit, runtime version, relevant configuration names]
Allowed work:
Inspect and reproduce locally. Do not edit files yet.
Return:
1. Minimal reproduction and exact command
2. Evidence with paths, symbols, logs or trace
3. Competing causes tested and ruled out
4. One-sentence root cause
5. Smallest check that would prove a fixFill this brief with a real failure before asking an agent to debug it. Keep secrets and customer data out of the prompt. A convincing explanation is not proof: require a reproducible baseline, evidence that distinguishes competing causes, and a small check that fails before and passes after a later fix.
Acceptance checks
- Evidence is separated from interpretation.
- Evidence supports or rejects a specific cause.
- The original failure passes and the correction stays bounded.
Limits and trade-offs
Changing code before establishing a baseline can hide the cause. Preserve logs and distinguish observed facts from hypotheses.
Official sources
Debug with agents
Related guides
Building AI agents that actually work
Most 'agents' are brittle pipelines dressed up with AI. Here's the anatomy of a reliable agent, three patterns that hold up in production, and when to use n8n vs code.
Everyone is building agents. Most of them break on the third run. One common failure mode is asking the model to handle too many responsibilities without clear checks. Architecture, model behavior and external dependencies can all contribute to failures. Here's what I've learned building agents that actually run week after week. The anatomy of a reliable agent Every agent that works has three parts, and only one of them should involve AI. Trigger something deterministic starts the agent. A schedule, a webhook, a file drop, a form submission. Not "whenever the AI decides it's time." Context the agent gathers what it needs before calling the AI. The document, the data, the user preferences, the constraints. The AI call happens with full context, not halfway through discovery. Action after the AI produces output, something deterministic happens with it. It gets saved, sent, logged, or published. The action step doesn't retry or…
Read the guideClaude Code Subagents: Parallel Agents
Learn when Claude Code subagents help, how to split parallel work, and how to configure a focused custom subagent without creating conflicts.
Subagents are useful when a task can be split cleanly: one agent searches the authentication code, another traces the database path, and the main conversation compares what they found. They add little to "read this file" or to work where every step depends on the same context. Short version: delegate independent research or a separate review when the results are worth the extra context and usage. Give each agent a narrow scope, the files or area to inspect, and a specific report format. Keep dependent work in the main conversation. Claude Code agents vs subagents Claude Code's documentation calls delegated workers subagents and uses Agent for the tool that starts them. When people search for Claude Code agents in this context, they usually mean subagents: workers that handle a delegated task in their own context and return a result to the main conversation. Claude Code's subagent documentation uses this terminology.…
Read the guide