Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 123 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,48 +1,130 @@
# 🧠 ReviewPal: AI-powered Pull Request Review Agent
# 🧠 ReviewPal: AI-Powered Pull Request Review System

> Automatically review GitHub Pull Requests with standard-compliant inline comments — powered by Gemini + LangGraph.
> 🚀 Automated, context-aware GitHub PR reviews using **RAG, LLMs, and parallel processing** — designed for real-world codebases.

## 📌 Features
## 📌 Overview

ReviewPal is an intelligent code review system that analyzes GitHub Pull Requests and generates **high-quality, standards-compliant inline feedback**.

Unlike basic LLM tools, it uses a **Retrieval-Augmented Generation (RAG) pipeline** to incorporate:

- 📂 Repository code context
- 📐 Organization-specific coding standards
- 🧠 Language-aware understanding

## ✨ Key Features

- 🤖 **AI-powered PR reviews** using Gemini LLM
- 🧠 **RAG-based architecture** (ChromaDB) for context-aware suggestions
- ⚡ **Parallel diff processing** for fast reviews (~1–2 minutes)
- 🎯 Comments only on **newly added lines** (zero noise)
- 📐 **Standards-driven reviews** (customizable per repo)
- 🌍 **Language-aware retrieval** (Python, TypeScript, C#)
- 🔁 **Incremental indexing with content hashing** (cost-efficient)
- 💾 **CI-integrated vector caching** for persistent performance
- 🧪 Robust **validation layer** (deduplication + correctness checks)

- ✅ AI-based automated code review for GitHub Pull Requests
- 🎯 Adds inline comments strictly on newly added lines only
- 📐 Fully standards-compliant reviews — supports any language/codebase (standards are configurable)
- 🔧 Modular LangChain tools to fetch diffs and post suggestions
- 🤖 Uses Gemini (via langchain-google-genai) and LangGraph's ReAct-style agent
- 🧪 Minimal setup and fully environment-driven configuration

## 🧱 Architecture

![ReviewPal architecture img](images/ReviewPal_architecture.jpg)
![ReviewPal architecture img](images/ReviewPal_architecture.png)

### 🔹 System Overview

The system consists of two major flows:

---

### ⚙️ 1. Indexing Pipeline (RAG Setup)

Runs in CI to prepare context:

- Parses repository source code
- Indexes coding standards
- Generates embeddings using Gemini
- Stores vectors in ChromaDB
- Uses **content hashing** to avoid re-indexing unchanged files
- Supports **multi-repo isolation via `repo_id`**

---

### ⚡ 2. Review Pipeline

Triggered on Pull Requests:

1. Fetch PR diffs via GitHub API
2. Chunk diffs for efficient processing
3. Process chunks in **parallel threads**
4. Retrieve relevant:
- Code context
- Coding standards
5. Generate review comments using LLM
6. Validate comments:
- Only on added lines
- Remove duplicates
- Enforce format
7. Post inline comments to GitHub

## 🧠 Core Concepts

### 🔍 Retrieval-Augmented Generation (RAG)

ReviewPal enhances LLM outputs by retrieving:

- Relevant code snippets from the repository
- Applicable coding standards

The architecture consists of six layers:
This significantly reduces hallucinations and improves accuracy.

- **User Interaction**: Initiates review via CLI or automation, provides PR details
- **LLM Agent Orchestrator**: LangGraph-powered Gemini agent that manages tool calling and flow control
- **Tool Functions Layer**: Wraps GitHub tools like fetch_pr_files() and post_inline_comments() as LangChain tools
- **GitHub REST API Access**: Handles actual HTTP operations to fetch file diffs and post reviews
- **Code Analysis & Processing**: Loads code standards, analyzes diffs, and generates suggestions
- **Review Result Dispatcher**: Final step to post comments and optionally notify the user
---

### ⚡ Parallel Processing

Diff chunks are processed concurrently using multithreading, enabling:

- Faster review times
- Scalability for large PRs

---

### 🧩 Language-Aware Filtering

Retrieval is scoped by file type:
E.g.
- .py → Python context
- .ts → TypeScript context
- .cs → C# context
---

### 🔁 Incremental Indexing

Uses content hashing to:

- Detect changed files
- Re-embed only modified content
- Reduce API usage and cost

---

## 🚀 Getting Started

### 1\. Clone the repository

```
```bash
git clone https://github.com//ReviewPal.git cd ReviewPal
```

### 2\. Install dependencies

```
```bash
pip install -r requirements.txt
```

### 3\. Set up environment variables

Create a .env file with the following keys:

```
```bash
GEMINI_API_KEY=your_gemini_api_key
TOKEN_GITHUB=your_github_pat
GITHUB_REPO=username/repo-name
Expand All @@ -51,31 +133,38 @@ Create a .env file with the following keys:

## 🧪 Usage

To run the review agent:

Run indexing (RAG setup)
```bash
python scripts/index_repo.py --path . --repo-id your-org/repo standards-path ./standards
```
python review_agent.py

To run the review pipeline:V

```bash
python src/pipeline/pipeline.py
```
## ⚙️ CI Integration (GitHub Actions)

This will:
ReviewPal integrates directly into PR workflows:

- Fetch the PR diff
- Analyze the code using AI based on your provided standards
- Post inline review comments directly on GitHub
- Runs indexing with caching
- Executes review pipeline automatically
- Posts inline comments on PRs

## 📌 Technologies Used

- Python 3.10+
- LangGraph
- LangChain
- [Gemini (Google Generative AI)](https://ai.google.dev/)
- [httpx](https://www.python-httpx.org/)
- Python 3.10+
- ChromaDB (Vector Store)
- GitHub REST API
- ThreadPoolExecutor (parallelism)

## 🔮 Future Scope

- Support for multiple cooperating agents (e.g., security reviewer, style reviewer, performance reviewer)
- Integration with an MCP (Multi-Context Processor) Server for:

- Contextual codebase awareness
- Database/stateful session memory
- Connecting PRs to JIRA and validating against acceptance criteria
- Multi-agent reviewers (security, performance, style)
- Semantic duplicate detection
- PR summary + risk scoring
- Connecting PRs to JIRA and validating against acceptance criteria
Binary file removed images/ReviewPal_architecture.jpg
Binary file not shown.
Binary file added images/ReviewPal_architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading