Skip to content

Latest commit

 

History

21 Commits

Folders and files

Repository files navigation

Multi-Agent-Code-Review-System

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.

Live Dashboard


Demo

When a pull request is opened or updated, the bot automatically:

  1. Receives the GitHub webhook event
  2. Fetches the PR diff
  3. Runs specialized AI agents in parallel
  4. Posts a structured review comment to the PR
  5. 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,))

Architecture

Intelligent Routing

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

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.

Power Combo Features

Beyond basic code review, the system tracks production metrics that demonstrate real-world impact:

Metrics Tracking

Every review is logged to PostgresSQL with:

  • Files changes, lines changed
  • Issues found by type and severity
  • Review duration

Cost Tracking

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

Feedback Loop

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.

Tech Stack

Backend

  • Python 3.12, FastAPI, Pydantic
  • LangGraph (agent orchestration with conditional branching)
  • LangChain + OpenAI GPT-4o-mini (structured outputs)
  • asyncpg + PostgresSQL 18

Frontend

  • React 18, Typescript, Vite
  • Recharts (data visualization)
  • Tailwind CSS
  • Custom WebGL background (OGL)

Infrastructure

  • Docker (containerization)
  • Kubernetes / Minikube (local orchestration)
  • Railway (cloud deployment - backend + PostgresSQL)
  • Vercel (frontend deployment)
  • ngrok (local webhook tunneling)

Project Structure

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

Getting Started

Prerequisites

  • Python 3.12+
  • Node.js 18+
  • PostgresSQL
  • OpenAI API key
  • GitHub account

Local Setup

  1. Clone the repository
git clone https://github.com/your-username/Multi-Agent-Code-Review-System.git
cd Multi-Agent-Code-Review-System
  1. Setup Python environment (venv)
python -m venv venv
.\venv\Scripts\Activate  # Windows
source venv/bin/activate  # Mac/Linux
pip install -r backend/requirements.txt
  1. Configure environment variables Create backend/.env or 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
  1. 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;
  1. Start the backend
uvicorn backend.main:app --reload
  1. Start the frontend
cd frontend
npm install
npm run dev
  1. Expose webhook endpoint
ngrok http 8000
  1. 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

docker build -t code-review-bot .
docker run -p 8000:8000 --env-file backend/.env code-review-bot

API Endpoints

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

Dashboard

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

Releases

Packages

Contributors

Languages