AI Code Review Automation: How to Build Agents That Review, Fix, and Approve PRs
As AI coding assistants take over most code writing, the real bottleneck in software delivery has shifted to everything that happens after a pull request is opened. This article breaks down an automated PR pipeline built from three single-purpose agents: a read-only review agent that scans diffs in parallel and filters false positives, a fix agent that rebuilds context and iterates on patches with a circuit breaker, and an approval agent that enforces declarative admission rules. It also covers severity levels, review depth configuration, and the cloud capabilities needed to run the system in production.
Introduction: Code Generation Is No Longer the Bottleneck, So What Comes Next?
Over the past year, the capability boundary of AI coding tools has shifted dramatically. Coding assistants built on advanced large models can now independently write the vast majority of business code. Yet a counterintuitive pattern is spreading across engineering teams: code is being written faster, but requirement delivery has not accelerated at the same pace.
The reason is not complicated. The traditional software delivery process was designed around the assumption that humans write the code. After a developer opens a pull request (PR), they move on to the next task; when review feedback comes back, they have to interrupt their current work, reload the context, modify the code, push the commit, and wait for another review round. Finally, someone with the right permissions has to click approve. In the era of manual coding, this asynchronous collaboration model worked fine, because writing code was itself the most time-consuming step.
Once code is primarily generated by AI tools, however, the bottleneck moves to the stretch of road after the PR is opened. The industry is starting to explore a new approach: an automated delivery pipeline built on multi-agent collaboration, where AI not only writes code but also reviews, fixes, and approves it. This article uses that technical paradigm as a starting point to systematically unpack the architecture, capability boundaries, and engineering considerations of an automated PR processing system.
Overall Architecture: Three Agents Chained into One Delivery Pipeline
A complete automated PR processing system is typically made up of three agents with single responsibilities and clear state transitions, chained together. They are not simply a pile of features stacked on top of each other; they mirror the review loop of a human team.
1. Code Review Agent: Multi-Dimensional Scanning and False Positive Filtering
The review agent is the entry point of the entire pipeline. Its core task is to find potential defects in the diff and the surrounding code. To balance coverage and accuracy, the engineering implementation usually adopts a strategy of “parallel scanning plus cross-validation”:
- Parallel analysis: Launch multiple sub-agents that inspect the changes from different perspectives (such as logical correctness, boundary conditions, concurrency safety, and resource release) at the same time.
- Validation and filtering: Suspected issues produced by each sub-agent go through an independent validation step to filter out false positives, so noise does not drown out real risks.
- Ranking and publishing: Issues that pass validation are deduplicated and sorted by severity, then anchored to specific lines of code as inline comments.
Severity is generally divided into three levels, which form the key contract between automated review and human collaboration:
| Level | Meaning | Recommended Action |
|---|---|---|
| Important | A defect that must be fixed before merging | Block the merge and trigger the fix agent |
| Nit | A minor issue that does not affect functionality | Suggested fix, does not block by force |
| Pre-existing | An issue left over in existing code | Notice only, not counted against this PR’s quality |
Review depth is usually offered in three tiers: fast, standard, and deep, configurable per repository. The default strategy focuses on real bugs that affect production, rather than formatting preferences or test coverage. If a team has specific requirements, it can maintain a review guideline file at the repository root (such as REVIEW.md) declaring constraints on framework choices, logging conventions, or security red lines.
A high-quality review comment should contain three elements: what the problem is, under what conditions it is triggered, and how it is recommended to be fixed. For example, when handling rate-limiting retry logic, the review agent might point out that the Retry-After response header may be a number of seconds or an HTTP date, or may even be missing; parsing it directly as a numeric value would break the wait-time calculation and trigger dense retries against a server that has already rate-limited the client.
The capability boundary that must be made clear is that the review agent is read-only. It does not build or run code, and it has no authority to approve or block a PR. Its output is “high-confidence opinions,” not “administrative decisions.”
2. PR Butler Agent: Context-Aware Automatic Fixes
The fix agent addresses the pain point of review feedback interrupting a human’s flow. Once the review agent flags an Important-level issue, the butler agent steps in to make the change.
The technical difficulty here is not generating a patch, but rebuilding context. The agent needs to understand the PR’s original intent, what the review comment specifically points at, and the calling conventions of the surrounding modules. A typical fix loop looks like this:
while unresolved Important comments exist:fetch comments and the corresponding code contextgenerate a minimal-change patchpush the committrigger a new review roundif the issue is downgraded or resolved -> exit the loopif the number of rounds exceeds the threshold -> escalate to a human
A circuit breaker is mandatory here. The last thing automated fixing needs is an infinite recursion of “fix one bug, introduce another, fix the new one.” In engineering practice, the maximum number of iterations is usually capped (for example, three rounds); once exceeded, the task must be handed to a human, with a clear summary of the failure reason left in the PR.
3. Rule-Based Approval Agent: Encoding “Who Can Approve” as Policy
The approval agent is the highest-risk step, and the one that best reflects the human-machine boundary. Its core is not to have AI make subjective judgments, but to execute the admission rules the team has agreed on in advance.
Rules are usually encoded as declarative policies, for example:
- All CI pipeline statuses are green;
- There are no unresolved Important comments;
- The changed files do not touch protected directories (such as authentication or core billing modules);
- The submitter has write permission on the corresponding repository;
- The automatic fix rounds have not tripped the circuit breaker.
Only when all conditions are met does the approval agent approve as a bot and move the PR into the queue awaiting merge; if any condition is not met, the PR stays blocked and the responsible person is notified. This design turns “approval” from an act of interpersonal trust into an auditable, versionable policy execution.
The three agents support independent on/off switches and can be rolled out gradually at repository granularity, which makes progressive adoption easier for teams.
Engineering Recommendations from the Baidu AI Cloud Perspective
In Baidu AI Cloud’s practice of supporting enterprise R&D efficiency improvements, this kind of automated delivery system typically requires the support of several general-purpose cloud capabilities:
- Container platform: Provides elastic compute for the review and fix agents, scaling out and in based on PR events to avoid wasting always-on resources.
- Object storage: Archives the diff snapshot, comment records, and fix patches from each review to meet audit and traceability needs.
- Message queue: Decouples code hosting platform events from agent tasks, smoothing out spikes so the system stays stable when a batch of PRs floods in during a major promotion.
- Logging, monitoring, and alerting: Builds dashboards for the agents’ false positive rate, fix success rate, and average review latency, with alerts when something goes wrong.
Three principles are recommended when rolling this out: first, read-only before write, running the review agent in shadow mode to build trust; second, low-risk repositories before core repositories, using configurable rules to control the blast radius; third, keep human veto power, since any automated pipeline must provide a one-click takeover entry point.
Conclusion
Having AI review, fix, and approve PRs is essentially about handing the friction cost of “waiting and context switching” in software delivery over to machines. The review agent finds risks, the butler agent removes them, and the approval agent lets changes through within the rules. Working together, the three compress asynchronous waiting that used to take hours into a closed loop measured in minutes. For R&D teams, the real competitive edge is no longer who writes code faster, but whose delivery pipeline is smarter and more controllable.
