Skip to content

ishaanparikh14/Multi-Agent-AI-KYC-System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🏦 Multi-Agent AI KYC System

Python 3.10+ LangGraph License: MIT

A sophisticated Multi-Agent AI System for automated Know Your Customer (KYC) verification, built with LangGraph state machines, Google Gemini LLM, and a tiered memory architecture. Designed for insurance and financial services applications.

KYC System Architecture


πŸ“‹ Table of Contents


🎯 Overview

The Multi-Agent AI KYC System automates the customer identity verification process for TATA AIA Life Insurance. It uses a hierarchical multi-agent architecture where:

  • A Main Orchestrator routes user intents to appropriate workflows
  • Specialist Agents handle specific document verifications (Aadhaar, PAN, Passport, DL, Form 60)
  • LangGraph State Machines manage complex, interruptible verification workflows
  • Tiered Memory System maintains conversation context across sessions

The system supports both Web Interface (Flask + WebSocket) and CLI modes.


✨ Features

πŸ€– Multi-Agent Architecture

  • Main Orchestrator: Intent recognition and routing using structured LLM outputs
  • KYC Manager Agent: Delegates tasks to specialist agents
  • Specialist Agents: Aadhaar, PAN, Passport, DL, and Form 60 verification
  • General Query Agent: Handles insurance-related questions
  • PAN Check Agent: Determines if user needs PAN or Form 60

πŸ“„ Document Verification

  • Aadhaar Verification: eKYC via OTP or document upload with OCR
  • PAN Card Verification: NSDL database validation + OCR support
  • Passport Verification: Document extraction and validation
  • Driving License: OCR-based verification
  • Form 60: For users without PAN card

🧠 Advanced Memory System

  • L1 Working Memory: Redis-based short-term conversation buffer
  • L2 Episodic Memory: LLM-generated summaries stored in Redis
  • L3 Semantic Memory: Mem0-powered long-term user preferences

🎨 Modern Web Interface

  • Real-time WebSocket communication
  • Interactive FAQ sidebar
  • Live process status tracking
  • Responsive design for mobile/desktop
  • Typing indicators and smooth animations

πŸ”§ Developer Features

  • LangSmith integration for tracing and debugging
  • Structured outputs with Pydantic models
  • Comprehensive error handling with retry mechanisms
  • Modular, extensible architecture

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                        User Interface                           β”‚
β”‚                  (Web App / CLI / API Client)                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      Main Orchestrator                          β”‚
β”‚  β€’ Intent Recognition (LLM + Pydantic Structured Output)        β”‚
β”‚  β€’ Workflow Routing                                             β”‚
β”‚  β€’ Memory Context Integration                                   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
              β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
              β–Ό               β–Ό               β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  KYC Manager    β”‚ β”‚ General Query   β”‚ β”‚  PAN Check      β”‚
β”‚     Agent       β”‚ β”‚    Agent        β”‚ β”‚    Agent        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Specialist Agents                            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”β”‚
β”‚  β”‚ Aadhaar  β”‚ β”‚   PAN    β”‚ β”‚ Passport β”‚ β”‚    DL    β”‚ β”‚Form 60 β”‚β”‚
β”‚  β”‚  Agent   β”‚ β”‚  Agent   β”‚ β”‚  Agent   β”‚ β”‚  Agent   β”‚ β”‚ Agent  β”‚β”‚
β”‚  β”‚(LangGraphβ”‚ β”‚(LangGraphβ”‚ β”‚(LangGraphβ”‚ β”‚(LangGraphβ”‚ β”‚        β”‚β”‚
β”‚  β”‚  FSM)    β”‚ β”‚  FSM)    β”‚ β”‚  FSM)    β”‚ β”‚  FSM)    β”‚ β”‚        β”‚β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”˜β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                              β”‚
                              β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                      External Services                          β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚ UIDAI DB     β”‚ β”‚ NSDL DB      β”‚ β”‚ Document     β”‚            β”‚
β”‚  β”‚ (Aadhaar)    β”‚ β”‚ (PAN)        β”‚ β”‚ Intelligence β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ› οΈ Tech Stack

Component Technology
LLM Google Gemini 2.5 Flash/Pro
Agent Framework LangGraph (State Machines)
Observability LangSmith
Memory - L1 Redis
Memory - L3 Mem0
Web Framework Flask + Flask-SocketIO
API Framework FastAPI
OCR Azure Document Intelligence
Data Validation Pydantic
Language Python 3.10+

πŸ“ Project Structure

Multi-Agent-AI-KYC-System/
β”‚
β”œβ”€β”€ agent/                      # Agent implementations
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ base_agent.py          # Base class for all agents
β”‚   β”œβ”€β”€ aadhar_agent.py        # Aadhaar verification (LangGraph FSM)
β”‚   β”œβ”€β”€ pan_agent.py           # PAN verification (LangGraph FSM)
β”‚   β”œβ”€β”€ passport_agent.py      # Passport verification
β”‚   β”œβ”€β”€ dl_agent.py            # Driving License verification
β”‚   β”œβ”€β”€ form60_agent.py        # Form 60 processing
β”‚   β”œβ”€β”€ kyc_agent.py           # KYC Manager Agent
β”‚   β”œβ”€β”€ genral_query_agent.py  # General insurance queries
β”‚   └── pan_check_agent.py     # PAN existence checker
β”‚
β”œβ”€β”€ api/                        # External API integrations
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── ocr_api.py             # Azure Document Intelligence
β”‚
β”œβ”€β”€ app/                        # FastAPI application
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ main.py                # FastAPI app definition
β”‚   β”œβ”€β”€ models.py              # API request/response models
β”‚   β”œβ”€β”€ dependencies.py        # Dependency injection
β”‚   └── routers/
β”‚       └── chat.py            # Chat API endpoints
β”‚
β”œβ”€β”€ config/                     # Configuration management
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ config.py              # Pydantic settings
β”‚   └── settings.py            # Environment settings
β”‚
β”œβ”€β”€ data/                       # Mock databases
β”‚   β”œβ”€β”€ database_nsdl.csv      # PAN verification data
β”‚   └── database_uidai.csv     # Aadhaar verification data
β”‚
β”œβ”€β”€ memory/                     # Memory management
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── memory.py              # Tiered memory system
β”‚
β”œβ”€β”€ models/                     # Pydantic models
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── intent.py              # Intent classification models
β”‚
β”œβ”€β”€ orchestrator/               # Main orchestration logic
β”‚   β”œβ”€β”€ __init__.py
β”‚   └── router.py              # Main Orchestrator
β”‚
β”œβ”€β”€ prompts/                    # LLM prompt templates
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ aadhar_prompts.py
β”‚   β”œβ”€β”€ pan_prompts.py
β”‚   β”œβ”€β”€ form60_prompts.py
β”‚   β”œβ”€β”€ greeting_prompts.py
β”‚   β”œβ”€β”€ orchestrate.py
β”‚   β”œβ”€β”€ prompts.py
β”‚   └── prompts_short.py
β”‚
β”œβ”€β”€ static/                     # Web static files
β”‚   β”œβ”€β”€ css/
β”‚   β”‚   └── style.css
β”‚   └── js/
β”‚       β”œβ”€β”€ script.js
β”‚       └── sw.js
β”‚
β”œβ”€β”€ templates/                  # Jinja2 templates
β”‚   └── index.html             # Main web interface
β”‚
β”œβ”€β”€ tools/                      # Verification tools
β”‚   β”œβ”€β”€ __init__.py
β”‚   β”œβ”€β”€ aadhar_tools.py        # Aadhaar validation tools
β”‚   β”œβ”€β”€ pan_tools.py           # PAN validation tools
β”‚   β”œβ”€β”€ ocr_tool.py            # OCR utilities
β”‚   β”œβ”€β”€ ocr_pan_tool.py        # PAN OCR processor
β”‚   └── tools_definition.py    # Tool definitions
β”‚
β”œβ”€β”€ .env                        # Environment variables (create this)
β”œβ”€β”€ app.py                      # Flask web application
β”œβ”€β”€ llm.py                      # LLM client factory
β”œβ”€β”€ main_cli.py                 # CLI interface
β”œβ”€β”€ requirements.txt            # Python dependencies
β”œβ”€β”€ run_api.py                  # FastAPI startup script
β”œβ”€β”€ run_web.py                  # Flask startup script
β”œβ”€β”€ state.py                    # State definitions (TypedDict)
β”œβ”€β”€ client_example.py           # API client example
β”œβ”€β”€ webhook_example.py          # Webhook integration example
└── README.md                   # This file

πŸ“‹ Prerequisites

Before running the application, ensure you have:

  • Python 3.10 or higher
  • pip (Python package manager)
  • Git (for cloning the repository)

Required API Keys/Services:

  • Google Gemini API Key (for LLM)
  • Mem0 API Key (for semantic memory)
  • Redis Cloud instance (for working memory)
  • Azure Document Intelligence (optional, for OCR)
  • LangSmith API Key (optional, for tracing)

πŸš€ Installation

1. Clone the Repository

git clone https://github.com/ishaanparikh14/Multi-Agent-AI-KYC-System.git
cd Multi-Agent-AI-KYC-System

2. Create a Virtual Environment

Windows:

python -m venv .venv
.venv\Scripts\activate

macOS/Linux:

python3 -m venv .venv
source .venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

Or install packages individually:

pip install openai langgraph langsmith mem0ai fastapi uvicorn flask flask-socketio python-multipart pydantic pydantic-settings httpx aiohttp requests aiofiles pandas Pillow redis python-dotenv typing-extensions Jinja2

βš™οΈ Configuration

1. Create Environment File

Create a .env file in the project root:

# LLM Configuration (Google Gemini)
GEMINI_API_KEY=your_gemini_api_key_here
GEMINI_BASE_URL=https://generativelanguage.googleapis.com/v1beta/openai/

# Memory - Mem0 (Long-term semantic memory)
MEM0_API_KEY=your_mem0_api_key_here

# Memory - Redis (Short-term working memory)
REDIS_HOST=your_redis_host
REDIS_DB_NAME=your_redis_db_name
REDIS_PASSWORD=your_redis_password

# OCR - Azure Document Intelligence (Optional)
DOCUMENT_INTELLIGENCE_API_KEY=your_azure_di_key
DOCUMENT_INTELLIGENCE_ENDPOINT=https://your-resource.cognitiveservices.azure.com

# LangSmith - Observability (Optional)
LANGSMITH_TRACING=false
LANGSMITH_ENDPOINT=https://api.smith.langchain.com
LANGSMITH_API_KEY=your_langsmith_api_key
LANGSMITH_PROJECT=your_project_name

# ChromaDB (Optional - for vector storage)
CHROMA_TOKEN=your_chroma_token
CHROMA_TENANT=your_tenant
CHROMA_DATABASE=your_database

# Cohere (Optional - for embeddings)
COHERE_API_KEY=your_cohere_api_key

2. Get API Keys

Service Sign Up URL Purpose
Google Gemini Google AI Studio LLM for conversations
Mem0 Mem0.ai Long-term memory
Redis Cloud Redis Cloud Short-term memory
Azure DI Azure Portal Document OCR
LangSmith LangSmith Tracing & debugging

πŸƒ Running the Application

Option 1: Web Interface (Recommended)

python run_web.py

Then open your browser to: http://localhost:5000

Option 2: Command Line Interface

python main_cli.py

Option 3: FastAPI Server

python run_api.py

Or with uvicorn directly:

uvicorn app.main:app --host 0.0.0.0 --port 8000 --reload

API documentation available at: http://localhost:8000/docs


πŸ“‘ API Reference

Chat Endpoint

POST /api/chat

Send a message to the KYC assistant.

Request Body:

{
    "message": "I want to start KYC verification",
    "session_id": "optional-session-id"
}

Response:

{
    "response": "Welcome! I'm Siddhi from TATA AIA...",
    "session_id": "abc123",
    "active_workflow": "aadhaar",
    "kyc_step": "awaiting_verification_method_selection",
    "completed_workflows": []
}

Session Status

GET /api/session/{session_id}/status

Get current session status and progress.

Response:

{
    "active_workflow": "aadhaar",
    "kyc_step": "awaiting_otp",
    "completed_workflows": ["pan"],
    "aadhar_details": {},
    "pan_details": {}
}

πŸ’‘ Usage Examples

Starting KYC Verification

User: Hi, I want to complete my KYC
Bot: Welcome! I'm Siddhi from TATA AIA Life Insurance. 
     Let's start with Aadhaar verification. Would you prefer:
     1. eKYC (OTP-based verification)
     2. DigiLocker

Aadhaar Verification Flow

User: I'll go with eKYC
Bot: Great! Please enter your 12-digit Aadhaar number.

User: 123456789012
Bot: I've sent an OTP to your registered mobile. Please enter the 6-digit OTP.

User: 123456
Bot: βœ… Aadhaar verified successfully!
     Name: John Doe
     DOB: 01/01/1990
     Is this information correct?

PAN Verification Flow

User: Now I want to verify my PAN
Bot: I see your name from Aadhaar is "John Doe" and DOB is "01/01/1990".
     Please enter your PAN card number.

User: ABCDE1234F
Bot: βœ… PAN verified successfully against NSDL database!

🧠 Memory System

The system implements a 3-tier memory architecture:

L1 - Working Memory (Redis)

  • Stores last 6 conversation turns
  • Fast access for immediate context
  • Automatic sliding window

L2 - Episodic Memory (Redis)

  • LLM-generated summaries of conversations
  • Triggered after threshold of turns
  • Preserves important facts and decisions

L3 - Semantic Memory (Mem0)

  • Long-term user preferences
  • Cross-session memory
  • Agent-specific memories (Aadhaar agent, PAN agent, etc.)

πŸ”§ Troubleshooting

Common Issues

1. Port Already in Use

# Windows
netstat -ano | findstr :5000
taskkill /PID <PID> /F

# Linux/macOS
lsof -i :5000
kill -9 <PID>

2. Redis Connection Failed

  • Verify Redis host, port (default: 10908), and password in .env
  • Check if Redis Cloud firewall allows your IP

3. LLM API Rate Limits

  • The system includes automatic retry with exponential backoff
  • Consider upgrading your Gemini API quota

4. Import Errors

  • Ensure you're running from the project root directory
  • Activate the virtual environment before running

5. OCR Not Working

  • Verify Azure Document Intelligence credentials
  • Check endpoint URL format

Debug Mode

Enable debug logging:

# In config/config.py
debug: bool = True

Enable LangSmith tracing:

LANGSMITH_TRACING=true

🀝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

Code Style

  • Follow PEP 8 guidelines
  • Use type hints
  • Add docstrings to functions and classes

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘€ Author

Ishaan Parikh


πŸ™ Acknowledgments


Made with ❀️ for the future of AI-powered KYC

About

Multi-Agent AI system for KYC verification using LangGraph state machines & Google Gemini. Features Aadhaar/PAN/Passport verification, OCR support, 3-tier memory (Redis + Mem0), Flask web UI, and FastAPI backend.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors