56444e4c8458a7a9db257ef2417038c48f6c4998
LangGraph Code Review Agent
Overview
This repository contains a LangGraph agent that performs a code review on a given Python function. The agent:
- Generates an initial draft review.
- Critiques the draft on four criteria (PEP8, type hints, edge cases, naming).
- If the review needs revision, rewrites the weakest part up to a maximum number of rounds.
Requirements
langgraph>=0.2.0
langchain-openai>=0.2.0
python-dotenv
Install dependencies:
pip install -r requirements.txt
Running the Demo
python main.py
The demo uses a simple sort_numbers function. The output shows the final review, the scores, and the verdict.
Usage
You can import the run_demo function or use the graph directly in your own code.
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)
Environment Variables
The agent uses OpenAI. Set OPENAI_API_KEY in your environment or in a .env file.
Description
Languages
Python
100%