Skip to content

Review pull requests with an agent ​

The Pull Request Reviewer template gives you an agent that reviews each pull request when it opens, but on its own it only sees the event, not the code. It reads the diff only if you give it a tool that can, or send the diff yourself. This page shows what to prepare, what each platform can supply, and how to roll the agent out without letting it write to your repositories on day one.

Enterprise module

The trigger and the connector tools need the enterprise Connectors module. See Connectors.

When to use ​

  • You want a first review on every pull request that a human then reads and forwards.
  • You use GitHub and want the shortest path. The template is built for it.
  • You use Azure DevOps, GitLab or Bitbucket and need to know what the agent can and cannot see.

What the template does and does not do ​

It doesIt does not
Reviews against a checklist skill, tpl-code-review-checklist, with the focus you set in the focus variable (default correctness, security, tests)Come with any tool. The agent has no tools attached
Returns structured output: summary, risk, up to 10 findings (file, line, severity, category, comment), tests_suggested, verdict and missing_contextReceive the diff in the event. The event carries the number, title, description, branches, author and link
Sets the verdict to approve, comment, request_changes or needs_more_contextInvent findings. With no visible diff it returns an empty list, the verdict needs_more_context and says what it needs
Treats titles, descriptions, commit messages and code comments as data, not as instructionsRun code, so it never claims that tests passed
Comes with a suggested GitHub pull_request trigger for opened, reopened, updated and ready-for-review events, skipping draftsPost anything. Its answer is a JSON result until you add a tool or a callback

The trigger is created disabled. The template suggests a reasoning-class model.

Decide: how the agent gets the diff ​

PlatformTrigger for the agentRead toolsDiffComment tool (write, Read only off)
GitHubpull_request: the template's ownget_pull_request, list_pull_request_filesYes. A patch per file, cut at 4,000 characters, and missing for binary or huge files. At most 3,000 files are listedcomment_on_pr: a comment in the conversation, not a line comment
Azure DevOpspull_request_created, pull_request_updatedget_pull_requestNo. It returns title, description, status, branches, merge status, reviewers' votes and labelscomment_on_pull_request: a new thread
GitLabmerge_requestget_merge_requestNo. It returns the description, reviewers, merge status, the number of changed files and the latest pipeline statuscomment_on_merge_request
Bitbucket (Cloud and Data Center)Noneget_pull_requestNo. It returns the changed files (up to 50), lines added and removed on Cloud, and the comments. Read file content with get_file on the source branchadd_pull_request_comment

The template's suggested trigger is for GitHub only. On another platform add your own connector trigger from the agent's Triggers tab and write the prompt against that package's event data.

Where the connector cannot read the diff, run the review from a pipeline step that has the diff and sends it to the agent. See GitHub Actions and Azure DevOps.

Prerequisites ​

CheckWhereHow to know
The Connectors module is in your packageBuild → Connectors opensWithout it the agent is created without the connector trigger, and the result screen says so
A connector with a connected account, in the same projectBuild → ConnectorsThe connector shows a connected account and its tool is Active
The repository, as owner/nameThe trigger's Repository fieldThe list reads from the connector, or you type it
The account may register a webhookThe connector's accountA trigger with an Active subscription. Otherwise it shows Needs setup with a callback URL and a secret for a manual setup
GitHub can reach /api/public/connector-hooks/ on your addressAPP_URL and your ingressThe subscription is not unreachable. An on-premises installation must route that path from the internet
Write actions are off until you want themThe connector's Read only setting, on by defaultThe comment tool is not offered while it is on
The trigger is enabledThe trigger's switchIt is created disabled. Enable it after you checked the subscription

Steps ​

  1. Open Build → Agents → Templates and select Pull Request Reviewer. In Use template pick a chat model, pick your GitHub connector and type the Repository. Leave Create the suggested triggers on.
  2. Open the agent and its Build tab. In Tools choose Add → Add from hub / library…, expand the GitHub tool (it has the Connector badge) and tick get_pull_request and list_pull_request_files. Leave the comment tool out for now.
  3. Open the agent's Triggers and look at Review pull requests: the connector, the repository, the events and the filter payload.draft eq false. Open its Settings tab and check the subscription.
  4. Use the Test tab: Preview with a sample event shows the message the agent would get.
  5. Publish the agent. A trigger runs the published version.
  6. Enable the trigger.

See Connector triggers for the subscription states and Connector tools and approvals for the tool binding.

Verify ​

CheckHowYou should see
The subscriptionThe trigger's Settings tabActive. If Needs setup, a callback URL and a secret to enter at GitHub
The messageThe Test tab, PreviewThe rendered prompt with the pull request number and the repository filled in
A real eventOpen a non-draft pull request in the test repositoryAn entry in Deliveries, then a run of the agent with trigger: connector
The diff was readOpen the runA call to list_pull_request_files, and findings with file names and lines
Drafts are skippedOpen a draft pull requestNo run starts, because the filter skips drafts. Marking it ready starts one
No diff, no inventionRemove the tool and rerunAn empty findings list, needs_more_context and a missing_context text

Roll it out in three stages ​

StageAgent canWho actsMove on when
1. Read onlyRead the pull request and its files. The connector stays on Read only. No comment toolA person reads the run result, or a callback sends it to a URL of your choiceYour reviewers agree with the findings on the pull requests you chose to compare
2. Comment with human approvalAlso comment_on_pr, with Read only off on the connectorA person approves each commentApproved comments are mostly posted unchanged
3. Evaluation gateThe same, wider: more repositories, fewer approvalsAn evaluation decides whether a change to the prompt, the model or the tools may shipThe suite passes at the threshold you set

Stage 2 details. A write action asks before it runs by default. A trigger run has nobody to answer, so with the default When nobody can answer setting, Deny the tool call, the comment is refused and the run goes on. To let a person approve, set it to Pause and wait for approval in Studio in the agent's Approvals & questions. The comment then waits in the session until someone answers. See Approvals.

Stage 3 details. Build a dataset of past pull requests with the problems a good review must catch, and an evaluation suite with your agent as the target. Use assertion scorers on the structured output (jsonSchema, jsonPath, mustContain) and an LLM judge with a rubric for the quality of a comment. Run it on every change to the prompt, the model or the tools. An alert rule on evaluation_pass_rate tells you when it drops.

Common problems ​

SymptomCauseFix
The verdict is always needs_more_contextThe agent has no tool that reads the diff, or the platform returns noneBind list_pull_request_files on GitHub. On other platforms send the diff from a pipeline
Nothing starts when a pull request opensThe trigger is still disabled, the subscription is not Active, the repository is wrong, or the filter skips draftsCheck the Settings tab and Deliveries. unreachable means APP_URL is not public
The trigger shows Needs setupThe account cannot register a webhookEnter the callback URL and the secret at GitHub under Settings → Webhooks, or give the account the webhook permission
The agent was created without a triggerNo GitHub connector, no Connectors module or no repositoryAdd the connector, then add the trigger from the agent's Triggers tab
A comment is never postedRead only is on, the call was denied because nobody can answer, or the account cannot writeSee stage 2
A large pull request is reviewed in partA patch is cut at 4,000 characters per file and GitHub omits someNarrow the focus, split the pull request, and read missing_context
A review runs on every pushpull_request.synchronize is one of the eventsRemove it, or accept a review per push. Each push is a new run
Strangers can start reviews on a public repositoryAnyone can open a pull requestAdd a rule on payload.author

Next steps ​

Studio · Pulse · Console · Agent SDK and more — the Cognipeer documentation hub · Contact Support