Spaces:
Sleeping
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
16.6 kB
| 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. | |
| [](https://www.python.org/downloads/) | |
| [](https://github.com/openai/swarm) | |
| [](https://supabase.com) | |
| [](https://opensource.org/licenses/MIT) | |
| --- | |
| ## ๐ 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 | |
| 1. **Clone the repository** | |
| ```bash | |
| git clone https://github.com/renzotjpro/ecommerce_support.git | |
| cd ecommerce_support | |
| ``` | |
| 2. **Create virtual environment** | |
| ```bash | |
| python -m venv .venv | |
| # On Windows | |
| .venv\Scripts\activate | |
| # On macOS/Linux | |
| source .venv/bin/activate | |
| ``` | |
| 3. **Install dependencies** | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| 4. **Set up environment variables** | |
| Create a `.env` file in the project root: | |
| ```env | |
| # 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-here | |
| ``` | |
| 5. **Create database tables** | |
| - Go to your [Supabase Dashboard](https://app.supabase.com) | |
| - Navigate to SQL Editor | |
| - Copy and run the SQL schema from `docs/complete_database_schema.sql` | |
| 6. **Load sample data** | |
| ```bash | |
| python setup_inventory_data.py | |
| ``` | |
| 7. **Run the application** | |
| **CLI Mode:** | |
| ```bash | |
| python main.py | |
| ``` | |
| **Web Interface (Gradio):** | |
| ```bash | |
| python app.py | |
| ``` | |
| Then open `http://localhost:7860` in 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 | |
| ```python | |
| 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 | |
| ```python | |
| 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 | |
| ```python | |
| 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 | |
| ```python | |
| 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) | |
| ```python | |
| 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`: | |
| ```python | |
| 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: | |
| ```python | |
| 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: | |
| ```python | |
| 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:** | |
| ```sql | |
| SELECT * FROM orders | |
| WHERE customer_id = 'CUST001' | |
| ORDER BY created_at DESC; | |
| ``` | |
| **Check low stock products:** | |
| ```sql | |
| SELECT * FROM inventory | |
| WHERE (stock_quantity - reserved_quantity) <= low_stock_threshold; | |
| ``` | |
| **View stock movement audit:** | |
| ```sql | |
| 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 tracking | |
| - `get_customer_orders(customer_id)` - List all customer orders | |
| - `update_order_tracking(order_id, tracking, delivery_date)` - Update shipping info | |
| - `create_new_order(customer_id, items, total)` - Create new order | |
| ### Inventory Tools | |
| - `check_product_availability(product_id)` - Check stock levels | |
| - `search_products_by_name(search_term)` - Search products | |
| - `search_products_by_category(category)` - Filter by category | |
| - `get_product_details(product_id)` - Get complete product info | |
| - `reserve_product(product_id, quantity, customer_id)` - Reserve stock | |
| - `cancel_reservation(reservation_id)` - Release reservation | |
| - `update_product_stock(product_id, quantity_change, reason)` - Update inventory | |
| - `get_low_stock_alerts()` - Get products needing restock | |
| - `add_new_product(...)` - Add product to catalog | |
| ### Refund Tools | |
| - `process_refund(order_id, reason)` - Initiate refund | |
| - `check_refund_status(refund_id)` - Check refund progress | |
| --- | |
| ## ๐ Deployment | |
| ### Deploy to Hugging Face Spaces | |
| 1. **Create a Space on Hugging Face** | |
| - Go to [huggingface.co/spaces](https://huggingface.co/spaces) | |
| - Click "Create new Space" | |
| - Choose "Gradio" as SDK | |
| - Name it `ecommerce-support` | |
| 2. **Push your code** | |
| ```bash | |
| git remote add hf https://huggingface.co/spaces/YOUR_USERNAME/ecommerce-support | |
| git push hf main | |
| ``` | |
| 3. **Add secrets in Space Settings** | |
| - `OPENAI_API_KEY` - Your OpenAI API key | |
| - `SUPABASE_URL` - Your Supabase project URL | |
| - `SUPABASE_KEY` - Your Supabase anon/public key | |
| 4. **Wait for build** (~2-3 minutes) | |
| 5. **Your agent is live!** ๐ | |
| - Access at: `https://huggingface.co/spaces/YOUR_USERNAME/ecommerce-support` | |
| ### 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 | |
| ```bash | |
| python main.py | |
| ``` | |
| ### Run Web Interface | |
| ```bash | |
| python app.py | |
| ``` | |
| ### Test Database Connection | |
| ```python | |
| from database import OrderDatabase | |
| db = OrderDatabase() | |
| print(db.get_product("PROD001")) | |
| ``` | |
| ### Test Individual Tools | |
| ```python | |
| 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: | |
| 1. **Fork the repository** | |
| 2. **Create a feature branch** (`git checkout -b feature/AmazingFeature`) | |
| 3. **Commit your changes** (`git commit -m 'Add some AmazingFeature'`) | |
| 4. **Push to the branch** (`git push origin feature/AmazingFeature`) | |
| 5. **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** | |
| ```bash | |
| # Solution: Install dependencies | |
| pip install -r requirements.txt | |
| ``` | |
| **Issue: "Supabase connection failed"** | |
| ```bash | |
| # Solution: Check .env file | |
| # Verify SUPABASE_URL and SUPABASE_KEY are correct | |
| ``` | |
| **Issue: "Product not found"** | |
| ```bash | |
| # Solution: Load sample data | |
| python setup_inventory_data.py | |
| ``` | |
| **Issue: "OpenAI API error"** | |
| ```bash | |
| # Solution: Verify API key in .env | |
| # Check OpenAI account has credits | |
| ``` | |
| **Issue: Database tables don't exist** | |
| ```bash | |
| # Solution: Run SQL schema in Supabase SQL Editor | |
| # See installation step 5 | |
| ``` | |
| --- | |
| ## ๐ Documentation | |
| - **[Setup Guide](docs/SETUP.md)** - Detailed installation instructions | |
| - **[Database Schema](docs/DATABASE_SCHEMA.md)** - Complete database documentation | |
| - **[API Reference](docs/API_REFERENCE.md)** - Tool and function documentation | |
| - **[Deployment Guide](docs/DEPLOYMENT.md)** - Production deployment steps | |
| --- | |
| ## ๐ Learning Resources | |
| ### Built With | |
| - [OpenAI Swarm](https://github.com/openai/swarm) - Multi-agent orchestration | |
| - [Supabase](https://supabase.com/docs) - PostgreSQL database | |
| - [Gradio](https://gradio.app/docs/) - Web interface framework | |
| - [Python AsyncIO](https://docs.python.org/3/library/asyncio.html) - Async operations | |
| ### Recommended Reading | |
| - [OpenAI Function Calling](https://platform.openai.com/docs/guides/function-calling) | |
| - [Agent Design Patterns](https://www.anthropic.com/research/building-effective-agents) | |
| - [PostgreSQL Best Practices](https://wiki.postgresql.org/wiki/Don%27t_Do_This) | |
| --- | |
| ## ๐ License | |
| This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details. | |
| --- | |
| ## ๐จ๐ป Author | |
| **Renzo** | |
| - GitHub: [@renzotjpro](https://github.com/renzotjpro) | |
| - LinkedIn: [https://www.linkedin.com/in/renzotellojimenez/](https://www.linkedin.com/in/renzotellojimenez/) | |
| - Email: [renzotj@outlook.com](mailto: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 โ | |
| - [x] Multi-agent architecture | |
| - [x] Order tracking | |
| - [x] Inventory management | |
| - [x] Refund processing | |
| - [x] Stock reservations | |
| - [x] 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: | |
| 1. **๐ Check the documentation** in the `docs/` folder | |
| 2. **๐ Open an issue** on GitHub for bugs | |
| 3. **๐ก Start a discussion** for feature requests | |
| 4. **๐ง Email me** for private inquiries | |
| --- | |
| ## โญ Star History | |
| If you find this project helpful, please consider giving it a star! โญ | |
| --- | |
| <div align="center"> | |
| **Made with โค๏ธ and AI** | |
| [Report Bug](https://github.com/renzotjpro/ecommerce_support/issues) ยท [Request Feature](https://github.com/renzotjpro/ecommerce_support/issues) ยท [Documentation](docs/) | |
| </div> |