Skip to content

Repository files navigation

Hierarchical Multi-Agent Customer Support System

A production-ready hierarchical multi-agent system built with LangGraph, LangChain, FastAPI, and Docker. This system demonstrates advanced AI agent orchestration for customer support operations.

🏗️ Architecture

Agent Hierarchy

┌─────────────────────────┐
│   Supervisor Agent      │
│  (Ticket Router)        │
└───────────┬─────────────┘
            │
    ┌───────┴────────┬────────────┬──────────────┐
    │                │            │              │
┌───▼────┐    ┌─────▼─────┐  ┌──▼────────┐  ┌──▼──────────┐
│Knowledge│    │ Database  │  │    MCP    │  │  Response   │
│  Base   │    │   Agent   │  │Integration│  │ Generator   │
│ Agent   │    │           │  │   Agent   │  │             │
│(Qdrant) │    │ (SQLite)  │  │(FS/GH/SL) │  │             │
└─────────┘    └───────────┘  └───────────┘  └─────────────┘

Components

  1. Supervisor Agent: Routes customer tickets to appropriate worker agents based on ticket classification
  2. Knowledge Base Agent: Semantic search using Qdrant vector database for FAQ and documentation
  3. Database Agent: Structured queries on SQLite for customer data and ticket history
  4. MCP Integration Agent: Integrates multiple MCP servers:
    • Filesystem MCP: File operations and document management
    • GitHub MCP: Issue tracking and repository operations
    • Slack MCP: Team notifications and communication

🚀 Features

  • ✅ Hierarchical agent orchestration with LangGraph StateGraph
  • ✅ Production-quality code with OOPS principles and PEP-8 compliance
  • ✅ Highly configurable design with Pydantic v2 settings
  • ✅ Vector search with Qdrant for semantic knowledge retrieval
  • ✅ Structured data queries with SQLite and aiosqlite
  • ✅ Multiple MCP server integrations (filesystem, GitHub, Slack)
  • ✅ RESTful API with FastAPI 0.115.0
  • Real-time streaming with Server-Sent Events (SSE)
  • LangGraph checkpointing with AsyncSqliteSaver
  • Structured outputs with Pydantic models
  • ✅ Docker containerization with multi-stage builds
  • ✅ Comprehensive logging and error handling
  • ✅ Health checks and component monitoring
  • Latest LangChain 1.2.10 and LangGraph 1.0.9 (Feb 2026)
  • LangGraph Checkpoint 4.0.0 with durable execution
  • Qdrant Client 1.17.0 for vector search

📋 Prerequisites

  • Docker and Docker Compose
  • Python 3.11+ (for local development)
  • OpenAI API key
  • Optional: GitHub token, Slack bot token

🛠️ Installation

Using Docker (Recommended)

  1. Clone the repository:
git clone <repository-url>
cd multi-agent-system
  1. Create environment file:
cp .env.example .env
# Edit .env with your API keys
  1. Start the system:
docker-compose up -d
  1. Initialize the databases:
docker-compose exec app python scripts/initialize_db.py

Local Development

  1. Create virtual environment:
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate
  1. Install dependencies:
pip install -r requirements.txt
  1. Set environment variables:
export OPENAI_API_KEY=your_key_here
# ... other environment variables
  1. Run the application:
uvicorn src.app:app --reload

📚 API Documentation

Once running, visit:

Example API Calls

Submit a Support Ticket (Synchronous)

curl -X POST "http://localhost:8000/tickets" \
  -H "Content-Type: application/json" \
  -d '{
    "content": "I forgot my password and the reset email is not arriving",
    "customer_id": "CUST001",
    "priority": "high"
  }'

Response:

{
  "ticket_id": "550e8400-e29b-41d4-a716-446655440000",
  "status": "completed",
  "response": "To reset your password, please...",
  "processing_time": 2.34
}

Submit a Support Ticket (Streaming with SSE)

curl -X POST "http://localhost:8000/tickets/stream" \
  -H "Content-Type: application/json" \
  -H "Accept: text/event-stream" \
  -d '{
    "content": "What is your refund policy?",
    "priority": "medium"
  }'

Streaming response:

event: start
data: {"ticket_id": "...", "status": "processing"}

event: update
data: {"node": "supervisor", "decision": "knowledge_base"}

event: u├── mcp_integration.py
│   │   └── response_generator.py
│   ├── config/             # Configuration management
│   │   └── settings.py     # Pydantic settings with validators
│   ├── database/           # Database clients
│   │   ├── qdrant_client.py
│   │   └── sqlite_client.py
│   ├── graph/              # LangGraph workflows
│   │   └── workflow.py     # StateGraph implementation
│   ├── mcp/                # MCP servers
│   │   ├── server.py       # FastMCP server with tools/resources
│   │   ├── filesystem_client.py
│   │   ├── github_client.py
│   │   └── slack_client.py
│   ├── models/             # Pydantic models
│   │   └── schemas.py
│   ├── services/           # Business logic
│   │   └── ticket_service.py
│   └── app.py              # FastAPI application with streaming
├── tests/                  # Test suite
│   ├── test_agents.py
│   ├── test_database.py
│   └── conftest.py
├── scripts/                # Utility scripts
│   ├── initialize_db.py
│   └── test_system.py
├── data/                   # Data storage
│   └── mcp_files/
├── logs/                   # Application logs
├── docs/                   # Documentation
│   ├── API_GUIDE.md
│   └── ARCHITECTURE.md
├── docker-compose.yml      # Development compose
├── Dockerfile              # Development Dockerfile
├── Dockerfile.prod         # Production Dockerfile
├── requirements.txt        # Python dependencies (latest versions)
├── setup.py                # Package setup
├── pyproject.toml          # Tool configuration
├── DEPLOYMENT.md           # Detailed deployment guide
# Run with coverage
pytest --cov=src --cov-report=html

# Run specific test file
pytest tests/test_agents.py

🏗️ Project Structure

multi-agent-system/
├── src/
│   ├── agents/              # Agent implementations
│   │   ├── base.py         # Base agent class
│   │   ├── supervisor.py   # Supervisor agent
│   │   ├── knowledge_base.py
│   │   ├── database.py
│   │   └── mcp_integration.py
│   ├── config/             # Configuration management
│   ├── database/           # Database clients
│   ├── graph/              # LangGraph workflows
│   ├── mcp/                # MCP server clients
│   ├── models/             # Pydantic models
│   ├── services/           # Business logic
│   └── main.py             # FastAPI application
├── tests/                  # Test suite
├── scripts/                # Utility scripts
├── data/                   # Data storage
├── logs/                   # Application logs
├── docker-compose.yml
├── Dockerfile
├── requirements.txt
└── README.md

🔧 Configuration

Key configuration files:

  • .env: Environment variables
  • src/config/settings.py: Application settings
  • pyproject.toml: Tool configuration

📊 Monitoring

  • Health endpoint: /health
  • Metrics endpoint: /metrics (if enabled)
  • Logs: ./logs/ directory

🔐 Security

  • Non-root Docker user
  • Environment variable management
  • API key validation
  • Input sanitization
  • Error message sanitization

📝 License

MIT License

🤝 Contributing

Contributions welcome! Please read CONTRIBUTING.md for guidelines.

📧 Support

For issues and questions, please open a GitHub issue.

About

This repository provides programs to build Agentic AI code for Generative AI with LlamaIndex, Deep Lake, and Pinecone leveraging the power of OpenAI and Hugging Face models for generation and evaluation.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages