Skip to content

Ankitkr-ak007/customer-complaint-agent_new

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

15 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ€– Quickfix – AI Complaint Resolver

License Python React FastAPI

Quickfix is an enterprise-grade agentic AI platform that intelligently handles customer complaints through multi-step reasoning, persistent memory, and conditional decision-making. Built with Google Gemini AI, FastAPI, and React.js, it automates complaint classification, prioritization, response generation, and actionable recommendations.


πŸ“‹ Table of Contents


✨ Key Features

🧠 Agentic AI Capabilities

ComplaintAI operates as an autonomous AI agent, not just a simple chatbot:

  • Intelligent Classification – Automatically categorizes complaints into relevant departments
  • Dynamic Prioritization – Assigns urgency levels (Low/Medium/High) based on context
  • Sentiment Analysis – Analyzes customer emotions and tone
  • Satisfaction Prediction – Predicts customer satisfaction outcomes
  • Professional Response Generation – Drafts empathetic, context-aware response templates
  • Solution Suggestions – Recommends specific solutions based on complaint type
  • Smart Action Recommendations – Suggests next steps for resolution
  • Complaint Matching – Identifies similar past complaints for faster resolution
  • Adaptive Re-evaluation – Reassesses urgency after initial response drafting
  • Email Notifications – Automated confirmation emails to users and alert emails to admins
  • Persistent Memory – Redis-based memory for high-priority complaint tracking
  • Database Integration – SQLite database for complaint history and analytics
  • Conditional Workflows – Executes different flows based on complaint severity

πŸ’¬ Integrated AI Assistant

  • Side-Panel Chatbot – Always accessible for real-time help
  • Contextual Guidance – Answers questions about complaint workflow and AI decisions
  • Gemini-Powered – Leverages Google's advanced language model
  • Graceful Fallbacks – Rule-based logic ensures reliability

πŸ–₯️ Modern Frontend

  • Responsive Design – Works seamlessly across devices
  • Intuitive Interface – Clean, user-friendly complaint submission flow
  • Real-Time Feedback – Instant AI analysis results
  • Dashboard View – Admin dashboard for complaint management
  • Complaint List – View and track all submitted complaints
  • Component Architecture – Modular React components for maintainability
  • Professional Styling – Production-ready CSS modules for each component

βš™οΈ Robust Backend

  • Modular Agent System – 11 specialized AI agents for comprehensive complaint handling
  • RESTful API – Clean, documented endpoints
  • Database Integration – SQLite database with SQLAlchemy ORM
  • Redis Memory Store – Fast, persistent memory for agent state
  • Error Handling – Comprehensive exception management
  • CORS Support – Configured for frontend integration
  • Secure Configuration – Environment-based secrets management
  • Startup Scripts – Easy initialization and database setup
  • Scalable Architecture – Ready for production deployment

πŸ—οΈ System Architecture

customer-complaint-agent/
β”‚
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ agents/
β”‚   β”‚   β”‚   β”œβ”€β”€ action_recommender.py    # Action suggestion engine
β”‚   β”‚   β”‚   β”œβ”€β”€ chat_agent.py            # Chatbot conversation handler
β”‚   β”‚   β”‚   β”œβ”€β”€ classifier.py            # Complaint categorization
β”‚   β”‚   β”‚   β”œβ”€β”€ complaint_matcher.py     # Complaint matching logic
β”‚   β”‚   β”‚   β”œβ”€β”€ gemini_client.py         # Gemini API abstraction
β”‚   β”‚   β”‚   β”œβ”€β”€ orchestrator.py          # Main agent coordinator
β”‚   β”‚   β”‚   β”œβ”€β”€ priority.py              # Priority assignment logic
β”‚   β”‚   β”‚   β”œβ”€β”€ reevaluator.py           # Urgency reassessment
β”‚   β”‚   β”‚   β”œβ”€β”€ responder.py             # Response template generation
β”‚   β”‚   β”‚   β”œβ”€β”€ satisfaction_predictor.py # Customer satisfaction prediction
β”‚   β”‚   β”‚   β”œβ”€β”€ sentiment_analyzer.py    # Sentiment analysis engine
β”‚   β”‚   β”‚   └── solution_suggester.py    # Solution recommendation system
β”‚   β”‚   β”œβ”€β”€ api/
β”‚   β”‚   β”‚   β”œβ”€β”€ chat.py                  # Chatbot API endpoints
β”‚   β”‚   β”‚   └── routes.py                # Complaint submission endpoints
β”‚   β”‚   β”œβ”€β”€ db/
β”‚   β”‚   β”‚   β”œβ”€β”€ database.py              # Database connection & setup
β”‚   β”‚   β”‚   └── models.py                # SQLAlchemy models
β”‚   β”‚   β”œβ”€β”€ memory/
β”‚   β”‚   β”‚   └── redis_store.py           # Redis-based memory management
β”‚   β”‚   β”œβ”€β”€ models/
β”‚   β”‚   β”‚   └── complaint.py             # Complaint data model
β”‚   β”‚   └── schemas/
β”‚   β”‚       β”œβ”€β”€ init_.py                 # Schema initialization
β”‚   β”‚       └── complaint.py             # Pydantic schemas
β”‚   β”œβ”€β”€ .env
    β”œβ”€β”€ email_services.py                   # Environment variables
β”‚   β”œβ”€β”€ check_db.py                      # Database verification script
β”‚   β”œβ”€β”€ complaints.db                    # SQLite database
β”‚   β”œβ”€β”€ init_db.py                       # Database initialization
β”‚   β”œβ”€β”€ requirements.txt                 # Python dependencies
β”‚   β”œβ”€β”€ requirements.lock.txt            # Locked dependencies
β”‚   └── start_backend.py                 # Backend startup script
β”‚
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintCard.jsx        # AI result display
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintForm.jsx        # Complaint submission form
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintList.jsx        # List of complaints
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.jsx            # Admin dashboard
β”‚   β”‚   β”‚   β”œβ”€β”€ Landing.jsx              # Landing page component
β”‚   β”‚   β”‚   └── SideChatBot.jsx          # Integrated chat assistant
β”‚   β”‚   β”œβ”€β”€ styles/
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintCard.css        # Card styling
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintForm.css        # Form styling
β”‚   β”‚   β”‚   β”œβ”€β”€ ComplaintList.css        # List styling
β”‚   β”‚   β”‚   β”œβ”€β”€ Dashboard.css            # Dashboard styling
β”‚   β”‚   β”‚   β”œβ”€β”€ Landing.css              # Landing page styling
β”‚   β”‚   β”‚   └── SideChatBot.css          # Chatbot styling
β”‚   β”‚   β”œβ”€β”€ api.js                       # API client configuration
β”‚   β”‚   β”œβ”€β”€ App.css                      # Global app styles
β”‚   β”‚   β”œβ”€β”€ App.jsx                      # Main application component
β”‚   β”‚   β”œβ”€β”€ index.css                    # Base CSS styles
β”‚   β”‚   └── main.jsx                     # React entry point
β”‚   β”œβ”€β”€ .gitignore                       # Frontend git ignore
β”‚   β”œβ”€β”€ eslint.config.js                 # ESLint configuration
β”‚   β”œβ”€β”€ index.html                       # HTML template
β”‚   β”œβ”€β”€ package.json                     # NPM dependencies
β”‚   β”œβ”€β”€ package-lock.json                # NPM lock file
β”‚   β”œβ”€β”€ vite.config.js                   # Vite configuration
β”‚   └── start_backend.py                 # Backend startup helper
β”‚
β”œβ”€β”€ .gitignore                           # Git ignore rules
└── README.md                            # Project documentation

πŸ”‘ Technology Stack

Backend

Technology Purpose
Python 3.10+ Core programming language
FastAPI High-performance web framework
Google Gemini API Advanced language model
Pydantic Data validation and serialization
SQLAlchemy SQL toolkit and ORM
SQLite Lightweight database
Redis In-memory data store for agent memory
SMTP (Gmail) Email notification service
Uvicorn ASGI server

Frontend

Technology Purpose
React.js UI component framework
Vite Fast build tool and dev server
Axios HTTP client for API calls
CSS Modules Scoped component styling

AI & Agent Framework

  • Google Gemini – Natural language understanding and generation
  • Multi-Agent Pipeline – 11 specialized agents working in coordination:
    • Orchestrator – Coordinates all agents
    • Classifier – Categorizes complaints
    • Priority Agent – Assigns urgency levels
    • Sentiment Analyzer – Analyzes emotional tone
    • Responder – Generates professional responses
    • Action Recommender – Suggests next steps
    • Solution Suggester – Recommends specific solutions
    • Re-evaluator – Reassesses complaint urgency
    • Satisfaction Predictor – Predicts customer satisfaction
    • Complaint Matcher – Finds similar past complaints
    • Chat Agent – Handles conversational queries
  • Redis-Based Memory – Persistent state management across sessions
  • SQLite Database – Historical data and analytics
  • Rule-Based Fallbacks – Ensures reliability when AI is unavailable

πŸš€ Getting Started

Prerequisites

  • Node.js 16+ and npm
  • Python 3.10+
  • Redis (optional, for memory store)
  • Google Gemini API Key (Get one here)

Installation

1. Clone the Repository

git clone https://github.com/RiteshKumar2e/customer-complaint-agent.git
cd customer-complaint-agent

2. Backend Setup

cd backend

# Create virtual environment
python -m venv venv

# Activate virtual environment
# Windows:
venv\Scripts\activate
# macOS/Linux:
source venv/bin/activate

# Install dependencies
pip install -r requirements.txt

# Initialize the database
python init_db.py

# Create .env file
echo "GEMINI_API_KEY=your_google_gemini_api_key" > .env

3. Frontend Setup

cd ../frontend

# Install dependencies
npm install

Running the Application

Start Backend Server

cd backend

# Using the startup script
python start_backend.py

# Or manually with uvicorn
uvicorn app.main:app --reload

Backend will be available at: http://localhost:8000

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

Start Frontend Development Server

cd frontend
npm run dev

Frontend will be available at: http://localhost:5174


πŸ“‘ API Documentation

Submit Complaint

Endpoint: POST /complaint

Request Body:

{
  "complaint": "My refund has been delayed for over 2 weeks"
}

Response:

{
  "category": "Billing",
  "priority": "High",
  "sentiment": "Negative",
  "satisfaction_score": 0.35,
  "response": "We sincerely apologize for the delay in processing your refund. We understand how frustrating this must be. Our finance team has been notified and will prioritize your case immediately.",
  "action": "Escalate to finance team within 24 hours",
  "solution": "Initiate immediate refund processing and provide tracking number"
}

Agent Chat

Endpoint: POST /agent/chat

Query Parameters:

  • message (string, required) – User's question

Example:

POST /agent/chat?message=What%20does%20this%20website%20do

Response:

{
  "response": "ComplaintAI is an intelligent customer complaint management system that uses AI to automatically categorize, prioritize, and draft responses to customer complaints. It helps businesses handle customer issues more efficiently."
}

πŸ”„ Agent Workflow

ComplaintAI uses a multi-stage agent pipeline for intelligent complaint processing:

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  Complaint Received β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Classify Category   β”‚  ← Classifier Agent
β”‚ (Billing, Support,  β”‚
β”‚  Technical, etc.)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Analyze Sentiment   β”‚  ← Sentiment Analyzer
β”‚ (Positive, Negative,β”‚
β”‚  Neutral)           β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Assign Priority     β”‚  ← Priority Agent
β”‚ (Low/Medium/High)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Match Similar       β”‚  ← Complaint Matcher
β”‚ Complaints          β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Draft Response      β”‚  ← Responder Agent
β”‚ (Professional,      β”‚
β”‚  Empathetic)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Suggest Solutions   β”‚  ← Solution Suggester
β”‚ (Specific fixes,    β”‚
β”‚  workarounds)       β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Recommend Actions   β”‚  ← Action Recommender
β”‚ (Escalate, Refund,  β”‚
β”‚  Investigation)     β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Predict Satisfactionβ”‚  ← Satisfaction Predictor
β”‚ (Expected outcome)  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Re-evaluate Urgency β”‚  ← Re-evaluator Agent
β”‚ (Adjust priority if β”‚
β”‚  needed)            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Store in Database   β”‚  ← SQLite Database
β”‚ & Update Memory     β”‚     Redis Store
β”‚ (Track high-priorityβ”‚
β”‚  complaints)        β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
           β”‚
           β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚ Send Email          β”‚  ← Email Service
β”‚ Notifications       β”‚     (User + Admin)
β”‚ (Confirmation +     β”‚
β”‚  Alert)             β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

βš™οΈ Configuration

Environment Variables

Create a .env file in the backend/ directory:

# Google Gemini API Configuration
GEMINI_API_KEY=your_google_gemini_api_key

# Email Configuration (Gmail)
SENDER_EMAIL=[email protected]
SENDER_PASSWORD=your-gmail-app-password

# Database Configuration
DATABASE_URL=sqlite:///./complaints.db

# Redis Configuration (optional)
REDIS_HOST=localhost
REDIS_PORT=6379
REDIS_DB=0

# Server Configuration (optional)
HOST=0.0.0.0
PORT=8000

# CORS Settings (optional)
ALLOWED_ORIGINS=http://localhost:5174,http://localhost:3000

Email Setup (Gmail)

ComplaintAI sends automated email notifications to users and admins. Follow these steps to configure:

1. Enable Gmail 2-Factor Authentication

  1. Go to Google Account Security
  2. Click "2-Step Verification" and enable it
  3. Complete the verification process

2. Generate Gmail App Password

  1. Visit App Passwords
  2. Select App: Mail and Device: Windows Computer
  3. Copy the generated 16-character password (format: xxxx xxxx xxxx xxxx)

3. Update .env File

SENDER_EMAIL=[email protected]
SENDER_PASSWORD=xxxx xxxx xxxx xxxx

Important: Use the App Password, NOT your regular Gmail password!

Email Features

  • User Confirmation Email - Sent immediately after complaint submission with AI analysis results
  • Admin Alert Email - Notifies admin team about new high-priority complaints
  • Professional Templates - HTML-formatted emails with branding and detailed information

Troubleshooting Emails

"Username and Password not accepted"

  • Verify Gmail address is correct
  • Generate a NEW app password from Google Account
  • Use App Password, not regular password
  • Restart backend server

"2-Step Verification not enabled"

  • Enable 2FA in Google Account Security settings
  • Then generate app password

SMTP Connection Failed

  • Check internet connection
  • Verify firewall settings
  • Try using VPN if corporate network blocks SMTP

Customization

Modify agent behavior in backend/app/agents/:

  • classifier.py – Add new complaint categories
  • priority.py – Adjust priority thresholds
  • sentiment_analyzer.py – Customize sentiment detection
  • responder.py – Customize response templates
  • solution_suggester.py – Add domain-specific solutions
  • action_recommender.py – Define action rules
  • satisfaction_predictor.py – Adjust satisfaction metrics

Database Management

# Initialize/reset database
python init_db.py

# Check database contents
python check_db.py

🀝 Contributing

Contributions are welcome! Please follow these steps:

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

πŸ“œ License

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

MIT License

Copyright (c) 2024 Ritesh Kumar

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.


πŸ“ž Contact

Ritesh Kumar


⭐ Show Your Support

If you find this project helpful, please consider giving it a star on GitHub! Your support helps others discover this tool.

GitHub stars


πŸ™ Acknowledgments

  • Google Gemini team for the powerful AI API
  • FastAPI community for excellent documentation
  • React and Vite teams for modern development tools

Made with ❀️ by Ritesh Kumar

Releases

No releases published

Packages

No packages published

Languages

  • CSS 34.6%
  • Python 33.4%
  • JavaScript 31.8%
  • HTML 0.2%