Skip to main content

Automated GitHub PR code review agent powered by LangGraph and Dough.id (Llama 3.3)

Project description

🤖 AI Code Review Agent

Python FastAPI React Vite LangGraph Dough API

Automated GitHub PR analysis using 3 parallel AI agents.

ArchitectureFeaturesQuick StartAPIDemo


⚡ Overview

The AI Code Review Agent is a full-stack application that acts as an automated, multi-disciplinary code reviewer. By pasting a GitHub Pull Request URL, the system fetches the code changes and processes them through three specialized AI agents in parallel.

Each agent has a specific focus:

  • 🔒 Security Agent: Hardcoded secrets, SQL injection, XSS, insecure dependencies.
  • 🚀 Performance Agent: N+1 queries, memory leaks, blocking I/O, O(n²) loops.
  • Code Quality Agent: Code smells, SOLID violations, naming conventions, missing error handling.

The agents parse the PR diff, generate a structured JSON report, and synthesize a comprehensive markdown review that can be automatically posted directly to the GitHub PR.


🏗️ Architecture

The backend utilizes FastAPI for high-performance async routing, while LangGraph orchestrates the multi-agent LLM workflow. Requests are routed through the Dough.id API (OpenAI compatible) to process using Meta's llama-3.3-70b-versatile model.

graph TD
    %% Styling
    classDef frontend fill:#2d3748,stroke:#4a5568,stroke-width:2px,color:#fff
    classDef backend fill:#2c5282,stroke:#4299e1,stroke-width:2px,color:#fff
    classDef agent fill:#702459,stroke:#d53f8c,stroke-width:2px,color:#fff
    classDef external fill:#276749,stroke:#48bb78,stroke-width:2px,color:#fff

    %% Nodes
    UI[🖥️ React SPA Frontend]:::frontend
    API[⚡ FastAPI Backend]:::backend
    GH_API[🐙 GitHub API]:::external
    DOUGH[🧠 Dough.id / Groq LLM]:::external
    
    subgraph LangGraph Orchestration
        SEC[🔒 Security Agent]:::agent
        PERF[🚀 Performance Agent]:::agent
        QUAL[✨ Code Quality Agent]:::agent
        SYNTH[📝 Markdown Synthesizer]:::agent
    end

    %% Connections
    UI -- "POST /review (PR URL)" --> API
    API -- "Fetch Diff & Meta" --> GH_API
    GH_API -- "Raw Git Diff" --> API
    API -- "asyncio.gather()" --> SEC & PERF & QUAL
    
    SEC -. "JSON Review" .-> DOUGH
    PERF -. "JSON Review" .-> DOUGH
    QUAL -. "JSON Review" .-> DOUGH
    
    SEC & PERF & QUAL --> SYNTH
    SYNTH -- "Combined Report" --> API
    API -- "Post Comment (Optional)" --> GH_API
    API -- "JSON + Markdown" --> UI

✨ Features

  • Parallel Execution: All three AI agents run simultaneously using asyncio.gather() to minimize latency.
  • Rate-Limit Resilient: Employs tenacity for exponential backoff retries and staggers agent starts by 2 seconds to avoid 429 errors.
  • Robust Parsing: Diff truncation ensures LLM token limits are respected (~8k char limit). Robust JSON extraction ignores markdown code fences.
  • Dark Glassmorphism UI: A premium, responsive React dashboard built with Vite.
  • Cloudflare Bypass: Configured with custom User-Agent headers to securely route through Dough.id's protected API gateway.

🚀 Quick Start

You can run this project in two ways: as a Standalone CLI or as a Full-Stack Web App.

1. Prerequisites

  • Python ≥ 3.11
  • Dough.id API Key (or Groq/OpenAI compatible key)
  • GitHub Personal Access Token (Optional for public repos, required to post comments)
  • Node.js ≥ 18 (Only required for the Web App)

Option A: Use as a CLI Package

The fastest way to use the code reviewer is directly from your terminal. You do not need to clone this repository.

# 1. Install globally via pip
pip install pr-review-me

# 2. Set your API key (or pass it directly via --dough-api-key)
export DOUGH_API_KEY="sk-your-key-here"

# 3. Run the review against any public PR!
pr-review-me https://github.com/django/django/pull/21523

# (Add --post-comment to automatically post the review back to GitHub)
pr-review-me https://github.com/django/django/pull/21523 --post-comment

Option B: Run the Web Dashboard

If you prefer a visual interface, you can boot up the FastAPI backend and React frontend.

1. Backend Setup

# Enter the directory
cd pr_rev

# Create and activate a virtual environment
python -m venv .venv
.venv\Scripts\activate      # Windows
source .venv/bin/activate   # macOS / Linux

# Install dependencies
pip install -r requirements.txt

3. Environment Variables

Create a .env file in the root directory:

# API Keys
DOUGH_API_KEY=sk-your-dough-api-key
GITHUB_TOKEN=ghp_your_github_token_here

4. Frontend Setup

cd frontend
npm install
cd ..

5. Running the Application

Open two terminals to run the services concurrently:

Terminal 1 — Backend (FastAPI)

.venv\Scripts\activate
uvicorn main:app --reload --port 8000

Terminal 2 — Frontend (Vite)

cd frontend
npm run dev

Navigate to http://localhost:5173 to access the dashboard.


📖 API Reference

GET /health

Liveness probe to verify the backend is running.

{ "status": "ok", "version": "1.0.0" }

POST /review

Executes the full multi-agent review pipeline.

Request:

{
  "pr_url": "https://github.com/owner/repo/pull/123",
  "post_comment": true
}

Response:

{
  "success": true,
  "pr_title": "Add user authentication",
  "pr_author": "octocat",
  "security": { "agent_name": "Security Agent", "issues": [], "summary": "..." },
  "performance": { "agent_name": "Performance Agent", "issues": [], "summary": "..." },
  "code_quality": { "agent_name": "Code Quality Agent", "issues": [], "summary": "..." },
  "markdown_comment": "# 🤖 AI Code Review Report\n...",
  "comment_posted": true,
  "comment_url": "https://github.com/owner/repo/pull/123#issuecomment-12345",
  "total_issues": 4,
  "critical_count": 0,
  "duration_seconds": 12.4
}

🛠️ Project Structure

pr_rev/
├── main.py                # FastAPI Application & Endpoints
├── agents.py              # LangGraph Agents & Dough.id Integration
├── github_utils.py        # GitHub REST API interactions
├── requirements.txt       # Python dependencies
├── .env                   # Environment variables
└── frontend/
    ├── src/
    │   ├── App.jsx        # Main React Dashboard Component
    │   ├── App.css        # Glassmorphism Styling
    │   └── main.jsx       # React Entry Point
    ├── package.json       # Node dependencies
    └── vite.config.js     # Vite configuration & proxy

🔧 Troubleshooting

Issue Resolution
401 Unauthorized (GitHub) Verify GITHUB_TOKEN is set in .env and has repo scope.
404 Not Found (GitHub) Ensure the PR URL is formatted correctly: https://github.com/owner/repo/pull/NNN.
403 / Blocked (Dough.id) Make sure User-Agent is configured in ChatOpenAI headers to bypass Cloudflare.
CORS Errors Ensure the backend is running on port 8000. Vite automatically proxies /review to it.
Empty Diff The PR might only contain merge commits without code changes.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pr_review_me-1.0.0.tar.gz (17.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pr_review_me-1.0.0-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

Details for the file pr_review_me-1.0.0.tar.gz.

File metadata

  • Download URL: pr_review_me-1.0.0.tar.gz
  • Upload date:
  • Size: 17.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pr_review_me-1.0.0.tar.gz
Algorithm Hash digest
SHA256 bde4dd6cbc0e925f833f425ab46b3e58acdc1d41496b2c16902ab5fa0e0ccd89
MD5 662aa25c43dba8270f33eb7c9cbb53a5
BLAKE2b-256 ec3570e9308bcd892af6fa641b9b5ba1c9ca161c30bed4328d476b4f6db49e10

See more details on using hashes here.

Provenance

The following attestation bundles were made for pr_review_me-1.0.0.tar.gz:

Publisher: publish.yml on kh-bikash/pr_agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pr_review_me-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pr_review_me-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 15.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pr_review_me-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c3b96393a7daa61ac7154616af9c9ab067bda82e659a0186c92de4da1f601974
MD5 f037b7554c76a3b10d4d99074b0efe9f
BLAKE2b-256 81680fc00bd144d19ec38d7b16e6735ca9180ce3c3509163f106ab2bfd77fcc9

See more details on using hashes here.

Provenance

The following attestation bundles were made for pr_review_me-1.0.0-py3-none-any.whl:

Publisher: publish.yml on kh-bikash/pr_agent

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page