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.
- 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)
- Python 3.11+
- Groq SDK (
groq) - FastAPI + Uvicorn (web backend/UI serving)
- python-dotenv (environment loading)
- pytest (tests)
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
- Create and activate a virtual environment.
python -m venv .venv
.\.venv\Scripts\Activate.ps1- Install dependencies.
pip install -r requirements.txt- Configure environment variables.
- Copy
.env.exampleto.env - Set your own Groq API key
Copy-Item .env.example .envExpected variable:
GROQ_API_KEY=your_groq_api_key
python src/agent.pyCLI commands:
exit-> quitreset-> clear conversation historyfile <path>-> review a file from disk
Example:
You: file example/bad_code.py
You: Review this function: def divide(a, b): return a / b
Start backend:
uvicorn ui.server:app --reload --port 8000Open:
Main API routes:
GET /-> serves UIPOST /chat-> sends free-form message to agentPOST /review-file-> reviews a local file pathPOST /reset-> clears conversation historyGET /history-> returns in-memory chat historyGET /health-> health/model/provider info
python src/benchmark.pyBenchmark 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
pytest -q- Initializes Groq client using
GROQ_API_KEY - Uses model:
openai/gpt-oss-120b(theMODELconstant; Groq retiredllama-3.3-70b-versatilefor free and developer keys in August 2026) - Maintains in-memory
conversation_history - Exposes:
chat(user_message: str) -> strreview_file(file_path: str) -> strscore_from_response(response_text: str) -> int | Nonereset_conversation() -> None
- Defines benchmark test suite and evaluation dataclasses
- Computes per-dimension and composite scores
- Exposes
run_benchmark(agent_fn)to evaluate any compatible agent callable
- Loads the same core agent functions
- Serves static frontend
- Provides API endpoints for chat/file review/reset/history/health
- 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.
-
RuntimeError: GROQ_API_KEY is not set- Add
GROQ_API_KEYin.envand restart the process.
- Add
-
model_not_foundfrom Groq- The model in
MODEL(src/agent.py) is no longer served for your key. Pick a current one from https://console.groq.com/docs/models.
- The model in
-
ModuleNotFoundError- Reinstall dependencies with
pip install -r requirements.txtin the active environment.
- Reinstall dependencies with
-
UI cannot connect to backend
- Ensure Uvicorn is running on port 8000.
- Check that requests go to
http://localhost:8000.
MIT © 2026 Mark Rodrigues