|
| 1 | +--- |
| 2 | +title: AI Code Review Agent |
| 3 | +sidebarTitle: AI Code Review Agent |
| 4 | +--- |
| 5 | + |
| 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> |
| 10 | + |
| 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 open source and packaged in [Sourcebot](https://github.com/sourcebot-dev/sourcebot). To get started using this agent, [deploy Sourcebot](http://localhost:3001/self-hosting/overview) |
| 14 | +and then follow the configuration instructions below. |
| 15 | + |
| 16 | + |
| 17 | + |
| 18 | +# Configure |
| 19 | + |
| 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. |
| 21 | + |
| 22 | +Before you get started, make sure you have an OpenAPI account that you can create an OpenAPI key with. |
| 23 | + |
| 24 | +<Steps> |
| 25 | + <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 you local deployment. |
| 32 | + - Permissions |
| 33 | + - Pull requests: Read |
| 34 | + - Contents: Read |
| 35 | + - Events: |
| 36 | + - Pull request |
| 37 | + </Step> |
| 38 | + <Step title="Install the GitHub app in your organization"> |
| 39 | + Navigate to your new GitHub app's page and press `Install`. You can find this 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). |
| 40 | + |
| 41 | + Select the repositories that you want to install the app into. |
| 42 | + </Step> |
| 43 | + <Step title="Configure the environment variables in Sourcebot"> |
| 44 | + Sourcebot requires the following environment variables to begin reviewing PRs through your new GitHub app: |
| 45 | + |
| 46 | + - `GITHUB_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) |
| 47 | + - `GITHUB_APP_WEBHOOK_SECRET`: A random webhook secret that you've set 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). This can be anything (ex. `python -c "import secrets; print(secrets.token_hex(10))"` to generate a random secret) |
| 48 | + - `GITHUB_APP_PRIVATE_KEY_PATH`: The path to your app's private key. 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) |
| 49 | +  |
| 50 | + - `OPENAI_API_KEY`: Your OpenAI API key |
| 51 | + </Step> |
| 52 | + <Step title="Verify configuration"> |
| 53 | + Navigate to the agents page by pressing `Agents` in the Sourcebot nav menu. If you've configured your environment variables you'll see the following: |
| 54 | + |
| 55 | +  |
| 56 | + </Step> |
| 57 | +</Steps> |
0 commit comments