Files
2026-06-11 16:10:24 +00:00

1.1 KiB

LangGraph Code Review Agent

Overview

This repository contains a LangGraph agent that performs a code review on a given Python function. The agent:

  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

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.