An AI-powered code review bot that automatically analyzes pull requests using a multi-agent pipeline built with LangGraph. The system detects security vulnerabilities, test coverage gaps, and code quality issues, then posts a formmated review comment to GitHub.
When a pull request is opened or updated, the bot automatically:
- Receives the GitHub webhook event
- Fetches the PR diff
- Runs specialized AI agents in parallel
- Posts a structured review comment to the PR
- Logs metrics, costs, and feedback to a live dashboard
Example review comment
## Automated Code Review
**Status:** Critical Issues Found - Please address before merging
### Summary
Found 3 issue(s):
- 🔴 1 Critical
- 🟠 1 High
- 🔵 1 Low
### Security
🔴 **Hardcoded API key detected** (Line 4)
💡 Use environment variables: API_KEY = os.getenv('API_KEY')
🟠 **SQL injection: f-string used in SQL query** (Line 12)
💡 Use parameterized queries: cursor.execute('SELECT * FROM users WHERE id = ?', (user_id,))The LangGraph workflow implements conditional branching:
- Critical path: If the Security Agent finds a critical vulnerability, testing and quality agents are skipped and the review is immediately sent to the developer, reducing latency for the most urgent issues
- Full path: For normal PRs, the Test Coverage and Code Quality agents run in parallel for faster analysis
- Deduplication: The Coordinator Agent merges overlapping findings across agents and keeps only the highest severity instance
| Agent | Responsibility | Approach |
|---|---|---|
| SecurityAgent | SQL injection, hardcoded secrets, XSS, insecure deserialization | Regex pattern matching + GPT-4o-mini |
| TestCoverageAgent | Missing tests for new functions, untested edge cases | GPT-4o-mini with structured output |
| CodeQualityAgent | High complexity, poor naming, code smells, missing docstrings | Regex pattern matching + GPT-4o-mini |
| CoordinatorAgent | Synthesizes findings, deduplicates, formats final review | Rule-based |
All LLM agents use OpenAI structured outputs with Pydantic models to gurantee consistent, parseable responses.
Beyond basic code review, the system tracks production metrics that demonstrate real-world impact:
Every review is logged to PostgresSQL with:
- Files changes, lines changed
- Issues found by type and severity
- Review duration
Every OpenAI API call is tracked per agent:
- Prompt tokens, completion tokens
- Cost in USD calculated using current pricing
- Breakdown by agent to identify optimization opportunities
Developers can rate reviews by commenting /feedback good or /feedback bad on any PR. The bot replies with a confirmation and logs the rating, enabling accuracy tracking over time.
- Python 3.12, FastAPI, Pydantic
- LangGraph (agent orchestration with conditional branching)
- LangChain + OpenAI GPT-4o-mini (structured outputs)
- asyncpg + PostgresSQL 18
- React 18, Typescript, Vite
- Recharts (data visualization)
- Tailwind CSS
- Custom WebGL background (OGL)
- Docker (containerization)
- Kubernetes / Minikube (local orchestration)
- Railway (cloud deployment - backend + PostgresSQL)
- Vercel (frontend deployment)
- ngrok (local webhook tunneling)
Multi-Agent-Code-Review-System/
├── backend/
│ ├── agents/
│ │ ├── base_agent.py # Abstract base class
│ │ ├── security_agent.py # Security vulnerability detection
│ │ ├── test_coverage_agent.py # Test coverage analysis
│ │ ├── code_quality_agent.py # Code quality checks
│ │ └── coordinator_agent.py # Synthesis and formatting
│ ├── api/
│ │ ├── webhooks.py # GitHub webhook handler
│ │ └── analytics.py # Analytics endpoints
│ ├── models/
│ │ ├── agent_state.py # LangGraph state definition
│ │ └── github.py # GitHub payload models
│ ├── services/
│ │ ├── agent_orchestrator.py # LangGraph workflow
│ │ ├── llm_client.py # OpenAI client + prompts
│ │ ├── github_client.py # GitHub API client
│ │ ├── analytics_db.py # PostgreSQL operations
│ │ └── cost_tracker.py # API cost calculation
│ ├── utils/
│ │ └── security.py # HMAC signature verification
│ ├── config.py # Settings + env vars
│ ├── main.py # FastAPI app
│ └── requirements.txt
├── frontend/
│ └── src/
│ ├── components/
│ │ ├── StatCard.tsx # Metric cards with BorderGlow
│ │ ├── SeverityChart.tsx # Pie chart
│ │ ├── AgentCostChart.tsx # Bar chart
│ │ ├── FeedbackCard.tsx # Accuracy display
│ │ ├── ReviewsTable.tsx # Recent reviews
│ │ └── Iridescence.tsx # WebGL background
│ ├── App.tsx # Dashboard with 30s polling
│ └── api.ts # API client
├── Dockerfile
├── docker-compose.yml
└── k8s/
├── deployment.yaml
└── service.yaml- Python 3.12+
- Node.js 18+
- PostgresSQL
- OpenAI API key
- GitHub account
- Clone the repository
git clone https://github.com/your-username/Multi-Agent-Code-Review-System.git
cd Multi-Agent-Code-Review-System- Setup Python environment (venv)
python -m venv venv
.\venv\Scripts\Activate # Windows
source venv/bin/activate # Mac/Linux
pip install -r backend/requirements.txt- Configure environment variables
Create
backend/.envor use.env.example:
GITHUB_TOKEN=your_github_token
GITHUB_WEBHOOK_SECRET=your_webhook_secret
OPENAI_API_KEY=your_openai_key
DATABASE_URL=postgresql://user:password@localhost:5432/code_review_analytics- Setup PostgresSQL
CREATE DATABASE code_review_analytics;
CREATE USER code_review_bot WITH PASSWORD 'your_password';
GRANT ALL PRIVILEGES ON DATABASE code_review_analytics TO code_review_bot;
\c code_review_analytics
GRANT ALL ON SCHEMA public TO code_review_bot;- Start the backend
uvicorn backend.main:app --reload- Start the frontend
cd frontend
npm install
npm run dev- Expose webhook endpoint
ngrok http 8000- Configure GitHub webhook Go to your repo -> Settings -> Webhooks -> Add webhook:
- Payload URL:
https://your-ngrok-url/webhook/github - Content type:
application/json - Secret: your webhook secret
- Events: Pull requests, Issue comments
docker build -t code-review-bot .
docker run -p 8000:8000 --env-file backend/.env code-review-bot| Method | Endpoint | Description |
|---|---|---|
| POST | /webhook/github |
Receives GitHub webhook events |
| GET | /analytics/summary |
Overview stats |
| GET | /analytics/costs |
API cost breakdown |
| GET | /analytics/feedback |
Developer feedback stats |
| GET | /analytics/reviews |
Recent reviews |
| GET | /health |
Health checks |
The live dashboard auto refreshes every 30 seconds and displays:
- Total reviews processed
- Issues found by severity (critical/high/medium/low)
- Issues found by type (security/testing/quality)
- API cost breakdown per agent
- Developer feedback accuracy rate
- Recent review history