Skip to content

Yourfiyan/customer-support-ai-agent

Repository files navigation

Customer Support AI Agent System

License: MIT Python Gemini FastAPI

A sophisticated multi-agent customer support chatbot built with Google Gemini AI for the Kaggle Agents Intensive Capstone Project.

🎯 Project Overview

This system demonstrates advanced AI agent orchestration using 4 specialized agents working together to provide automated customer support responses:

  1. Classifier Agent - Categorizes customer inquiries
  2. Research Agent - Searches FAQ database for relevant answers
  3. Writer Agent - Crafts professional, helpful responses
  4. Validator Agent - Ensures response quality before sending

🏗️ Architecture

┌─────────────────────────────────────────────────────────────┐
│                  Customer Support Request                   │
│                  (Question + Email)                         │
└────────────────────┬────────────────────────────────────────┘
                     │
                     ▼
┌──────────────────────────────────────────────────────────────┐
│              ROOT ORCHESTRATOR AGENT                         │
│         (Coordinates Multi-Agent Workflow)                   │
└──────────────────────┬───────────────────────────────────────┘
                       │
     ┌─────────────────┼────────────────┬────────────────┐
     │                 │                │                │
     ▼                 ▼                ▼                ▼
┌─────────┐      ┌──────────┐     ┌──────────┐     ┌───────────┐
│ AGENT 1 │      │ AGENT 2  │     │ AGENT 3  │     │ AGENT 4   │
│         │      │          │     │          │     │           │
│Classify │ ──>  │ Research │ ──> │  Write   │ ──> │ Validate  │
│         │      │   FAQs   │     │ Response │     │  Quality  │
└─────────┘      └──────────┘     └──────────┘     └─────┬─────┘
                                                         │
                                          ┌──────────────┴──────────┐
                                          │                         │
                                          ▼                         ▼
                                     ┌──────────┐            ┌────────────┐
                                     │ APPROVED │            │  REVISION  │
                                     │   Send   │            │  NEEDED    │
                                     └──────────┘            └─────┬──────┘
                                                                   │
                                                          (Loop back to Writer)

🚀 Key Features

  • Multi-Agent Orchestration: 4 specialized agents working in sequence
  • Custom Tool Integration: FAQ search and email sending capabilities
  • Quality Validation Loop: Ensures high-quality responses with retry logic
  • REST API: FastAPI-based server for web integration
  • Interactive Demo: Beautiful web UI for testing
  • Session Memory: Context preservation across agent interactions
  • Performance Tracking: Response time and statistics monitoring

📚 Technologies Used

  • LLM: Google Gemini 2.5 Flash (via google-generativeai library)
  • API: FastAPI + Uvicorn
  • Frontend: HTML5 + JavaScript (Vanilla)
  • Language: Python 3.12+

📋 Prerequisites

  • Python 3.12 or higher
  • Google API Key (for Gemini access)
  • pip (Python package manager)

🛠️ Installation

1. Clone the Repository

git clone https://github.com/Yourfiyan/customer-support-ai-agent.git
cd customer-support-ai-agent

2. Set Up Python Environment (Recommended)

# Create virtual environment
python -m venv .venv

# Activate virtual environment
.\.venv\Scripts\Activate.ps1

# If you get execution policy error, run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser

3. Install Dependencies

pip install -r requirements.txt

4. Configure Google API Key

Copy the example file and add your API key:

# Copy template
Copy-Item .env.example .env

# Edit .env and replace 'your_api_key_here' with your actual key

Get your free API key:

  1. Visit: https://aistudio.google.com/apikey
  2. Create a new API key
  3. Paste it into the .env file

🎮 Usage

Option 1: Test Agent System Directly

Run the agent system with test scenarios:

python agent.py

This will:

  • Initialize all 4 agents
  • Process 4 test inquiries
  • Display detailed workflow logs
  • Save responses to response_log.txt

Option 2: Start REST API Server

Launch the API server:

python api_server.py

The API will be available at:

Option 3: Use Web Demo Interface

  1. Start the API server (see Option 2)
  2. Open demo/index.html in your browser
  3. Enter your email and question
  4. Click "Submit Inquiry" to see the AI agents work!

Quick test: Try clicking the preset question buttons for instant testing.

📡 API Endpoints

POST /api/support/inquiry

Submit a customer support inquiry.

Request:

{
  "question": "I forgot my password. How do I reset it?",
  "email": "customer@example.com"
}

Response:

{
  "success": true,
  "category": "account",
  "response": "Dear Customer,\n\nThank you for contacting us...",
  "faq_count": 2,
  "validation_status": "approved",
  "processing_time_ms": 1250
}

GET /api/support/health

Health check endpoint.

Response:

{
  "status": "healthy",
  "version": "1.0.0",
  "timestamp": "2025-11-19T10:30:00",
  "agents_loaded": true
}

GET /api/support/stats

System statistics.

Response:

{
  "total_inquiries": 42,
  "categories": {
    "account": 15,
    "billing": 12,
    "technical": 10,
    "general": 5
  },
  "avg_response_length": 387,
  "uptime_seconds": 3600
}

🧪 Testing Scenarios

Test the system with these example questions:

Category Question Expected Result
Account "I forgot my password" Password reset instructions
Account "How do I change my email?" Email update steps
Billing "Where can I find my invoices?" Billing portal info
Technical "The app is running slowly" Performance troubleshooting
General "What are your business hours?" Support hours info

🎓 Key Concepts Demonstrated

This project showcases key concepts from the Kaggle Agents Intensive course:

  1. Multi-Agent Systems: 4 specialized agents with distinct roles
  2. Agent Orchestration: Orchestrator coordinates workflow
  3. Custom Tools: FAQ search and email logging tools
  4. Validation Loop: Quality checking with retry logic
  5. System Prompts: Precise role definition for each agent
  6. Temperature Control: Low temperature (0.2) for consistency

📁 Project Structure

customer-support-ai-agent/
│
├── agent.py              # Main multi-agent system
├── tools.py              # Custom FAQ search & email tools
├── api_server.py         # FastAPI REST API server
├── faqs.json             # Knowledge base (12 Q&A pairs)
├── requirements.txt      # Python dependencies
├── README.md             # This file
├── .env                  # API key configuration (create this)
│
├── demo/
│   └── index.html        # Web interface demo
│
└── response_log.txt      # Generated: Email response logs

🔍 How It Works

Step-by-Step Workflow

  1. Customer submits question via web UI or API
  2. Classifier Agent analyzes question → determines category
  3. Research Agent searches FAQ database → finds relevant answers
  4. Writer Agent crafts response → combines FAQs with friendly tone
  5. Validator Agent checks quality → approves or requests revision
  6. System sends response → logs to file (mock email)

Example Flow

Input: "I forgot my password"
  ↓
Classifier: category = "account"
  ↓
Researcher: Found 2 relevant FAQs about password reset
  ↓
Writer: Drafted friendly response with step-by-step instructions
  ↓
Validator: ✓ Approved (accurate, complete, professional)
  ↓
Output: Professional response sent to customer

Case Study

Problem

Customer support teams spend the majority of their time answering repetitive questions — password resets, billing inquiries, and feature explanations. Average response time is 24–48 hours, and each ticket costs $15–25 to handle manually. This creates a poor customer experience and wastes human agents' time on tasks that don't require judgment.

Solution

A multi-agent AI system that automates responses to common support inquiries in under 2 seconds. Four specialized agents (Classifier → Researcher → Writer → Validator) work as a pipeline. The Validator agent provides a quality gate — if a response doesn't meet standards, it loops back to the Writer for revision before reaching the customer.

Architecture Decisions

  • Multi-agent over single-prompt: Breaking the task into specialized agents improves accuracy. A single LLM prompt conflates classification, research, and writing — separate agents let each focus on one job.
  • Validation loop: The Validator agent catches hallucinations and incomplete answers before they reach customers. This was the single biggest quality improvement during development.
  • FAQ tool over RAG: For a 12-entry knowledge base, keyword search is faster and more predictable than vector embeddings. The system can scale to RAG when the FAQ grows past ~100 entries.
  • FastAPI for serving: Async-native, automatic OpenAPI docs, and simple enough to deploy to Cloud Run with zero configuration.

Security Considerations

  • API key stored in .env, never committed (.gitignore enforced)
  • No user data is persisted — responses are stateless
  • Rate limiting should be added before production deployment
  • The LLM is instructed to never fabricate policies or make promises the company can't keep

Lessons Learned

  • Temperature matters: Setting LLM temperature to 0.2 dramatically reduced inconsistent responses. Higher temperatures introduced creative but inaccurate support answers.
  • Validation is non-negotiable: Without the Validator agent, ~15% of responses contained hallucinated features or incorrect procedures.
  • Prompt engineering > model size: Well-crafted system prompts on Gemini Flash outperformed larger models with vague prompts for this structured task.
  • The orchestrator pattern scales: Adding a fifth agent (e.g., sentiment analysis) requires zero changes to existing agents — just add it to the orchestrator pipeline.

See docs/architecture.md for a deeper dive into the agent pipeline and data flow.

🚀 Deployment

Local Testing (Already Configured)

python api_server.py

Cloud Deployment (Google Cloud Run)

  1. Create Dockerfile (add to project):
FROM python:3.12-slim

WORKDIR /app

COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

ENV PORT=8080
ENV GOOGLE_API_KEY=${GOOGLE_API_KEY}

CMD uvicorn api_server:app --host 0.0.0.0 --port $PORT
  1. Deploy to Cloud Run:
# Build and deploy
gcloud run deploy customer-support-agent \
  --source . \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated \
  --set-env-vars GOOGLE_API_KEY=your-key-here
  1. Get public URL for Kaggle submission

📊 Performance Metrics

  • Average Response Time: 1-2 seconds
  • FAQ Match Rate: ~85% for common questions
  • Validation Pass Rate: ~95% on first attempt
  • Supported Categories: 4 (account, billing, technical, general)
  • Knowledge Base: 12 Q&A pairs (easily expandable)

🎥 Demo Video Script

For Kaggle Submission (30-60 seconds):

  1. Introduction (5s): "Multi-agent customer support system built with Google Gemini AI"
  2. Architecture (10s): Show 4-agent diagram, explain workflow
  3. Demo (30s):
    • Open web interface
    • Submit question: "I forgot my password"
    • Show real-time processing through agents
    • Display professional response
  4. Results (10s): Show stats, response time, quality validation
  5. Value (5s): "Automates 70% of support tickets, saves 6-8 hours/week"

🐛 Troubleshooting

Error: "Module not found"

Reinstall dependencies:

pip install -r requirements.txt

Error: "GOOGLE_API_KEY not found"

Create .env file with your API key (see Installation step 4)

Error: "Port 8000 already in use"

# Find and kill process using port 8000
Get-NetTCPConnection -LocalPort 8000 | Select-Object -ExpandProperty OwningProcess | Stop-Process -Force

# Or use a different port
$env:API_PORT="8001"; python api_server.py

Web demo not connecting to API

  • Ensure API server is running on http://localhost:8000
  • Check browser console for CORS errors
  • Verify API_URL in demo/index.html matches your server

📝 Future Enhancements

  • Add more FAQs (expand to 50+ entries)
  • Implement semantic search for better FAQ matching
  • Add sentiment analysis to writer agent
  • Integrate with real email service (SendGrid, Mailgun)
  • Add multi-language support
  • Implement conversation history tracking
  • Add escalation to human agent for complex issues
  • Create admin dashboard for monitoring

🤝 Contributing

Contributions are welcome! See CONTRIBUTING.md for guidelines.

🔒 Security

See SECURITY.md for vulnerability reporting.

📄 License

This project is licensed under the MIT License.

🙏 Acknowledgments

  • Kaggle Agents Intensive - For the excellent 5-day course
  • Google Gemini Team - For the powerful AI API
  • Gemini 2.5 Flash - For fast, accurate LLM responses

📚 Resources


Built with ❤️ for the Kaggle Agents Intensive Capstone Project

Demonstrating multi-agent orchestration, custom tools, validation loops, and production-ready deployment.

About

Multi-agent customer support system using Google Gemini AI - Built for Kaggle Agents Intensive

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors