Skip to content

Commit 6c006a0

Browse files
author
Gavin Williams
committed
Update review-agent docs
1 parent 456fa94 commit 6c006a0

File tree

1 file changed

+101
-50
lines changed

1 file changed

+101
-50
lines changed

docs/docs/features/agents/review-agent.mdx

Lines changed: 101 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -3,64 +3,55 @@ title: AI Code Review Agent
33
sidebarTitle: AI code review agent
44
---
55

6-
<Note>
7-
This agent sends data to OpenAI (through an API key you supply) to perform code reviews. This data includes code from the PR being reviewed, as well as additional relevant context from your
8-
codebase that the agent may fetch to perform the review.
9-
</Note>
6+
This agent provides codebase-aware reviews for your GitHub PRs and GitLab MRs. For each diff, the agent fetches relevant context from your indexed codebase and feeds it into a configured language model for a detailed review.
107

11-
This agent provides codebase-aware reviews for your PRs. For each diff, this agent fetches relevant context from Sourcebot and feeds it into an LLM for a detailed review of your changes.
12-
13-
The AI Code Review Agent is [fair source](https://github.com/sourcebot-dev/sourcebot/tree/main/packages/web/src/features/agents/review-agent) and packaged in [Sourcebot](https://github.com/sourcebot-dev/sourcebot). To get started using this agent, [deploy Sourcebot](/docs/deployment/docker-compose)
14-
and then follow the configuration instructions below.
8+
The AI Code Review Agent is [fair source](https://github.com/sourcebot-dev/sourcebot/tree/main/packages/web/src/features/agents/review-agent) and packaged in [Sourcebot](https://github.com/sourcebot-dev/sourcebot). To get started, [deploy Sourcebot](/docs/deployment/docker-compose) and follow the configuration instructions below.
159

1610
![AI Code Review Agent Example](/images/review_agent_example.png)
1711

18-
# Configure
12+
# Language model
13+
14+
The review agent uses whichever language model you have configured in your `config.json`. All providers supported by Sourcebot (OpenAI, Anthropic, AWS Bedrock, Azure OpenAI, and others) work out of the box.
1915

20-
This agent currently only supports reviewing GitHub PRs. You configure the agent by creating a GitHub app, installing it into your GitHub organization, and then giving your app info to Sourcebot.
16+
If you have multiple models configured, set `REVIEW_AGENT_MODEL` to the `displayName` of the model you want the agent to use. If this variable is unset, the agent uses the first configured model.
2117

22-
Before you get started, make sure you have an OpenAPI account that you can create an OpenAPI key with.
18+
# GitHub
2319

2420
<Steps>
2521
<Step title="Register a GitHub app">
26-
Follow the official GitHub guide for [registering a GitHub app](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app)
27-
28-
- GitHub App name: You can make this whatever you want (ex. Sourcebot Review Agent)
29-
- Homepage URL: You can make this whatever you want (ex. https://www.sourcebot.dev/)
30-
- Webhook URL (**IMPORTANT**): You must set this to point to your Sourcebot deployment at /api/webhook (ex. https://sourcebot.aperture.com/api/webhook). Your Sourcebot deployment must be able to accept requests from GitHub
31-
(either github.com or your self-hosted enterprise server) for this to work. If you're running Sourcebot locally, you can [use smee](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#step-2-get-a-webhook-proxy-url) to [forward webhooks](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#step-6-start-your-server) to your local deployment.
32-
- Webook Secret: This can be any string (ex. generate a random string `python -c "import secrets; print(secrets.token_hex(10))"`). You'll provide this to Sourcebot to be able to read webhook events from your app.
33-
- Permissions
22+
Follow the official GitHub guide for [registering a GitHub app](https://docs.github.com/en/apps/creating-github-apps/registering-a-github-app/registering-a-github-app).
23+
24+
- **GitHub App name**: Any name you choose (e.g. Sourcebot Review Agent)
25+
- **Homepage URL**: Any URL you choose (e.g. `https://www.sourcebot.dev/`)
26+
- **Webhook URL** (required): Your Sourcebot deployment URL at `/api/webhook` (e.g. `https://sourcebot.example.com/api/webhook`). Your deployment must be reachable from GitHub. If you are running Sourcebot locally, use [smee](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#step-2-get-a-webhook-proxy-url) to [forward webhooks](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#step-6-start-your-server) to your local deployment.
27+
- **Webhook Secret**: Any string (e.g. generate one with `python -c "import secrets; print(secrets.token_hex(10))"`)
28+
- **Permissions**
3429
- Pull requests: Read & Write
3530
- Issues: Read & Write
3631
- Contents: Read
37-
- Events:
32+
- **Events**
3833
- Pull request
3934
- Issue comment
4035
</Step>
4136
<Step title="Install the GitHub app in your organization">
42-
Navigate to your new [GitHub app's page](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings) and press `Install`
37+
Navigate to your new [GitHub app's page](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings) and press **Install**.
4338
</Step>
44-
<Step title="Configure the environment variables in Sourcebot">
45-
Sourcebot requires the following environment variables to begin reviewing PRs through your new GitHub app:
46-
47-
- `GITHUB_REVIEW_AGENT_APP_ID`: The client ID of your GitHub app. Can be found in your [app settings](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings)
48-
- `GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET`: The webhook secret you defined in your GitHub app. Can be found in your [app settings](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings)
49-
- `GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH`: The path to your app's private key. If you're running Sourcebot from a container, this is the path to this file from within your container
50-
(ex `/data/review-agent-key.pem`). You must copy the private key file into the directory you mount to Sourcebot (similar to the config file).
51-
52-
You can generate a private key file for your app in the [app settings](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings). You must copy this private key file into the
53-
directory that you mount to Sourcebot
54-
![GitHub App Private Key](/images/github_app_private_key.png)
55-
- `OPENAI_API_KEY`: Your OpenAI API key
56-
- `REVIEW_AGENT_API_KEY`: The Sourcebot API key that the review agent uses to hit the Sourcebot API to fetch code context
57-
- `REVIEW_AGENT_AUTO_REVIEW_ENABLED` (default: `false`): If enabled, the review agent will automatically review any new or updated PR. If disabled, you must invoke it using the command defined by `REVIEW_AGENT_REVIEW_COMMAND`
58-
- `REVIEW_AGENT_REVIEW_COMMAND` (default: `review`): The command that invokes the review agent (ex. `/review`) when a user comments on the PR. Don't include the slash character in this value.
59-
60-
You can find an example docker compose file below.
61-
- This docker compose file is placed in `~/sourcebot_review_agent_workspace`, and I'm mounting that directory to Sourcebot
62-
- The config and the app private key files are placed in this directory
63-
- The paths to these files are given to Sourcebot relative to `/data` since that's the directory in Sourcebot that I'm mounting to
39+
<Step title="Configure environment variables">
40+
Set the following environment variables in your Sourcebot deployment:
41+
42+
| Variable | Description |
43+
|---|---|
44+
| `GITHUB_REVIEW_AGENT_APP_ID` | The client ID of your GitHub app, found in your [app settings](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings) |
45+
| `GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET` | The webhook secret you set when registering the app |
46+
| `GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH` | Path to your app's private key file inside the container (e.g. `/data/review-agent-key.pem`). Copy the key file into the directory you mount to Sourcebot. |
47+
48+
You can generate a private key in your [app settings](https://docs.github.com/en/apps/creating-github-apps/writing-code-for-a-github-app/quickstart#navigate-to-your-app-settings).
49+
50+
<Frame>
51+
<img src="/images/github_app_private_key.png" alt="GitHub App Private Key" />
52+
</Frame>
53+
54+
Example `docker-compose.yml`:
6455

6556
```yaml
6657
services:
@@ -71,26 +62,86 @@ Before you get started, make sure you have an OpenAPI account that you can creat
7162
ports:
7263
- "3000:3000"
7364
volumes:
74-
- "/Users/michael/sourcebot_review_agent_workspace:/data"
65+
- "/home/user/sourcebot_workspace:/data"
7566
environment:
7667
CONFIG_PATH: "/data/config.json"
7768
GITHUB_REVIEW_AGENT_APP_ID: "my-github-app-id"
78-
GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET: "my-github-app-webhook-secret"
69+
GITHUB_REVIEW_AGENT_APP_WEBHOOK_SECRET: "my-webhook-secret"
7970
GITHUB_REVIEW_AGENT_APP_PRIVATE_KEY_PATH: "/data/review-agent-key.pem"
80-
REVIEW_AGENT_API_KEY: "sourcebot-my-key"
81-
OPENAI_API_KEY: "sk-proj-my-open-api-key"
8271
```
8372
</Step>
8473
<Step title="Verify configuration">
85-
Navigate to the agents page by pressing `Agents` in the Sourcebot nav menu. If you've configured your environment variables correctly you'll see the following:
74+
Navigate to **Agents** in the Sourcebot nav menu. If your environment variables are set correctly, the GitHub Review Agent card shows a confirmation that the agent is configured and accepting requests.
8675
87-
![Review Agent Configured](/images/review_agent_configured.png)
76+
<Frame>
77+
<img src="/images/review_agent_configured.png" alt="Review Agent Configured" />
78+
</Frame>
79+
</Step>
80+
</Steps>
81+
82+
# GitLab
83+
84+
<Steps>
85+
<Step title="Create a GitLab access token">
86+
Create a [personal access token](https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html) or [project access token](https://docs.gitlab.com/ee/user/project/settings/project_access_tokens.html) with the following scope:
87+
88+
- `api`
89+
90+
Keep a note of the token value — you will need it in the next step.
91+
</Step>
92+
<Step title="Configure a webhook in GitLab">
93+
In your GitLab project, go to **Settings → Webhooks** and add a new webhook:
94+
95+
- **URL**: Your Sourcebot deployment URL at `/api/webhook` (e.g. `https://sourcebot.example.com/api/webhook`)
96+
- **Secret token**: Any string (e.g. generate one with `python -c "import secrets; print(secrets.token_hex(10))"`)
97+
- **Trigger events**: Merge request events, Comments
98+
99+
Save the webhook.
100+
</Step>
101+
<Step title="Configure environment variables">
102+
Set the following environment variables in your Sourcebot deployment:
103+
104+
| Variable | Description |
105+
|---|---|
106+
| `GITLAB_REVIEW_AGENT_WEBHOOK_SECRET` | The secret token you set on the GitLab webhook |
107+
| `GITLAB_REVIEW_AGENT_TOKEN` | The GitLab personal or project access token |
108+
| `GITLAB_REVIEW_AGENT_HOST` | Your GitLab hostname. Defaults to `gitlab.com`. Set this for self-hosted GitLab instances (e.g. `gitlab.example.com`). |
109+
110+
Example `docker-compose.yml`:
111+
112+
```yaml
113+
services:
114+
sourcebot:
115+
image: ghcr.io/sourcebot-dev/sourcebot:latest
116+
pull_policy: always
117+
container_name: sourcebot
118+
ports:
119+
- "3000:3000"
120+
volumes:
121+
- "/home/user/sourcebot_workspace:/data"
122+
environment:
123+
CONFIG_PATH: "/data/config.json"
124+
GITLAB_REVIEW_AGENT_WEBHOOK_SECRET: "my-webhook-secret"
125+
GITLAB_REVIEW_AGENT_TOKEN: "glpat-my-token"
126+
GITLAB_REVIEW_AGENT_HOST: "gitlab.example.com"
127+
```
128+
</Step>
129+
<Step title="Verify configuration">
130+
Navigate to **Agents** in the Sourcebot nav menu. If your environment variables are set correctly, the GitLab Review Agent card shows a confirmation that the agent is configured and accepting requests.
88131
</Step>
89132
</Steps>
90133

91134
# Using the agent
92135

93-
The review agent will not automatically review your PRs by default. To enable this feature, set the `REVIEW_AGENT_AUTO_REVIEW_ENABLED` environment variable to true.
136+
By default, the agent does not review PRs and MRs automatically. To enable automatic reviews on every new or updated PR/MR, set `REVIEW_AGENT_AUTO_REVIEW_ENABLED` to `true`.
137+
138+
You can also trigger a review manually by commenting `/review` on any PR or MR. To use a different command, set `REVIEW_AGENT_REVIEW_COMMAND` to your preferred value (without the leading slash).
139+
140+
# Environment variable reference
94141

95-
You can invoke the review agent manually by commenting `/review` on the PR you'd like it to review. You can configure the command that triggers the agent by changing
96-
the `REVIEW_AGENT_REVIEW_COMMAND` environment variable.
142+
| Variable | Default | Description |
143+
|---|---|---|
144+
| `REVIEW_AGENT_AUTO_REVIEW_ENABLED` | `false` | Automatically review new and updated PRs/MRs |
145+
| `REVIEW_AGENT_REVIEW_COMMAND` | `review` | Comment command that triggers a manual review (without the `/`) |
146+
| `REVIEW_AGENT_MODEL` | first configured model | `displayName` of the language model to use for reviews |
147+
| `REVIEW_AGENT_LOGGING_ENABLED` | unset | Write prompt and response logs to disk for debugging |

0 commit comments

Comments
 (0)