LoanLinkAI is a sophisticated agentic AI system that automates personal loan processing through a conversational interface. The system uses a Master Agent orchestrating multiple Worker Agents to guide users seamlessly through the loan application journeyβfrom initial sales conversation to sanction letter generation.
- π€ Master Agent with State Machine orchestration
- π¬ Conversational AI using OpenAI GPT models
- π Mock OCR for document processing
- π¦ Credit Assessment with mock credit bureau
- π PDF Sanction Letter generation using ReportLab
- πΎ In-Memory State Management for simplicity
- π¨ Professional UI with Tailwind CSS
- β‘ Real-time Status Tracking with live agent status panel
The system implements a finite state machine with the following states:
Sales β Verification_Pending β Underwriting β Approved β Completed
- Sales: Initial conversation, capture loan requirements
- Verification_Pending: Wait for document upload and verification
- Underwriting: Fetch credit score, validate eligibility
- Approved: Present approval and offer sanction letter
- Completed: Transaction complete
Backend:
- Python 3.13
- FastAPI (REST API)
- Uvicorn (Server)
- OpenAI API (GPT-3.5-turbo / GPT-4o)
- ReportLab (PDF Generation)
- Pydantic (Data validation)
- Python-Multipart (File uploads)
Frontend:
- React 18 (UI Framework)
- Vite (Build tool)
- Tailwind CSS (Styling)
- Axios (HTTP Client)
- Lucide React (Icons)
loanlinkai/
βββ backend/
β βββ app/
β β βββ __init__.py # Package initializer
β β βββ main.py # FastAPI application
β β βββ agents.py # Master Agent logic
β β βββ models.py # Pydantic models
β β βββ utils.py # Utility functions
β βββ static/ # Generated PDFs folder
β βββ .env # Environment configuration
β βββ requirements.txt # Python dependencies
β βββ README.md # Backend documentation
βββ frontend/
β βββ src/
β β βββ components/
β β β βββ ChatBox.jsx # Chat interface
β β β βββ StatusPanel.jsx # Status sidebar
β β βββ assets/ # Static assets
β β βββ App.jsx # Main layout
β β βββ App.css # Component styles
β β βββ index.css # Global styles
β β βββ main.jsx # React entry point
β βββ public/ # Public static files
β βββ node_modules/ # Dependencies (npm)
β βββ eslint.config.js # ESLint configuration
β βββ tailwind.config.js # Tailwind configuration
β βββ vite.config.js # Vite build configuration
β βββ package.json # npm dependencies
β βββ package-lock.json # npm lock file
β βββ index.html # HTML entry point
β βββ README.md # Frontend documentation
βββ .git/ # Git repository
βββ .gitignore # Git ignore file
βββ LICENSE # MIT License
βββ README.md # Project documentation
βββ LICENSE βββ README.md # This file
---
## π Quick Start
### Prerequisites
- Python 3.13 or higher
- Node.js 18+ and npm
- OpenAI API key
### Backend Setup
1. **Navigate to backend directory:**
```bash
cd backend
-
Create virtual environment:
python -m venv venv # Windows venv\Scripts\activate # macOS/Linux source venv/bin/activate
-
Install dependencies:
pip install -r requirements.txt
-
Configure environment:
# Edit .env and add your OpenAI API key OPENAI_API_KEY=sk-your-key-here -
Run server:
python -m uvicorn app.main:app --reload --host 0.0.0.0 --port 8000
Backend will be available at:
http://localhost:8000
-
Navigate to frontend directory:
cd frontend -
Install dependencies:
npm install
-
Create environment file:
echo "VITE_API_URL=http://localhost:8000" > .env.local
-
Run development server:
npm run dev
Frontend will be available at:
http://localhost:5173
- Open browser to
http://localhost:5173 - Start chatting with the AI assistant!
- POST
/chat- Send message and get bot response{ "message": "I need a personal loan", "user_id": "user123", "session_id": "optional_session_id" }
- POST
/upload- Upload and process documents- Accepts: PDF, JPG, PNG, DOC, DOCX
- Performs mock OCR extraction
- Updates user profile
- GET
/state- Get current session state - GET
/session/{session_id}- Get session details - GET
/sessions- List all active sessions (monitoring)
- POST
/sanction-letter- Generate PDF sanction letter - GET
/static/{filename}- Download PDF
- GET
/health- Server health check - GET
/- API information
class MasterAgent:
def process_message(user_message, session):
current_state = session.state
if state == SALES:
# Extract loan amount, collect requirements
# Transition to VERIFICATION_PENDING if amount mentioned
elif state == VERIFICATION_PENDING:
# Check if document uploaded
# Run mock OCR if document present
# Transition to UNDERWRITING
elif state == UNDERWRITING:
# Fetch mock credit score
# Validate eligibility (score > 700)
# Transition to APPROVED or COMPLETED
elif state == APPROVED:
# Offer sanction letter generation
# Generate PDF if requested
# Transition to COMPLETED
return agent_response-
OCR Agent (
mock_ocr_scan)- Extracts: Name, PAN, Email, Phone, Employment Type
- Returns: Structured user data
-
Credit Bureau Agent (
fetch_mock_credit_score)- Returns: Random credit score (600-850)
- In production: Call real credit bureau API
-
PDF Generator Agent (
generate_sanction_pdf)- Creates professional sanction letter PDF
- Includes: Applicant details, loan terms, conditions
- Saves to
static/folder
- Real-time message display
- User/Bot message distinction
- File upload capability
- Auto-scroll to latest message
- Loading states
- Application state visualization
- Progress timeline
- User profile information
- Credit score display
- Sanction letter download button
- Live status updates
- Implement proper authentication (JWT/OAuth)
- Use environment variables for sensitive data
- Add rate limiting to prevent abuse
- Implement input validation and sanitization
- Use HTTPS for all communications
- Secure CORS policy
- Add request logging and monitoring
- Implement data encryption
- Use persistent database instead of in-memory
- Add API key management
User: "Hello, I'm interested in a personal loan"
Bot: "Welcome to LoanLinkAI! I'm your personal loan assistant.
What loan amount are you looking for?"
User: "I need 5 lakhs"
Bot: "Great! Let's verify your details.
Please upload your identity proof (Aadhar/PAN) and recent salary slip."
- Frontend sends file to
/uploadendpoint - OCR extracts information
- User profile updated
- Transition to Underwriting
Bot: "Your documents have been verified.
Credit score: 750. Processing your application..."
Bot: "Congratulations! Your loan application is approved.
Would you like to generate your sanction letter?"
User: "Yes, please"
Bot: "Your sanction letter has been generated!
Download: /static/sanction_letter_xxx.pdf"
Backend (.env):
OPENAI_API_KEY=sk-your-key-here
BACKEND_HOST=0.0.0.0
BACKEND_PORT=8000
DEBUG=True
FRONTEND_URL=http://localhost:5173
LOG_LEVEL=INFOFrontend (.env.local):
VITE_API_URL=http://localhost:8000The system uses mock data for demonstration:
- Credit Scores: Random 600-850
- User Names: Predefined list of Indian names
- PAN Format: ABCDE1234F pattern
- Employment Types: Salaried, Self-Employed, Businessperson
- Start backend:
python -m uvicorn app.main:app --reload - Start frontend:
npm run dev - Open
http://localhost:5173 - Test conversation flow
- Upload sample documents
- Verify state transitions
# Send message
curl -X POST http://localhost:8000/chat \
-H "Content-Type: application/json" \
-d '{"message": "I need a loan", "user_id": "test"}'
# Get state
curl http://localhost:8000/state?user_id=test
# Health check
curl http://localhost:8000/health- Chrome/Edge (Latest)
- Firefox (Latest)
- Safari (Latest)
- Mobile browsers (Responsive design)
Port already in use:
# Change port in main.py or use
uvicorn app.main:app --port 8001Import errors:
# Ensure virtual environment is activated
pip install -r requirements.txtOpenAI API errors:
- Check API key in .env
- Verify internet connection
- Check OpenAI account status
Dependencies not installing:
rm -rf node_modules package-lock.json
npm installPort 5173 in use:
npm run dev -- --port 5174CORS errors:
- Ensure backend CORS is configured
- Check FRONTEND_URL in backend .env
FROM python:3.10-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY app app
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "8000"]npm run build
# Upload dist/ folder- Persistent database (PostgreSQL/MongoDB)
- User authentication system
- Multi-language support
- Advanced NLP for better intent detection
- Real credit bureau integration
- Email/SMS notifications
- Video integration for VideoBot
- Dashboard for loan officers
- Advanced analytics and reporting
- Mobile app (React Native)
This project is licensed under the MIT License - see LICENSE file for details.
Contributions are welcome! Please follow these steps:
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
For issues, questions, or suggestions:
- Create an Issue on GitHub
Built with β€οΈ by the LoanLinkAI Team
Technologies: Python β’ FastAPI β’ React β’ Tailwind β’ OpenAI