Skip to content

About

AI code-review agent returning structured JSON findings - bugs, security vulnerabilities, and performance issues - with severity ratings and line-specific fixes. Web UI and API, live on Hugging Face Spaces.

Resources

Stars

1 star

Watchers

0 watching

Forks

Repository files navigation

Code-Review-Agent

Code-Review-Agent is a specialized AI code review assistant built in Python. It reviews pasted code or full files, returns structured findings, and can be used from both:

  • A CLI chat loop
  • A FastAPI web UI

The project also includes a benchmark module and a pytest test suite.

What it does

  • Detects common bug patterns (off-by-one, mutable defaults, race windows)
  • Flags security issues (injection patterns, hardcoded secrets)
  • Highlights performance risks (N+1-like access patterns)
  • Provides style and test-related review guidance
  • Returns responses in a structured JSON-friendly format (when prompted)

Tech stack

  • Python 3.11+
  • Groq SDK (groq)
  • FastAPI + Uvicorn (web backend/UI serving)
  • python-dotenv (environment loading)
  • pytest (tests)

Project structure

Code-Review-Agent/
  src/
    agent.py          # Core chat/review logic (Groq client + conversation history)
    benchmark.py      # Evaluation suite with weighted scoring (0-10,000)
  ui/
    server.py         # FastAPI app bridging browser UI to the agent
    static/
      index.html      # Frontend UI
  tests/
    conftest.py       # Sets a dummy GROQ_API_KEY so tests run without a real key
    test_agent.py     # Unit tests for agent + benchmark behavior
    test_server.py    # HTTP tests for the FastAPI routes
  example/
    bad_code.py       # Intentionally vulnerable code sample
  pytest.ini          # Puts the repo root on the import path for pytest
  requirements.txt
  .env.example

Setup

  1. Create and activate a virtual environment.
python -m venv .venv
.\.venv\Scripts\Activate.ps1
  1. Install dependencies.
pip install -r requirements.txt
  1. Configure environment variables.
  • Copy .env.example to .env
  • Set your own Groq API key
Copy-Item .env.example .env

Expected variable:

GROQ_API_KEY=your_groq_api_key

Run the CLI agent

python src/agent.py

CLI commands:

  • exit -> quit
  • reset -> clear conversation history
  • file <path> -> review a file from disk

Example:

You: file example/bad_code.py
You: Review this function: def divide(a, b): return a / b

Run the web UI

Start backend:

uvicorn ui.server:app --reload --port 8000

Open:

Main API routes:

  • GET / -> serves UI
  • POST /chat -> sends free-form message to agent
  • POST /review-file -> reviews a local file path
  • POST /reset -> clears conversation history
  • GET /history -> returns in-memory chat history
  • GET /health -> health/model/provider info

Run benchmark

python src/benchmark.py

Benchmark summary:

  • Uses 5 planted test cases:
    • SQL Injection
    • Hardcoded Secret
    • Off-by-one Loop
    • N+1 Query
    • Race Condition
  • Scores across weighted dimensions:
    • accuracy (35%)
    • relevance (20%)
    • specificity (20%)
    • latency (10%)
    • format (10%)
    • false positives (5%)
  • Produces a composite score on a 0-10,000 scale

Run tests

pytest -q

Core modules

src/agent.py

  • Initializes Groq client using GROQ_API_KEY
  • Uses model: openai/gpt-oss-120b (the MODEL constant; Groq retired llama-3.3-70b-versatile for free and developer keys in August 2026)
  • Maintains in-memory conversation_history
  • Exposes:
    • chat(user_message: str) -> str
    • review_file(file_path: str) -> str
    • score_from_response(response_text: str) -> int | None
    • reset_conversation() -> None

src/benchmark.py

  • Defines benchmark test suite and evaluation dataclasses
  • Computes per-dimension and composite scores
  • Exposes run_benchmark(agent_fn) to evaluate any compatible agent callable

ui/server.py

  • Loads the same core agent functions
  • Serves static frontend
  • Provides API endpoints for chat/file review/reset/history/health

Notes

  • Conversation history is in-memory only and resets when process restarts.
  • File review uses local filesystem paths passed to the backend.
  • Keep secrets in .env; do not commit real API keys.

Quick troubleshooting

  • RuntimeError: GROQ_API_KEY is not set

    • Add GROQ_API_KEY in .env and restart the process.
  • model_not_found from Groq

  • ModuleNotFoundError

    • Reinstall dependencies with pip install -r requirements.txt in the active environment.
  • UI cannot connect to backend

    • Ensure Uvicorn is running on port 8000.
    • Check that requests go to http://localhost:8000.

License

MIT © 2026 Mark Rodrigues

About

AI code-review agent returning structured JSON findings - bugs, security vulnerabilities, and performance issues - with severity ratings and line-specific fixes. Web UI and API, live on Hugging Face Spaces.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages