An intelligent, multi-agent system that automates grading of complex academic essay questions with human-level reasoning and detailed pedagogical feedback. Built as a Capstone Project in Computer Science Engineering.
Key Capabilities:
- π€ Multi-Agent Architecture with consensus-based grading
- π Batch Processing optimized for high throughput
- π― Pedagogical Feedback explaining grading decisions
- π Enterprise-Ready with error handling and resilience
- 5x throughput improvement β Grading 30 submissions reduced from 10+ minutes to ~2 minutes
- 90% reduction in vector DB queries via intelligent RAG caching
- Dual-examiner consensus β 2 independent Examiner agents + 1 Arbiter reduces bias
- Full explainability β Every grade includes written justification traceable to rubric criteria
The grading system employs a distributed, consensus-based architecture orchestrated through LangGraph and optimized using DSPy for intelligent prompt engineering.
| Agent | Role | Description |
|---|---|---|
| Examiner C1 | Primary Evaluator | Grades submissions independently against rubric using RAG |
| Examiner C2 | Secondary Evaluator | Independent evaluation for consensus validation |
| Arbiter | Dispute Resolution | Activated when divergence exceeds threshold; mediates final grade |
| Analytics Engine | Quality Assurance | Detects plagiarism, tracks student progress, provides insights |
graph TD
A[Student Submission] --> B(RAG Context Retrieval)
B --> C1[Examiner 1]
B --> C2[Examiner 2]
C1 --> D{Divergence Check}
C2 --> D
D -->|Difference > 1.5 points| E[Arbiter Resolution]
D -->|Within Threshold| F[Consensus Reached]
E --> F
F --> G[Generate Feedback]
G --> H[Store Results]
H --> I[Analytics Pipeline]
I --> J[Complete]
- π Parallel Batch Processing β Handles high-volume submissions without hitting LLM rate limits (async workers + chunking strategy)
- π§© Stateful LangGraph Workflow β Uses
StateGraphnodes/edges to orchestrate retrieval, dual evaluation, arbitration, and final decision routing - π Production RAG Pipeline β Indexes exam attachments via PDF chunking + embeddings + ChromaDB retrieval
- πΎ Persistent Vector Store β Stores vectors on disk for reuse across runs, avoiding unnecessary re-indexing
- π Flexible Embedding Providers β Supports Google, OpenAI, and local Ollama embeddings via environment configuration
- π‘ Intelligent Cost Optimization β Tiered model strategy (Gemini 2.0 Flash for routine grading, Pro for complex arbitration)
- π‘οΈ Production-Grade Resilience β Self-healing logic with retry mechanisms, graceful API error handling, and JSON validation
- π Context-Aware Feedback β Pedagogical explanations that help students understand grading rationale
- π Academic Integrity Checks β Semantic similarity detection across submissions
- π Student Progress Analytics β Tracks performance trends and learning patterns
- ποΈ Postgres + Alembic β Versioned database migrations for reproducible deployments
| Layer | Technology | Purpose |
|---|---|---|
| Orchestration | LangGraph | Multi-agent workflow engine |
| Prompt Engineering | DSPy (Stanford) | Structured prompt optimization |
| LLM Provider | Google Gemini 2.0 Flash/Pro | Core AI reasoning |
| LLM Interface | LiteLLM | Unified LLM abstraction |
| Embeddings | Google / OpenAI / Ollama | Configurable vector generation |
| Backend API | FastAPI | REST endpoints |
| Database | PostgreSQL 16 | Persistent data storage |
| Migrations | Alembic | Schema versioning |
| Vector Search | ChromaDB | RAG context retrieval |
| Containerization | Docker & Docker Compose | Local & cloud deployment |
Ensure you have the following installed:
- Docker (v20.0+) and Docker Compose (v2.0+)
- Git (for version control)
- Python (v3.12+) β only if running locally without Docker
git clone https://github.com/savinoo/ai-grading-system.git
cd ai-grading-systemEnvironment templates are available at the project root. Follow these steps:
cp database.env.example database.env
# Windows (PowerShell): Copy-Item database.env.example database.envThe root database.env contains shared Docker Compose settings (PostgreSQL credentials).
cp .env.example .env
# Windows (PowerShell): Copy-Item .env.example .envThen edit .env and set:
DATABASE_URLβ PostgreSQL connection string (must match values fromdatabase.env)GOOGLE_API_KEYβ Your Google Gemini API key (get from Google AI Studio)SECRET_KEYβ Random string for JWT signing (generate viapython -c "import secrets; print(secrets.token_urlsafe(32))")BREVO_API_KEYβ Email service key (optional, for notifications)EMBEDDING_PROVIDERβgoogle,openai, orlocal(Ollama)EMBEDDING_MODELβ Optional override for embedding model- Other settings as needed (see detailed comments in
.env.example)
This is the fastest and most reliable approach.
cd ai-grading-system
docker compose up -dThis will spin up:
- Backend (FastAPI on
http://localhost:8000) - PostgreSQL (on
localhost:5432) - Ollama (on
http://localhost:11434)
docker compose exec backend alembic upgrade headThis applies all migrations in sequence:
- Database infrastructure (extensions, functions)
- Core schema (tables for users, exams, grading criteria, etc.)
- Triggers (auto-update timestamps)
- Seed data (default grading criteria)
- Backend API Docs: Open http://localhost:8000/docs (Swagger UI)
- Health Check:
curl http://localhost:8000/health
If you prefer running locally:
# Create virtual environment
python -m venv .venv
source .venv/bin/activate # On Windows (PowerShell): .venv\Scripts\Activate.ps1
# Install dependencies
pip install -r requirements.txt
# Run migrations
alembic upgrade head
# Start server
uvicorn src.main.server.server:app --reload --port 8000| Issue | Solution |
|---|---|
| Docker build fails | Run docker compose down -v to remove volumes, then retry |
| Port 5432 already in use | Check docker ps for conflicting containers or change port in docker-compose.yml |
| Alembic migration fails | Verify DATABASE_URL in .env, ensure PostgreSQL is running |
| LLM API errors | Verify GOOGLE_API_KEY is valid and has quota available |
# Generate a new migration file
docker compose exec backend alembic revision --autogenerate -m "description of changes"
# Review the generated migration file in alembic/versions/
# Apply the migration
docker compose exec backend alembic upgrade headrevisionIDsdown_revisionreferences- Migration order
β Safe to modify:
- Migration file names
- SQL logic and table definitions
# Revert to previous migration
docker compose exec backend alembic downgrade -1
# Revert to specific revision
docker compose exec backend alembic downgrade <revision_id># Format code
docker compose exec backend black src/
# Run linting
docker compose exec backend pylint src/
# Run tests
docker compose exec backend pytest
# Shell access
docker compose exec backend bash- Set
ENVIRONMENT=productionin backend.env - Set
DEBUG=false - Use production LLM keys
- Configure proper
CORS_ORIGINS - Set up database backups
- Enable HTTPS/SSL
- Review and test all migrations
- Set resource limits in Docker Compose
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit changes (
git commit -m 'Add amazing feature') - Push to branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License β see LICENSE for details.
- Built with LangGraph by LangChain AI
- Prompt optimization powered by DSPy from Stanford NLP
- LLM inference via Google Gemini and LiteLLM
Last Updated: March 2026 | Status: Active Development