Build guide
How to Build a Pull Request Review Agent
Build a pull request review agent by giving it the diff, the repo's rules, the test status and your review criteria. By default it should comment on risks instead of rewriting the pull request, and a person should still decide what merges. Check what Bugbot and PR Routing & Approval already cover before you build.

On this page
How do you build a pull request review agent?
A pull request review agent starts from a clear trigger and ends with a handoff a person can check. The steps below cover that path, and the code shape after them lists the fields one run needs.
- 1Define the trigger: issue, PR, failed CI job, docs change or support ticket.
- 2Limit tool access to the files and systems the agent needs.
- 3Add a plan step before writes.
- 4Run checks and produce a short reviewer handoff.
- 5Log the prompt, changed files, commands and result.
type AgentJob = { task: string; context: string[]; allowedTools: string[]; checks: string[]; handoff: "diff" | "comment" | "pull_request"; };
Decide allowedTools first. While you build, broad access is tempting, because narrowing it is fiddly and everything works when you are watching. An agent that runs unattended with write access to the whole repo and a shell is a different kind of risk from one that can edit three paths and run a single command. You find out which one you built on the run where something goes wrong.
handoff decides whether people will trust the agent. For an agent that changes code, returning a diff keeps a person in front of every change before it lands, which is the right default while you learn how the agent behaves on your codebase. A pull request keeps the same gate with less friction once you have more confidence in the agent.
A comment is the lightest handoff and suits agents that only diagnose. Whichever you choose, don't let the agent merge until the commands in checks are ones you would have run yourself.
Interactive diagram. Step through it with the Next and Previous controls below, or Tab to a region to read its detail.
A review agent points the reviewer to risk and proof. The reviewer still decides.
This exact topic is a hands-on Lesson: Review, verify & guardrails — about 5 minutes, free to read.
Rather do it than read about it? Run 11 interactive Cursor walkthroughs in a simulated editor. Free, no account needed.
What can go wrong?
Most failures here are ordinary. The agent gets too much room, or someone trusts a "done" that no test proved.
The agent touches files outside the task.
The handoff says done without test or review proof.
The agent gets broad access when narrow access would work.
Scope problems show up first. Give an agent a vague task and it will find related work to do, which looks like initiative until you face a diff across twenty files and can't tell which changes were the point. Narrow the task instead: name the files, name the behavior that should change and say what is out of bounds. A stronger model won't solve a scope problem.
Weak checks show up last and do the most damage. An agent reports success from its own reading of its own work, and nothing outside it says otherwise. If the agent's summary is the only thing between its work and your main branch, you have no review step. Give it a command whose exit code you trust, and fail the run when that command fails.
Should you build this when Bugbot already reviews PRs?
Check what Cursor already ships before you build. BugbotCursor's automated PR reviewer that posts inline findings and can push fix commits from isolated VMs. Press Enter for the full definition. reviews pull requests for bugs, and a side project is unlikely to beat a shipped product at generic bug-finding on a diff.
Routing ships too. PR Routing & Approval, which you set up in Automations, assigns reviewers based on code ownership and commit history. It can also approve low-risk pull requests that meet criteria you write. Cursor says it does not replace a full code review.
Build only what those products don't cover. BugbotCursor's automated PR reviewer that posts inline findings and can push fix commits from isolated VMs. Press Enter for the full definition. and Automations aren't included on Free, Plus or the legacy Start plan, so on those plans the whole build is yours. PR Routing & Approval supports GitHub and Origin repositories only, so a team whose code lives elsewhere still has to build its own routing. Both products also take rules and criteria specific to your repository, so read their settings before you decide that a check needs custom code.
Whatever you build, plan the delivery. Findings that live only in a comment thread go stale. A tool or MCPModel Context Protocol. A standard that lets an AI agent pull in context from outside the repo, like Jira tickets or internal docs. Press Enter for the full definition. server that files them in Slack or your issue tracker is a small piece of plumbing, and it decides whether anyone acts on them at all.
What should the agent hand back so a reviewer uses it?
A short comment that points at the risk and at the proof, and by default nothing else. An agent that rewrites the PR hands the reviewer a second diff to review on top of the first.
Give yourself a way to tell whether the agent is working. Cursor's Security Agents track three numbers: vulnerabilities found, issues fixed and a resolution rate. To decide whether an issue was fixed, Cursor has a model review the incremental diffs. Copy that shape, even crudely: log each finding, look at the next push and count what got addressed.
Watch the share of comments that lead to a change, not the number of comments. A review agent whose findings nobody resolves is spending usage without improving the code.
Should it trigger on the pull request or before the push?
Start with the pull-request trigger. It covers every pull request opened in the repo itself and doesn't depend on anyone remembering to run it. Pull requests opened from forks are the exception: pull request triggers don't run on them. A pre-push run is cheaper, but anyone can skip it, so it makes a good habit and a weak guarantee.
Filter the trigger either way, so a run doesn't fire on every pull request in the repo. On GitHub, a Pull request label changed trigger runs only when a specific label is added or removed, which lets reviewers opt a pull request in.
The governance line matters more than the code. Don't let an automation merge on its own: have its code change arrive as a pull request that a person reviews, so whoever clicks merge is accountable for it. The new exposure is who can start a run. Don't wire a code-touching automation to an audience you wouldn't give write access to the repo.
On a team, check the automation's Share settings as well. Run as decides whether it works with your credentials or as its own service account, and Access decides who can view it or edit it.
If you build on the SDK instead of Automations, change the defaults first. A local SDK agent runs every tool call without restriction, because a headless run has nobody to approve it. Turning on local.sandboxOptions keeps its shell commands' writes inside the working directory and temp folders, and blocks outbound network unless you allow a host. Turning on local.autoReview routes tool calls through Cursor's Auto-review classifier, which Cursor calls best-effort and not a security boundary. Keep the human review before merge either way.
Frequently asked questions
Who is this guide for?
AI engineers and developer experience teams who are building pull request review automation for their own repos.
What should I do next?
Start small: one pull request trigger, read access to the diff and a comment as the handoff. Track how many of its comments lead to a change before you give it more access.
Should I build a review agent if Bugbot already reviews pull requests?
Check first. Bugbot reviews pull requests for bugs, and PR Routing & Approval assigns reviewers and can approve low-risk pull requests that meet criteria you write. Free, Plus and the legacy Start plan include neither Bugbot nor Automations. Build only what those products don't cover, such as routing for repositories hosted outside GitHub and Origin.
What should a pull request review agent hand back?
A short comment that points at the risk and at the proof, and nothing else by default. An agent that rewrites the pull request hands the reviewer a second diff to review. Track the share of its comments that lead to a change.
Should the review agent run on the pull request or before the push?
Start with the pull request trigger. It runs on every pull request opened in the repo itself, though not on pull requests from forks. A pre-push run is cheaper, but anyone can skip it.
Sources & last verified
- Cursor agent best practices
- Cursor Learn: working with agents
- Cursor Learn: context
- Cursor docs: prompting agents
- Cursor docs: PR Routing and Approval
- Cursor docs: Bugbot
- Cursor docs: Automations
- Cursor docs: Models and pricing
- Cursor docs: Legacy Cursor plans
- Cursor docs: Security Agents
- Cursor TypeScript SDK
Cursor ships frequently. Facts verified against primary sources on October 28, 2026.