Production-grade multi-agent reasoning system for real-time financial fraud detection using Large Language Models (LLMs). Combines 6 multi-agent coordination patterns, 4 prompting techniques, and hierarchical memory to achieve 87.3% F1-score on 6.36M transactions.
- π€ Multi-Agent Coordination: 6 patterns (single, manager-worker, planner-executor-critic, debate, role-specialized, swarm)
- π§ Advanced Reasoning: Hypothesis generation, counterfactual analysis, constraint satisfaction
- π Production Performance: 87.3% F1 (ReAct) | 91.2% F1 (Debate) | 3.12s p95 latency | 1,150 txn/min
- π RAG System: Hierarchical memory (5-tier: short-term β procedural) with ChromaDB + Redis
- π‘οΈ Safety-First: Prompt injection defense (94% prevention), bias mitigation, HITL escalation
- π Full Explainability: Reasoning traces with tool grounding (4.6/5.0 faithfulness)
- π― Tool Infrastructure: 6 production tools with circuit breakers, retry logic, fallback chains
- π¬ Autonomy Control: 5-level HITL system with confidence-based escalation
- π‘ Production Deployment: Kubernetes with HPA, Prometheus monitoring, 99.7% availability
- π Privacy-First: Local LLM inference (Ollama), no data leaves infrastructure
- βοΈ Bias Mitigation: Demographic parity monitoring, fairness metrics
π Full Architecture: See docs/architecture/ARCHITECTURE-2026.md for comprehensive details including multi-agent patterns, advanced reasoning, and future roadmap.
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 1: PRESENTATION (Next.js 14) β
β β’ Transaction submission UI β’ Reasoning trace visualizer β
β β’ Analyst HITL dashboard β’ Audit log explorer β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β HTTPS + WebSocket
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 2: API GATEWAY (FastAPI) β
β β’ RESTful routes β’ JWT auth β’ Rate limiting β’ Input validation β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 3: ORCHESTRATION (LangGraph + Reasoning + Memory) β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββ β
β β Multi-Agent β β Reasoning β β Memory (5-tier) β β
β β β’ Single β β β’ Hypothesis β β β’ Short-term (session) β β
β β β’ Manager- β β β’ Counter- β β β’ Working (Redis 1h) β β
β β Worker β β factual β β β’ Episodic (ChromaDB) β β
β β β’ Planner- β β β’ Constraint β β β’ Semantic (ChromaDB) β β
β β Executor- β β β’ Uncertaintyβ β β’ Procedural (schemas) β β
β β Critic β β β β β β β
β β β’ Debate π β β β β β β
β β β’ Role-Spec β β β β β β
β β β’ Swarm β β β β β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββββββββββββ β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 4: LLM INFERENCE (Ollama) β
β β’ Mistral-7B-Instruct-v0.2 (Q4_K_M, 4.1GB) β
β β’ Llama-2-7B-Chat (Q4_K_M, 3.8GB) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 5: DATA PERSISTENCE β
β ChromaDB (Vector) β’ Redis (Cache) β’ PostgreSQL (Analytics) β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β Layer 6: TOOL INFRASTRUCTURE β
β 6 tools: risk_score β’ fraud_policy β’ account_history β’ anomalies β
β Features: Circuit breakers β’ Retry logic β’ Health monitoring β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
Legend: π Highest Accuracy (91.2% F1) | β Production Default (88.9% F1, best cost-accuracy)
- Source: Kaggle - PaySim1
- Size: 6,362,620 transactions (4.45M train, 955K val, 955K test)
- Fraud Rate: 0.13% (highly imbalanced)
- Location:
data/raw/PS_*.csv - Features: 11 base β 30 engineered features
- Challenge: Class imbalance, temporal patterns, adversarial fraud
# Run complete 8-step pipeline
cd backend
python scripts/prepare_data_pipeline.pyPipeline Steps:
- Data Cleaning - Handle missing values, normalize, engineer features (30 final features)
- Dataset Splitting - Stratified & temporal splits (70/15/15 train/val/test)
- Data Augmentation - SMOTE balancing for class imbalance (3 strategies)
- Weak Supervision - Generate labels and RLHF preference pairs
- Fraud Explanations - LLM-generated explanations (100 samples)
- Bias Analysis - Fairness audit with demographic parity checks
- Data Lineage - Complete data provenance tracking
- Vectorization - Populate ChromaDB with 639 embeddings for RAG
Quick Options:
# Quick mode (skip augmentation, faster)
python scripts/prepare_data_pipeline.py --quick
# Skip specific steps
python scripts/prepare_data_pipeline.py --skip-steps augmentation,bias_analysis
# Generate execution report
python scripts/prepare_data_pipeline.py --generate-reportOutput: All processed data in data/ directory + ChromaDB collections ready for inference.
See backend/scripts/README.md for detailed documentation.
Automated data validation ensures data quality throughout the MLOps pipeline:
# Validate raw data
pnpm data:validate
# Validate cleaned data
pnpm data:validate:cleaned
# Strict mode (fail on warnings)
pnpm data:validate:strict
# Drift detection (compare current vs baseline)
pnpm data:validate:driftValidation Checks:
- β Schema validation (columns, data types)
- β Missing value detection
- β Duplicate detection
- β Outlier detection (IQR method)
- β Fraud rate validation
- β Drift detection (KS test)
Quality Score: 0-100 weighted score across all validations
See docs/DATA-VALIDATION-GUIDE.md for comprehensive documentation.
All model training is tracked with MLflow for experiment management, model versioning, and reproducibility. Supports both local tracking and remote DagsHub integration.
Models Available:
- Random Forest - Baseline ensemble model with SMOTE balancing
- XGBoost - Gradient boosting with Optuna hyperparameter optimization
- LightGBM - Fast gradient boosting optimized for large datasets
# Quick training (10k samples, ~30 seconds each)
pnpm train:rf:quick # Random Forest baseline
pnpm train:xgboost:quick # XGBoost (5 Optuna trials)
pnpm train:lightgbm:quick # LightGBM
pnpm train:all:quick # Train all 3 models
# Full training (50k samples, production config)
pnpm train:rf # Random Forest with hyperparameter tuning
pnpm train:xgboost # XGBoost (20 Optuna trials)
pnpm train:lightgbm # LightGBM
pnpm train:all # Train all 3 modelsView Experiments:
# Launch MLflow UI
pnpm mlflow:ui
# Open http://localhost:5000
# Compare experiments in Jupyter notebook
pnpm mlflow:compare
# Opens backend/notebooks/02_model_evaluation.ipynbWhat's Tracked:
- β Parameters: Model hyperparameters, training config, dataset sizes, fraud rates
- β Metrics: Accuracy, Precision, Recall, F1-Score, ROC-AUC
- β Artifacts: Trained models, feature importance, metadata, preprocessors
- β Tags: Algorithm type, stage (baseline/development/production), hardware, optimization method
Model Registry:
xgboost-fraud-detector- XGBoost models with versioninglightgbm-fraud-detector- LightGBM models with versioningrandom-forest-fraud-detector- Random Forest models with versioning
What is DagsHub?
DagsHub is a platform for data science collaboration, providing:
- Remote MLflow tracking server (free tier available)
- Git-based data versioning (DVC integration)
- Shareable experiment URLs for team collaboration
- Perfect for thesis defense presentations!
Setup:
- Create account at dagshub.com
- Get token from https://dagshub.com/user/settings/tokens
- Update
backend/.env.local:# Comment out local tracking # MLFLOW_TRACKING_URI=./mlruns # Enable DagsHub MLFLOW_TRACKING_URI=https://dagshub.com/bibekgupta3333/finsight-ai.mlflow MLFLOW_TRACKING_USERNAME=bibekgupta3333 MLFLOW_TRACKING_PASSWORD=<YOUR_DAGSHUB_TOKEN>
- Train models - experiments auto-sync to DagsHub
- View at https://dagshub.com/bibekgupta3333/finsight-ai/experiments
Benefits for Thesis:
- π Share experiment results with committee via URL
- π Beautiful visualization of model comparison
- π Full reproducibility trail
- π Automatic experiment documentation
Run with MLflow CLI:
cd backend
# Run specific model
mlflow run . -e xgboost -P max_samples=50000 -P n_trials=20
mlflow run . -e lightgbm -P max_samples=50000
mlflow run . -e baseline -P max_samples=50000
# Run via main entry point (model selector)
mlflow run . -e main -P model_type=xgboost -P max_samples=50000Direct Python Execution:
cd backend
# With custom run name for organization
python scripts/train_xgboost_model.py --max-samples 50000 --run-name "xgb_v2_optimized"
python scripts/train_lightgbm_model.py --max-samples 50000 --run-name "lgbm_baseline"
python scripts/train_baseline_models.py --max-samples 50000 --no-tune --run-name "rf_quick_test"Interactive Notebook:
pnpm mlflow:compare
# Opens 02_model_evaluation.ipynb with:
# - Automated experiment loading from MLflow
# - Sortable comparison table with color-coded metrics
# - 4-panel visualization (F1, Precision, Recall, ROC-AUC)
# - Best model identification with loading instructionsMLflow UI:
- Start UI:
pnpm mlflow:ui - Navigate to "Experiments" tab
- Select multiple runs
- Click "Compare" button
- View side-by-side metrics, params, and artifacts
Filtering by Tags:
algorithm- random_forest, xgboost, lightgbmstage- baseline, development, productionhardware- M4_Pro (or your machine)optimization- optuna (for hyperparameter tuning)
| Model | Samples | Training Time | F1-Score | Precision | Recall |
|---|---|---|---|---|---|
| Random Forest (quick) | 10,000 | ~25s | 0.85 | 0.82 | 0.88 |
| XGBoost (quick) | 10,000 | ~40s | 0.87 | 0.84 | 0.90 |
| LightGBM (quick) | 10,000 | ~18s | 0.86 | 0.83 | 0.89 |
| XGBoost (full) | 50,000 | ~4m | 0.91 | 0.89 | 0.93 |
Memory Optimization:
- Default max samples: 50,000 (configurable)
- Memory limit: 16GB (adjustable for M4 Pro)
- SMOTE balancing applied for class imbalance
- Stratified sampling ensures fraud representation
Documentation:
- π Complete guide: docs/MLOPS-PHASE-2-SUMMARY.md
- π WBS tracking: docs/planning/MLOPS-WBS.md
- π§ Troubleshooting: See Phase 2 summary for common issues
- Node.js 18+ and pnpm
- Python 3.11+
- Docker Desktop
- Ollama (for local LLM)
-
Clone the repository
git clone https://github.com/yourusername/finsight-ai.git cd finsight-ai -
Install dependencies
# Install root dependencies pnpm install # Install backend dependencies cd backend python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate pip install -r requirements.txt cd .. # Install frontend dependencies cd frontend pnpm install cd ..
-
Setup environment variables
# Backend cp backend/.env.example backend/.env # Edit backend/.env with your configuration # Frontend cp frontend/.env.example frontend/.env.local # Edit frontend/.env.local with your configuration
-
Install and start Ollama
# macOS brew install ollama ollama serve # In another terminal, pull the model ollama pull llama2:7b
-
Start development servers
# From root directory - starts both frontend and backend pnpm dev # Or manually: # Terminal 1 - Backend cd backend && source venv/bin/activate && uvicorn app.main:app --reload # Terminal 2 - Frontend cd frontend && pnpm dev
-
Prepare data pipeline (one-time setup)
# Download PaySim dataset from Kaggle and place in data/raw/ # https://www.kaggle.com/datasets/ealaxi/paysim1 # Start ChromaDB docker-compose up -d chromadb # Run complete data pipeline (8 steps) cd backend python scripts/prepare_data_pipeline.py # Or run in quick mode for testing python scripts/prepare_data_pipeline.py --quick
-
DVC Data Versioning (optional - for reproducibility)
# Install DVC pip install 'dvc[s3]' dagshub # Check DVC status dvc status # Reproduce entire data pipeline from raw data dvc repro # Visualize pipeline DAG dvc dag # Pull data from remote storage (after initial setup) dvc pull
Common DVC Commands:
# Pipeline Management dvc status # Check what has changed dvc repro # Reproduce pipeline dvc repro <stage> # Run specific stage dvc dag # Visualize dependencies # Data Management dvc pull # Download data from remote dvc push # Upload data to remote dvc checkout # Restore specific version # Experimentation dvc params diff # Compare parameters dvc metrics show # Show metrics dvc plots show # Generate plots # Remote Storage dvc remote list # List configured remotes dvc remote add <name> <url> # Add remote storage
Pipeline Stages: clean β split β balance β annotate β quality_check
See: NEXT-STEPS-DVC.md for detailed DVC setup -
Train models and track experiments (MLflow)
# Quick training to test setup (10k samples, ~1 minute total) pnpm train:all:quick # View experiments in MLflow UI pnpm mlflow:ui # Open http://localhost:5000 # Or compare in Jupyter notebook pnpm mlflow:compare # Full training with all samples (50k, ~5-10 minutes) pnpm train:all
What happens:
- Trains Random Forest, XGBoost, and LightGBM
- Logs all metrics to MLflow (./backend/mlruns)
- Registers models in model registry
- Generates comparison visualizations
-
Access the application
- Frontend: http://localhost:3000
- Backend API: http://localhost:8000
- API Docs: http://localhost:8000/docs
- MLflow UI: http://localhost:5000 (after running
pnpm mlflow:ui) - ChromaDB: http://localhost:8001
# Start all services with Docker Compose
docker-compose up -d
# Pull Ollama model
docker exec -it finsight-ollama ollama pull llama2:7b
# View logs
docker-compose logs -f
# Stop services
docker-compose downComprehensive documentation is available in the docs/ folder:
- Work Breakdown Structure - Project plan and status tracking
- System Design - Architecture and component design
- Database Design - Data models and schema
- Deployment Guide - Step-by-step deployment instructions
- Figma Design Prompt - UI/UX design specifications
- FastAPI - High-performance async API framework
- LangGraph - Agent orchestration
- Ollama - Local LLM inference
- ChromaDB - Vector database for embeddings
- EasyOCR - Text extraction from images
- pdfplumber - PDF parsing
- Next.js 14 - React framework with App Router
- TypeScript - Type-safe JavaScript
- Tailwind CSS - Utility-first styling
- shadcn/ui - Beautiful UI components
- Zustand - State management
- Recharts - Data visualization
- Docker - Containerization
- Kubernetes - Orchestration
- Terraform - Infrastructure as Code
- Helm - Kubernetes package manager
- AWS - Cloud provider
finsight-ai/
βββ frontend/ # Next.js frontend application
β βββ app/ # Next.js app directory (routes)
β βββ components/ # React components
β βββ lib/ # Utilities and API client
β βββ store/ # Zustand stores
βββ backend/ # FastAPI backend application
β βββ app/
β β βββ api/ # API routes
β β βββ agents/ # LangGraph agents
β β βββ services/ # Business logic
β β βββ models/ # Pydantic models
β βββ tests/ # Backend tests
βββ docs/ # Documentation
β βββ planning/ # Project planning
β βββ architecture/ # System design
β βββ deployment/ # Deployment guides
β βββ design/ # UI/UX design
βββ kubernetes/ # K8s manifests
βββ terraform/ # Infrastructure as Code
βββ docker/ # Docker configurations
βββ package.json # Root package.json (monorepo)
βββ turbo.json # Turborepo configuration
βββ docker-compose.yml # Local development setup
# Backend tests
cd backend
pytest
# Frontend tests
cd frontend
pnpm test
# All tests via Turbo
pnpm test# Create namespace
kubectl create namespace finsight-ai
# Deploy with Helm
helm install finsight ./helm/finsight-ai-chart \
--namespace finsight-ai \
--create-namespacecd terraform
terraform init
terraform plan
terraform applySee Deployment Guide for detailed instructions.
Contributions are welcome! Please read our contributing guidelines first.
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- Built with LangChain and LangGraph
- Powered by Ollama for local LLM inference
- UI components from shadcn/ui
- Vector embeddings by Sentence Transformers
- π§ Email: [email protected]
- π¬ Discord: Join our community
- π Issues: GitHub Issues
- Voice input processing
- Mobile app (React Native)
- Multi-language support
- Budget planning features
- Investment insights
- Real-time alerts
- Team/family accounts
Made with β€οΈ by the FinSight AI Team