Skip to content

HoneyTyagii/Autonomous-Code-Review-Agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

23 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Autonomous Code Review Agent

A production-grade AI agent that autonomously reviews GitHub pull requests β€” understanding repository context, enforcing coding standards, running security analysis, and posting actionable feedback with auto-generated fix patches.

Open a PR. The agent reviews it. No human in the loop.

Python FastAPI PostgreSQL Redis Docker OpenAI License


✨ Highlights

Capability Description
πŸ”— GitHub App Integration Webhook-driven β€” installs on any repo, posts reviews as inline comments with approve/reject
🌳 Multi-language AST Tree-sitter parsing for Python, JavaScript, TypeScript β€” understands code structure, not just text
🧠 RAG-powered Context ChromaDB vector store retrieves related code + coding standards for context-aware reviews
🐳 Docker Sandbox Runs linters, type checkers, and tests in isolated containers with CPU/memory limits
πŸ”’ Security Scanning Bandit + Semgrep + regex secret detection β€” catches vulnerabilities before merge
πŸ› Bug Prediction Heuristic-based risk scoring (entropy, error handling removal, sensitive file changes)
🩹 Auto-generated Patches Produces git apply-ready unified diffs and GitHub suggestion blocks
πŸ“š Review Memory Learns from past reviews β€” tracks author patterns, detects false positives, avoids repetition
πŸ”Œ MCP Server Model Context Protocol interface for IDE integration and extensible tool access
⚑ Async Processing Celery + Redis task queue β€” reviews run in background, webhook returns instantly

πŸš€ Quickstart

Option 1 β€” Full stack with Docker Compose (recommended)

git clone https://github.com/HoneyTyagii/Autonomous-Code-Review-Agent.git
cd Autonomous-Code-Review-Agent
cp .env.example .env   # Fill in your API keys and GitHub App credentials

docker compose up -d --build
docker compose run --rm migrations

Option 2 β€” Local development

python -m venv .venv
.venv\Scripts\activate          # Windows
# source .venv/bin/activate     # Linux/Mac

pip install -e ".[dev]"
python -m code_review_agent.main

Verify it's running

Endpoint Purpose
http://localhost:8000/health Liveness check β†’ {"status":"healthy"}
http://localhost:8000/health/ready Readiness check (DB, Redis, ChromaDB)
http://localhost:8000/docs Interactive Swagger UI

πŸ—ΊοΈ How It Works

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  PR Opened       β”‚  GitHub webhook fires
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Fetch Diff      β”‚  Parse unified diff β†’ structured hunks with line mapping
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Understand Repo β”‚  Tree-sitter AST + RAG retrieval of related code
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Load Standards  β”‚  Vector search for applicable coding rules
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Static Analysis β”‚  ruff, mypy, eslint in Docker sandbox
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Security Scan   β”‚  Bandit + Semgrep + secret detection
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Bug Prediction  β”‚  Heuristic risk scoring on the diff
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  LLM Review      β”‚  GPT-4o / Claude with structured JSON output
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Generate Fixes  β”‚  Auto-patches as unified diffs
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Post to GitHub  β”‚  Inline comments + approve / request changes
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Layer Technology
API FastAPI, uvicorn, Pydantic
LLM OpenAI GPT-4o, Anthropic Claude (pluggable via factory)
Embeddings OpenAI text-embedding-3-small / Sentence Transformers
Vector Store ChromaDB (cosine similarity, per-repo collections)
AST Tree-sitter (Python, JavaScript, TypeScript grammars)
Database PostgreSQL 16 + SQLAlchemy 2.0 (async) + Alembic migrations
Queue Celery + Redis (separate broker/result queues)
Sandbox Docker SDK (resource-limited, read-only, network-isolated)
Security Bandit, Semgrep, regex-based secret detection
GitHub App JWT auth, installation tokens, webhook HMAC verification
Observability structlog (JSON in prod, colored console in dev)
MCP Model Context Protocol server (stdio transport)

πŸ“ Project Structure

src/code_review_agent/
β”œβ”€β”€ main.py                    FastAPI app + lifespan management
β”œβ”€β”€ config.py                  Pydantic settings (all env vars)
β”œβ”€β”€ logging.py                 Structured logging (structlog)
β”‚
β”œβ”€β”€ api/                       HTTP layer
β”‚   β”œβ”€β”€ webhooks.py              GitHub webhook receiver
β”‚   β”œβ”€β”€ webhook_security.py      HMAC-SHA256 signature verification
β”‚   └── health.py                Liveness + readiness probes
β”‚
β”œβ”€β”€ github/                    GitHub integration
β”‚   β”œβ”€β”€ auth.py                  JWT + installation token auth
β”‚   β”œβ”€β”€ client.py                Async API client with retry + rate limits
β”‚   β”œβ”€β”€ diff_parser.py           Unified diff β†’ structured hunks
β”‚   └── pr_fetcher.py            Assembles complete PR context
β”‚
β”œβ”€β”€ analysis/                  Code analysis
β”‚   β”œβ”€β”€ ast_parser.py            Tree-sitter multi-language parsing
β”‚   β”œβ”€β”€ security_scanner.py      Bandit + Semgrep + secrets
β”‚   └── bug_predictor.py         Heuristic risk scoring
β”‚
β”œβ”€β”€ core/                      Review engine
β”‚   β”œβ”€β”€ engine.py                Pipeline orchestrator (whole-PR / per-file)
β”‚   β”œβ”€β”€ prompts.py               LLM prompt construction
β”‚   β”œβ”€β”€ schemas.py               Structured output JSON schemas
β”‚   └── patch_generator.py       Auto-fix generation (unified diff)
β”‚
β”œβ”€β”€ llm/                       LLM abstraction
β”‚   β”œβ”€β”€ base.py                  Interface + Message/Response types
β”‚   β”œβ”€β”€ openai_provider.py       OpenAI with retry + JSON mode
β”‚   β”œβ”€β”€ anthropic_provider.py    Claude with system message handling
β”‚   └── factory.py               Provider factory from config
β”‚
β”œβ”€β”€ rag/                       Retrieval-Augmented Generation
β”‚   β”œβ”€β”€ embeddings.py            Multi-provider embedding service
β”‚   β”œβ”€β”€ vector_store.py          ChromaDB client wrapper
β”‚   β”œβ”€β”€ indexer.py               AST-aware code chunking + batch indexing
β”‚   β”œβ”€β”€ retriever.py             Semantic context retrieval
β”‚   └── standards_loader.py      Coding standards ingestion (Markdown β†’ rules)
β”‚
β”œβ”€β”€ sandbox/                   Isolated execution
β”‚   β”œβ”€β”€ docker_sandbox.py        Docker container management
β”‚   └── analysis_runner.py       Linter/test orchestration
β”‚
β”œβ”€β”€ memory/                    Learning system
β”‚   β”œβ”€β”€ review_memory.py         Persistence + semantic search over history
β”‚   └── learning.py              Author profiling + false positive detection
β”‚
β”œβ”€β”€ tasks/                     Background processing
β”‚   β”œβ”€β”€ celery_app.py            Celery configuration + routing
β”‚   └── review_tasks.py          Async review pipeline + GitHub posting
β”‚
β”œβ”€β”€ models/                    Database ORM
β”‚   β”œβ”€β”€ repository.py            Repository tracking model
β”‚   └── review.py                Review + ReviewComment models
β”‚
β”œβ”€β”€ db/                        Database layer
β”‚   └── session.py               Async engine + session factory
β”‚
└── mcp/                       Model Context Protocol
    β”œβ”€β”€ server.py                JSON-RPC server
    β”œβ”€β”€ tools.py                 6 exposed tools
    └── transport.py             Stdio transport for IDEs

πŸ§ͺ Development

make install          # Install in dev mode
make test             # Run pytest with coverage
make check            # Lint + typecheck
make format           # Auto-format with ruff
make dev              # Full dev stack (hot-reload + Flower monitoring)
Command Description
make dev Start full dev stack with hot-reload
make test Run pytest with coverage
make lint Run ruff linter
make typecheck Run mypy
make migrate Run database migrations
make psql Connect to PostgreSQL
make logs Tail all service logs
make clean Remove build artifacts

πŸ”Œ MCP Integration

The agent exposes a Model Context Protocol server for IDE integration:

python -m code_review_agent.mcp.transport

Exposed tools:

Tool Description
review_diff Review a code diff with full LLM pipeline
check_security Run security scans on code
query_standards Find relevant coding standards
search_past_reviews Semantic search over review history
generate_patch Generate a fix as unified diff
predict_bugs Heuristic bug risk analysis

βš™οΈ Configuration

All settings via environment variables (see .env.example):

Variable Description Default
GITHUB_APP_ID GitHub App numeric ID β€”
GITHUB_WEBHOOK_SECRET Webhook HMAC secret β€”
LLM_PROVIDER openai or anthropic openai
OPENAI_MODEL Model for reviews gpt-4o
ENABLE_SECURITY_SCAN Run Bandit + Semgrep true
SANDBOX_TIMEOUT Docker sandbox timeout (s) 300
SANDBOX_MEMORY_LIMIT Container memory cap 512m
DATABASE_URL PostgreSQL connection postgresql+asyncpg://...
REDIS_URL Redis connection redis://localhost:6379/0

πŸ—οΈ Demonstrates

Domain What's showcased
AI/ML Engineering LLM orchestration, RAG pipelines, embeddings, structured output, prompt engineering
Backend Development Async Python, FastAPI, SQLAlchemy, Celery, Redis, PostgreSQL
DevOps Docker multi-stage builds, Compose orchestration, health checks, Makefile automation
Systems Design Event-driven architecture, webhook processing, background tasks, graceful degradation
Security Engineering HMAC verification, sandboxed execution, secret scanning, non-root containers
Software Engineering Clean architecture, SOLID principles, type safety, structured logging, migrations

πŸ“„ License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages