Building a Multi-Agent Workflow for Automated Bug Fixing with CrewAI

luyisi Beginner 5/11/2026 199 views 3 likes 3 min read

Cursor is great for one-off fixes, but when you're dealing with a backlog of 50+ Jira tickets, manually prompting an LLM for every single bug is a bottleneck. I've spent the last month moving my bug-triage process into a CrewAI workflow to automate the "reproduction -> fix -> verify" loop.

Building a Multi-Agent Workflow for Automated Bug Fixing with CrewAI

The core idea is to stop treating the AI as a chat window and start treating it as a pipeline of specialized roles. I set up three distinct agents: the Bug Analyst (reads the issue, finds the relevant files), the Developer (writes the fix), and the QA Engineer (runs the tests and rejects the PR if it fails).

The biggest "gotcha" I hit early on was the Developer agent hallucinating file paths. To fix this, I stopped letting the agents "guess" where the code lived. I built a custom tool using grep and ls that the Analyst must use to provide the Developer with absolute paths.

Here is the basic structure of the crew configuration:

from crewai import Agent, Task, Crew, Process
from my_tools import SearchCodeTool, WriteFileTool, RunTestTool

analyst = Agent(
    role='Bug Analyst',
    goal='Locate the exact lines of code causing the reported bug',
    backstory='Expert at navigating complex codebases and tracing stack traces.',
    tools=[SearchCodeTool()],
    verbose=True
)

developer = Agent(
    role='Senior Dev',
    goal='Implement the minimal fix required to solve the bug without regressions',
    backstory='Pragmatic coder who hates over-engineering.',
    tools=[WriteFileTool()],
    verbose=True
)

qa = Agent(
    role='QA Engineer',
    goal='Verify the fix by running the test suite and checking for side effects',
    backstory='Pedantic tester who finds every edge case.',
    tools=[RunTestTool()],
    verbose=True
)

To make this actually work in production, I had to implement a strict "Review Loop." In CrewAI, you can set process=Process.sequential, but for bug fixing, you need a conditional loop. If the QA agent's output contains "FAILED", the task needs to be kicked back to the Developer. I handled this by wrapping the Crew execution in a while loop that checks the final output for a "PASSED" flag.

My current config for productivity gains:

Memory management: I enabled memory=True in the Crew setup. This is crucial because the QA agent needs to remember why the Developer made a specific change to avoid suggesting "fixes" that break the original intent.

LLM Selection: I use Claude 3.5 Sonnet for the Developer agent because its coding reasoning is leagues ahead of GPT-4o for complex refactors. For the Analyst, I use GPT-4o-mini since it's faster and cheaper for just scanning file lists.

Prompting the Developer: I found that telling the agent to "be concise" wasn't enough. I added a system instruction: Only modify the lines necessary for the fix. Do not reformat the entire file or change indentation of unrelated blocks. This prevents the massive, noisy diffs that make PR reviews a nightmare.

The workflow looks like this:
1. The Analyst receives a GitHub Issue URL.
2. It searches the repo and outputs: File: src/auth.py, Line: 42, Reason: Null pointer on session expiry.
3. The Developer applies the fix.
4. The QA agent runs pytest on the affected module.
5. If it fails, the output is fed back to the Developer.

This setup has cut my manual triage time by about 60%. It doesn't replace the human dev—I still review every PR—but it means I start my morning reviewing solved bugs instead of hunting for where the bug actually is.

All Replies (0)

No replies yet — be the first!

Write a Reply

Markdown supported