An automated GitHub PR review agent powered by OpenAI that provides thoughtful, critical code reviews across multiple repositories.
An example of the agent's feedback
- 🤖 AI-powered code reviews that challenge assumptions and improve code quality
- 📊 Monitor multiple GitHub repositories for new PRs
- 🔄 Configurable checking intervals
- ⚙️ Avoids duplicate comments on PRs
- 📝 Critical but constructive feedback
- 🔍 Reviews code with the OpenAI o4-mini model
- Python 3.8 or higher
- A GitHub personal access token with repo permissions
- OpenAI API key
-
Clone the repository:
git clone https://github.com/yourusername/PR-Review-Agent.git cd PR-Review-Agent
-
Create a virtual environment and install dependencies:
python -m venv .venv source .venv/bin/activate # On Windows: .venv\Scripts\activate pip install -r requirements.txt
-
Set up your environment variables in a
.env
file:GITHUB_TOKEN=your_github_token OPENAI_API_KEY=your_openai_api_key
The agent monitors repositories listed in a repositories.txt
file in the project root. Format:
# Add repositories to monitor, one per line
username/repo1
username/repo2
If the file doesn't exist, it will be created automatically with default settings.
You need a GitHub personal access token with repo
scope to enable the agent to read PRs and post comments.
To create a token:
- Go to GitHub → Settings → Developer settings → Personal access tokens → Tokens (classic)
- Generate a new token with
repo
scope - Add it to your
.env
file or provide it when running the agent
Run the agent with default settings:
python main.py
This will:
- Check repositories listed in
repositories.txt
- Use default 1-hour interval between checks
- Look for GitHub token in
.env
file or prompt you to enter one
python main.py --repos-file custom_repos.txt --interval 1800 --token your_github_token
Options:
--repos-file
: Path to a custom repository list file (default:repositories.txt
)--interval
: Checking interval in seconds (default: 3600)--token
: GitHub token (can also be set via GITHUB_TOKEN env var)--legacy
: Run legacy git analysis mode
To customize the type of feedback provided by the agent, modify the review prompts in the review_pr
function in main.py
.
- The agent reads the repository list from the configuration file
- For each repository, it fetches open PRs via the GitHub API
- For each PR that hasn't been reviewed yet, it:
- Uses OpenAI's o4-mini model to generate a code review
- Posts the review as a comment on the PR
- Tracks the PR to avoid duplicate comments
- Waits for the configured interval, then repeats
Contributions are welcome! To contribute:
- Fork the repository
- Create a new branch for your feature
- Add your changes
- Submit a pull request
- Use descriptive commit messages
- Add tests for new features
- Update documentation as needed
- Follow the existing code style
- This project uses the OpenAI Agents SDK
- Inspired by the need for automated, critical code reviews that challenge developers to improve their code