This project showcases a multi-agent customer support system built with Python, OpenAI, and Streamlit. It uses intelligent routing to handle refunds, product FAQs, and general inquiries, simulating how a chatbot manages customer interactions in e-commerce.
View Demo | View YouTube video
- Triage (classifier) Agent: Intelligently classifies and routes customer queries (query classification, intent detection, routing decisions)
- Refund (specialized) Agent: Handles return requests with transaction verification (transaction verification, refund processing, customer validation)
- FAQ (specialized) Agent: Answers product and policy questions using knowledge base (knowledge base search, answer synthesis, confidence scoring)
Why Multi-Agent Architecture?
- Separation of Concerns: Each agent specializes in specific domains
- Scalability: Easy to add new agent types or modify existing ones
- Maintainability: Clear boundaries between different business logic
- Testing: Independent testing of each agent's functionality
- Natural language understanding for intent classification
- Automatic extraction of transaction details (Invoice numbers, Customer IDs)
- Fuzzy matching for FAQ searches with confidence scoring
- SQLite database for conversation logging
- Session-based context preservation, query limits, and timeout handling
- Automated cleanup for privacy compliance
- Export capabilities for CRM integration
- Response Caching: Reduces API costs for repeated queries
- Session Context: Maintains conversation state
- TTL Management: Prevents stale data issues
- Downloadable chat logs and refund requests
- Real-time session statistics
- CRM team integration ready
- Sufficient input sanitization
- Transaction verification against database
- Error handling with proper fallbacks
- Python 3.12+
- OpenAI API key
- Git
- Clone the repository
git clone https://github.com/your-username/crm-multi-agents.git
cd crm-multi-agents- Run the setup script
python setup.pyThis creates the directory structure, generates mock data, and creates .env template.
- Install dependencies
pip install -r requirements.txt- Configure API key
Edit
.envfile:
OPENAI_API_KEY=your-openai-api-key-here
OPENAI_MODEL=gpt-3.5-turbo # Cost-effective for demo
MAX_TOKENS=150 # Control API costs
TEMPERATURE=0.1 # Consistent responses
MAX_QUERIES_PER_SESSION=30 # Rate limiting
SESSION_TIMEOUT=1800 # 30 minutes
CACHE_TTL=300 # 5-minute response cache- Generate mock data (if not done by setup.py)
python create_mock_data.py- Launch the application
streamlit run app.pyThe app will be available at http://localhost:8501
# Clone and setup
git clone https://github.com/your-username/crm-multi-agents.git
cd crm-multi-agents
# Create .env with your API key
echo "OPENAI_API_KEY=your-key-here" > .env
# Build and run
docker build -t crm-support-ai .
docker run -p 8501:8501 --env-file .env crm-support-aiRefund Requests:
User: "I want to return my wireless headphones from order INV1001, customer CUST267"
System: Verifies transaction → Processes refund → Logs request
Product FAQ:
User: "What are the dimensions of PRD001?"
System: Searches knowledge base → Returns specifications → Logs interaction
General Inquiries:
User: "How can I track my order?"
System: Provides tracking information → Offers additional help
crm-multi-agents/
├── agents/
│ ├── __init__.py
│ ├── base_agent.py # Abstract base class for all agents
│ ├── triage_agent.py # Query classification and routing
│ ├── refund_agent.py # Refund request processing
│ └── faq_agent.py # FAQ and product information
├── utils/
│ ├── __init__.py
│ ├── database.py # SQLite session management
│ ├── validators.py # Input validation and sanitization
│ └── response_schema.py # Standardized response format
├── data/
│ ├── transactions.csv # Mock transaction database
│ ├── faq.json # Knowledge base
│ └── session_logs.db # SQLite session storage
├── config.py # Configuration management
├── app.py # Main Streamlit application
├── create_mock_data.py # Data generation script
├── setup.py # Project initialization
├── requirements.txt # Python dependencies
├── Dockerfile # Container configuration
└── .env # Environment variables (create from template)
Generated by create_mock_data.py execution.
InvoiceNo,StockCode,Description,Quantity,InvoiceDate,UnitPrice,CustomerID
INV1001,PRD008,Gaming Keyboard,3,2025-07-17,89.99,CUST267{
"records": [
{
"id": 1,
"category": "return_policy",
"question": "What is the return policy?",
"answer": "Items can be returned within 30 days...",
"keywords": ["return", "policy", "refund", "30 days"]
}
]
}- Live Chat Integration: Real-time customer support
- API Endpoints: RESTful API for external integrations
- Admin Dashboard: CRM team management interface
- Advanced Analytics: ML-powered conversation and traffic insights
- Fork or star the repository
- Create a feature branch:
git checkout -b feature/your-featureand make your changes - Commit your changes:
git commit -am 'Add some feature' - Push to the branch:
git push origin feature/your-feature - Submit a pull request
- OpenAI for providing the GPT models
- Streamlit for the web framework
- The open-source community for inspiration and tools