Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GitHub PR Review — Multi-Agent System

Disclaimer: This is an internship project meant for upskilling in agentic AI. Not intended for production code review automation.

Overview

An agentic AI system that automates pull request code review on GitHub. Given a PR number and repository, a four-agent pipeline fetches the diff, scans for security vulnerabilities, checks for style violations, and posts structured inline review comments back to the PR.

How It Works

PR Request → Agent 1 (Diff Analysis) → Agent 2 (Security Scan)  → Agent 4 (Post Review) → GitHub PR
                                      → Agent 3 (Style Check)  ↗
  1. Agent 1 — Diff Analysis: Fetches the PR diff via GitHub API, parses files and hunks, classifies by language, flags test/generated files
  2. Agent 2 — Security Scanner: Pattern-matches added lines against known vulnerability signatures (hardcoded secrets, SQL injection, XSS, etc.) with CWE references
  3. Agent 3 — Style Checker: Evaluates code against language-specific style rules (PEP 8 for Python, ESLint-style for JS/TS)
  4. Agent 4 — Review Commenter: Aggregates findings, deduplicates, prioritizes by severity, and posts structured inline comments with a verdict (APPROVE / COMMENT / REQUEST_CHANGES)

Agents 2 and 3 run in parallel since they both depend only on Agent 1's output.

Project Structure

GitHub_PR_Review/
├── Master.md                              # System architecture, schemas, guardrails, success metrics
├── main.py                                # Orchestrator — runs the full pipeline
├── requirements.txt
├── README.md
│
├── Agents/
│   ├── diff_analysis_agent/
│   │   ├── agent.md                       # Role definition, system prompt, guardrails
│   │   └── agent.py                       # Implementation with GitHub API integration point
│   ├── security_scanner_agent/
│   │   ├── agent.md
│   │   └── agent.py                       # Regex-based vulnerability detection
│   ├── style_checker_agent/
│   │   ├── agent.md
│   │   └── agent.py                       # Language-specific style rule checking
│   └── review_commenter_agent/
│       ├── agent.md
│       └── agent.py                       # Finding aggregation + GitHub review posting
│
├── Skills/
│   ├── diff_parsing/
│   │   └── diff_parsing.md                # Unified diff format parsing logic
│   ├── security_scanning/
│   │   └── security_scanning.md           # Vulnerability pattern database docs
│   ├── style_checking/
│   │   └── style_checking.md              # Style rule definitions by language
│   └── comment_formatting/
│       └── comment_formatting.md          # Review comment templates and verdict logic
│
├── Memory/
│   ├── Memory.md                          # Index of all shared memory files
│   ├── security_patterns.json             # Regex patterns + CWE mappings (Python & JS)
│   ├── style_rules.json                   # PEP 8 + JS style rules
│   ├── severity_definitions.json          # Severity levels and verdict logic
│   ├── suppression_list.json              # Files/patterns to skip
│   ├── review_history.json                # Past review records
│   └── audit_log.json                     # Agent invocation trail
│
└── Data/
    └── sample_pr_request.json             # Sample input for testing

Quick Start

# Clone the repo
git clone https://github.com/your-username/GitHub_PR_Review.git
cd GitHub_PR_Review

# Install dependencies
pip install -r requirements.txt

# Run with sample data
python main.py

The system ships with a built-in sample PR (a deliberately insecure authentication endpoint) so it runs out of the box without any API keys.

Sample Output

Running python main.py produces:

  • 3 security findings: hardcoded password (critical), weak MD5 hashing (medium), debug mode enabled (medium)
  • 2 style findings: PascalCase function name (warning), untracked TODO comment (info)
  • Verdict: REQUEST_CHANGES — critical security finding blocks merge

Connecting to Real GitHub (Optional)

To use with real PRs, add your GitHub token in two places:

  1. Agents/diff_analysis_agent/agent.py — uncomment GITHUB_TOKEN and replace the fetch_pr_diff function with the real API call (commented template included)
  2. Agents/review_commenter_agent/agent.py — uncomment GITHUB_TOKEN and replace the post_review_to_github function with the real API call (commented template included)

Security Patterns Covered

Category CWE Languages
Hardcoded Secrets CWE-798 Python, JS
SQL Injection CWE-89 Python
Command Injection CWE-78 Python
XSS CWE-79 Python, JS
Insecure Deserialization CWE-502 Python
Weak Crypto CWE-327 Python
Debug Exposure CWE-215 Python
Code Injection CWE-94 JS
Prototype Pollution CWE-1321 JS
NoSQL Injection CWE-943 JS

Patterns are fully configurable in Memory/security_patterns.json.

Technology Stack

  • Language: Python 3.10+
  • GitHub API: REST API v3 (simulated; real integration template included)
  • Data Format: JSON
  • LLM (optional): Any OpenAI-compatible API for enhanced natural-language review comments

Key Design Decisions

  • Parallel agents: Agents 2 and 3 are independent, enabling concurrent execution
  • Configurable rules: All security patterns and style rules live in JSON memory files, not hardcoded
  • Comment cap: Maximum 30 inline comments per review to avoid spamming large PRs
  • Verdict logic: Deterministic — critical/high security findings always trigger REQUEST_CHANGES
  • Audit trail: Every agent invocation is logged for traceability

About

An agentic AI system that automates pull request code review on GitHub.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages