0
Phase 18

Bug Fix Agent

~3 min read

Concept & How It Works

    Why Does It Exist?

    Triage-to-fix is slow and context-heavy. Agents shrink mean-time-to-resolution by systematically exploring the codebase and running the test loop that engineers repeat manually.

    Real-World Analogy

    A detective with a lab: gathers evidence (logs, tests), forms a hypothesis, runs experiments (repro, patch), and presents a case file (PR) — not a guess on the first clue.
    Loading diagram...

    Visual Workflows

    What is Bug Fix Agent?

    Loading diagram...

    Example

    Scenario

    Sentry reports `NullPointerException` in checkout. The agent traces to `CartService.applyCoupon`, adds a null guard test, fixes the bug, runs `npm test`, and opens PR #842 with linked Sentry issue.

    Solution

    In Coding Agents, apply Bug Fix Agent to this scenario: Sentry reports `NullPointerException` in checkout. Identify the inputs, run the technique, validate the output, and note one thing you would monitor in production.

    Practice Task

    Do this before moving to the next module — reading alone is not enough.

    Open the Code Walkthrough below and run it locally. Change one parameter related to Bug Fix Agent (e.g. model, temperature, top_k, or tool name), observe the difference in output, and write 2–3 sentences explaining what changed.

    Code Walkthrough

    Highlighted lines show where Bug Fix Agent happens in the code.

    Bug Fix Agent
    1async function bugFixLoop(errorReport) {2  const context = await gatherContext(errorReport); // stack, files, recent commits3  for (let i = 0; i < MAX_ITERATIONS; i++) {4    const hypothesis = await planner.diagnose(context);5    const patch = await coder.proposePatch(hypothesis);6    const result = await sandbox.runTests(patch);7    if (result.passed) return { patch, testsAdded: result.newTests };  # return the result8    context.failures.push(result.output);9  }10  return { status: "needs_human", context };  # return the result11}

    Commands to Remember

    Commands to Remember

    • pip install openai # code generation and review
    • gh pr create # open a pull request from agent output

    Common Mistakes

    • Treating Bug Fix Agent as a black box without evaluation
    • Ignoring cost and latency in production
    • Skipping error handling for bug fix agent

    Cheat Sheet

    Quick recap — the most important points from this module.

    Cheat Sheet

    quick ref
    • Bug Fix Agent
    • Repro Test
    • Root Cause Analysis
    • Sandbox