add README.md
This commit is contained in:
@@ -1,33 +1,54 @@
|
||||
# LangGraph Code Review Agent
|
||||
|
||||
This repository implements a LangGraph agent that performs a code review on a Python function. The graph consists of three nodes:
|
||||
## Overview
|
||||
|
||||
1. **draft_review** – generates an initial review.
|
||||
2. **reflect** – a critic that scores the review on four criteria (PEP8, type hints, edge cases, naming) and decides whether a rewrite is required.
|
||||
3. **rewrite** – rewrites the weakest part of the review.
|
||||
This repository contains a LangGraph agent that performs a code review on a given Python function. The agent:
|
||||
|
||||
The graph runs for a maximum of `max_rounds` (default 2). The demo can be executed with `python -m main`.
|
||||
1. Generates an initial draft review.
|
||||
2. Critiques the draft on four criteria (PEP8, type hints, edge cases, naming).
|
||||
3. If the review needs revision, rewrites the weakest part up to a maximum number of rounds.
|
||||
|
||||
## Requirements
|
||||
|
||||
```text
|
||||
langgraph>=0.2.0
|
||||
langchain-openai>=0.2.0
|
||||
python-dotenv>=1.0.0
|
||||
python-dotenv
|
||||
```
|
||||
|
||||
Install dependencies:
|
||||
|
||||
```bash
|
||||
pip install -r requirements.txt
|
||||
```
|
||||
|
||||
## Running the Demo
|
||||
|
||||
```bash
|
||||
python main.py
|
||||
```
|
||||
|
||||
The demo uses a simple `sort_numbers` function. The output shows the final review, the scores, and the verdict.
|
||||
|
||||
## Usage
|
||||
|
||||
```bash
|
||||
# Install dependencies
|
||||
pip install -r requirements.txt
|
||||
You can import the `run_demo` function or use the graph directly in your own code.
|
||||
|
||||
# Run the demo
|
||||
python -m main
|
||||
```python
|
||||
from main import graph, CodeReviewState
|
||||
|
||||
state = CodeReviewState(
|
||||
code="def foo(x): return x+1",
|
||||
draft_review="",
|
||||
criteria_scores={},
|
||||
weakest_criterion="",
|
||||
verdict="",
|
||||
round=0,
|
||||
max_rounds=2,
|
||||
)
|
||||
result = await graph.ainvoke(state)
|
||||
```
|
||||
|
||||
The demo uses a simple `sort_numbers` function. The output shows the final review, the scores for each criterion, the verdict, and the number of rounds performed.
|
||||
|
||||
## Environment Variables
|
||||
|
||||
The agent uses OpenAI. Set the `OPENAI_API_KEY` environment variable before running.
|
||||
The agent uses OpenAI. Set `OPENAI_API_KEY` in your environment or in a `.env` file.
|
||||
|
||||
Reference in New Issue
Block a user