Spaces:
Sleeping
Download README.md from renzotello/Ecommerce_Support: direct link, hf CLI and curl.
- Browser
- Download file 16.6 kB
-
https://huggingface.co/spaces/renzotello/Ecommerce_Support/resolve/main/README.md
- Command line
-
hf download hf://spaces/renzotello/Ecommerce_Support/README.md
-
curl -L -o README.md https://huggingface.co/spaces/renzotello/Ecommerce_Support/resolve/main/README.md
A newer version of the Gradio SDK is available: 6.33.0
title: E-Commerce Support Agent
emoji: ๐๏ธ
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 6.3.0
app_file: app.py
pinned: false
license: mit
An intelligent multi-agent customer support system powered by OpenAI's Swarm framework. This AI agent handles customer inquiries for e-commerce operations including order tracking, inventory management, and refund processing.
๐ Features
Multi-Agent Architecture
- ๐ฏ Triage Agent - Intelligently routes customer requests to specialized agents
- ๐ฆ Inventory Agent - Handles product availability, searches, and stock reservations
- ๐ง Technical Support Agent - Manages order tracking and delivery inquiries
- ๐ฐ Billing Agent - Processes refunds and payment-related queries
Core Capabilities
- โ Order Tracking - Real-time order status and delivery information
- โ Inventory Management - Product search, availability checks, and stock alerts
- โ Refund Processing - Automated refund request handling
- โ Stock Reservations - 15-minute checkout holds to prevent overselling
- โ Conversation History - Persistent chat context across sessions
- โ Low Stock Alerts - Automatic notifications for products running low
Technical Highlights
- ๐ค OpenAI Swarm Framework - Advanced multi-agent orchestration
- ๐๏ธ PostgreSQL/Supabase - Production-ready database with full ACID compliance
- ๐ Async Operations - Fast, non-blocking agent responses
- ๐ Complete Audit Trail - Stock movement tracking and conversation logs
- ๐จ Gradio Interface - User-friendly web UI for testing and demos
๐ธ Demo
User: "Is the MacBook Pro in stock?"
Agent: [Routing to Inventory Agent...]
Inventory Agent: "Product: MacBook Pro 14-inch (PROD001)
โ
IN STOCK
๐ฆ Stock Information:
- Available: 25 units
- Price: $1,999.99
- Category: Electronics
Great news! We have plenty in stock. Would you like to place an order?"
๐๏ธ Architecture
Agent Flow
โโโโโโโโโโโโโโโ
โ User โ
โโโโโโโโฌโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโ
โ Triage Agent โ โโโ Routes to appropriate specialist
โโโโโโโโโโฌโโโโโโโโโ
โ
โโโโโโดโโโโโฌโโโโโโโโโโโฌโโโโโโโโโโโโโโ
โ โ โ โ
โผ โผ โผ โผ
โโโโโโโ โโโโโโโโโโ โโโโโโโโ โโโโโโโโโโโโ
โBillsโ โSupport โ โInven-โ โWarehouse โ
โAgentโ โ Agent โ โ tory โ โ Manager โ
โโโโโโโ โโโโโโโโโโ โโโโโโโโ โโโโโโโโโโโโ
Database Schema
customers โโโฌโโ orders โโโโ refunds
โ
โโโ conversations
inventory โโโฌโโ reservations
โ
โโโ stock_movements
๐ Quick Start
Prerequisites
- Python 3.8 or higher
- OpenAI API key
- Supabase account (free tier works great!)
Installation
Clone the repository
git clone https://github.com/renzotjpro/ecommerce_support.git cd ecommerce_supportCreate virtual environment
python -m venv .venv # On Windows .venv\Scripts\activate # On macOS/Linux source .venv/bin/activateInstall dependencies
pip install -r requirements.txtSet up environment variables
Create a
.envfile in the project root:# OpenAI Configuration OPENAI_API_KEY=sk-your-openai-api-key-here # Supabase Configuration SUPABASE_URL=https://xxxxx.supabase.co SUPABASE_KEY=your-supabase-anon-key-hereCreate database tables
- Go to your Supabase Dashboard
- Navigate to SQL Editor
- Copy and run the SQL schema from
docs/complete_database_schema.sql
Load sample data
python setup_inventory_data.pyRun the application
CLI Mode:
python main.pyWeb Interface (Gradio):
python app.pyThen open
http://localhost:7860in your browser
๐ Project Structure
ecommerce_support/
โโโ ๐ agents_config.py # Agent definitions and configurations
โโโ ๐ app.py # Gradio web interface
โโโ ๐ database.py # Database operations (Supabase)
โโโ ๐ inventory_tools.py # Inventory management tools
โโโ ๐ main.py # CLI interface
โโโ ๐ tools.py # Order and refund tools
โโโ ๐ setup_inventory_data.py # Sample data loader
โโโ ๐ requirements.txt # Python dependencies
โโโ ๐ .env # Environment variables (not in git)
โโโ ๐ .env.example # Example environment file
โโโ ๐ .gitignore # Git ignore rules
โโโ ๐ README.md # This file
๐ฏ Usage Examples
Example 1: Check Product Availability
User: "Do you have the iPhone 15 Pro in stock?"
Agent: Product: iPhone 15 Pro (PROD002)
โ
IN STOCK
๐ฆ Stock Information:
- Available: 50 units
- Reserved: 0 units
- Total Stock: 50 units
- Price: $999.99
- Category: Electronics
Example 2: Search Products by Category
User: "Show me all electronics"
Agent: Products in 'Electronics' category (5 items):
โ
MacBook Pro 14-inch (ID: PROD001)
Price: $1,999.99 | Available: 25 units
โ
iPhone 15 Pro (ID: PROD002)
Price: $999.99 | Available: 50 units
โ ๏ธ AirPods Pro (2nd Gen) (ID: PROD003)
Price: $249.99 | Available: 3 units
LOW STOCK WARNING!
Example 3: Order Tracking
User: "Where is my order #ORD1299?"
Agent: Order ORD1299 status:
- Status: SHIPPED
- Tracking Number: TRK123456789
- Expected Delivery: Friday, January 25, 2026
- Total: $1,024.99
Example 4: Refund Request
User: "I want a refund for order #ORD1299"
Agent: Refund initiated successfully!
- Order ID: ORD1299
- Refund Amount: $1,024.99
- Refund ID: REF-78910
- Status: PENDING
The refund will be processed within 5-7 business days.
Example 5: Reserve Product (Checkout)
User: "Reserve 2 AirPods Pro for me"
Agent: โ
Reservation Successful!
Product ID: PROD003
Quantity Reserved: 2 units
Customer: CUST001
Reservation ID: 123
โฐ This reservation will expire in 15 minutes
Please complete your purchase before it expires.
๐ง Configuration
Agent Customization
Modify agent behavior in agents_config.py:
inventory_agent = Agent(
name="Inventory Agent",
instructions="""You are an inventory specialist...""",
tools=[
check_product_availability,
search_products_by_name,
reserve_product,
# Add more tools here
]
)
Adding New Products
Use the database interface:
from database import OrderDatabase
db = OrderDatabase()
db.add_product(
product_id="PROD999",
name="New Product",
description="Product description",
price=99.99,
category="Electronics",
stock_quantity=100
)
Adjusting Stock Thresholds
Modify low stock alerts:
db.add_product(
product_id="PROD001",
name="MacBook Pro",
# ... other fields
low_stock_threshold=5 # Alert when โค 5 units
)
๐๏ธ Database
Tables
| Table | Purpose |
|---|---|
customers |
Customer profiles and information |
orders |
Order history and tracking |
inventory |
Product catalog and stock levels |
refunds |
Refund requests and processing |
reservations |
Temporary stock holds (15-min expiry) |
stock_movements |
Complete audit trail of inventory changes |
conversations |
Customer support chat history |
product_categories |
Product category definitions |
Key Relationships
- Orders โ Customers (Many-to-One)
- Refunds โ Orders (Many-to-One)
- Reservations โ Inventory + Customers (Many-to-One each)
- Stock Movements โ Inventory (Many-to-One)
Sample Queries
Get customer order history:
SELECT * FROM orders
WHERE customer_id = 'CUST001'
ORDER BY created_at DESC;
Check low stock products:
SELECT * FROM inventory
WHERE (stock_quantity - reserved_quantity) <= low_stock_threshold;
View stock movement audit:
SELECT * FROM stock_movements
WHERE product_id = 'PROD001'
ORDER BY timestamp DESC;
๐ ๏ธ Tools Available
Order Management Tools
check_order_status(order_id)- Get order details and trackingget_customer_orders(customer_id)- List all customer ordersupdate_order_tracking(order_id, tracking, delivery_date)- Update shipping infocreate_new_order(customer_id, items, total)- Create new order
Inventory Tools
check_product_availability(product_id)- Check stock levelssearch_products_by_name(search_term)- Search productssearch_products_by_category(category)- Filter by categoryget_product_details(product_id)- Get complete product inforeserve_product(product_id, quantity, customer_id)- Reserve stockcancel_reservation(reservation_id)- Release reservationupdate_product_stock(product_id, quantity_change, reason)- Update inventoryget_low_stock_alerts()- Get products needing restockadd_new_product(...)- Add product to catalog
Refund Tools
process_refund(order_id, reason)- Initiate refundcheck_refund_status(refund_id)- Check refund progress
๐ Deployment
Deploy to Hugging Face Spaces
Create a Space on Hugging Face
- Go to huggingface.co/spaces
- Click "Create new Space"
- Choose "Gradio" as SDK
- Name it
ecommerce-support
Push your code
git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/ecommerce-support git push hf mainAdd secrets in Space Settings
OPENAI_API_KEY- Your OpenAI API keySUPABASE_URL- Your Supabase project URLSUPABASE_KEY- Your Supabase anon/public key
Wait for build (~2-3 minutes)
Your agent is live! ๐
- Access at:
https://huggingface.co/spaces/YOUR_USERNAME/ecommerce-support
- Access at:
Deploy to Other Platforms
The application can also be deployed to:
- Render - For production hosting
- Railway - Easy deployment with databases
- Vercel - For serverless deployment
- AWS/GCP/Azure - Enterprise hosting
๐งช Testing
Run CLI Tests
python main.py
Run Web Interface
python app.py
Test Database Connection
from database import OrderDatabase
db = OrderDatabase()
print(db.get_product("PROD001"))
Test Individual Tools
from inventory_tools import check_product_availability
result = check_product_availability("PROD001")
print(result)
๐ Performance
Response Times
- Simple queries (product availability): ~1-2 seconds
- Complex queries (multi-step reservations): ~2-4 seconds
- Database operations: <100ms average
Scalability
- Concurrent users: Supports multiple simultaneous conversations
- Database: PostgreSQL handles 1000+ TPS
- Agent routing: Sub-second decision making
๐ Security
Best Practices Implemented
- โ Environment variables for sensitive data
- โ No API keys in code
- โ Input validation on all database operations
- โ SQL injection prevention (parameterized queries)
- โ Error handling with safe messages
- โ Audit logging for all inventory changes
Data Privacy
- Customer conversations stored securely
- PII (email, phone) encrypted at rest in Supabase
- No data sharing with third parties
๐ค Contributing
Contributions are welcome! Here's how you can help:
- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Areas for Contribution
- ๐จ UI/UX improvements
- ๐ Multi-language support
- ๐ง Email notification system
- ๐ Analytics dashboard
- ๐ค Additional agent types
- โ More test coverage
๐ Troubleshooting
Common Issues
Issue: "Module not found" error
# Solution: Install dependencies
pip install -r requirements.txt
Issue: "Supabase connection failed"
# Solution: Check .env file
# Verify SUPABASE_URL and SUPABASE_KEY are correct
Issue: "Product not found"
# Solution: Load sample data
python setup_inventory_data.py
Issue: "OpenAI API error"
# Solution: Verify API key in .env
# Check OpenAI account has credits
Issue: Database tables don't exist
# Solution: Run SQL schema in Supabase SQL Editor
# See installation step 5
๐ Documentation
- Setup Guide - Detailed installation instructions
- Database Schema - Complete database documentation
- API Reference - Tool and function documentation
- Deployment Guide - Production deployment steps
๐ Learning Resources
Built With
- OpenAI Swarm - Multi-agent orchestration
- Supabase - PostgreSQL database
- Gradio - Web interface framework
- Python AsyncIO - Async operations
Recommended Reading
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐จ๐ป Author
Renzo
- GitHub: @renzotjpro
- LinkedIn: https://www.linkedin.com/in/renzotellojimenez/
- Email: renzotj@outlook.com
๐ Acknowledgments
- OpenAI for the Swarm framework and GPT models
- Supabase for the excellent PostgreSQL hosting
- Gradio for the user-friendly interface framework
- Anthropic for Claude assistance in development
๐ Roadmap
Phase 1 - Core Features โ
- Multi-agent architecture
- Order tracking
- Inventory management
- Refund processing
- Stock reservations
- Web interface
Phase 2 - Enhancements ๐ง
- Email notifications
- Product recommendations
- Analytics dashboard
- Multi-language support
- Voice interface
Phase 3 - Advanced Features ๐ฎ
- Machine learning for demand forecasting
- Automated restocking suggestions
- Customer sentiment analysis
- Integration with shipping APIs
- Mobile app
๐ฌ Support
Need help? Here's how to get support:
- ๐ Check the documentation in the
docs/folder - ๐ Open an issue on GitHub for bugs
- ๐ก Start a discussion for feature requests
- ๐ง Email me for private inquiries
โญ Star History
If you find this project helpful, please consider giving it a star! โญ
Made with โค๏ธ and AI