Ecommerce_Support / README.md
renzo
Add Hugging Face Spaces configuration to README
cff9197
|
Raw History Blame Contribute Delete
16.6 kB

A newer version of the Gradio SDK is available: 6.33.0

Upgrade
metadata
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.

Python 3.8+ OpenAI Supabase License: 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

    git clone https://github.com/renzotjpro/ecommerce_support.git
    cd ecommerce_support
    
  2. Create virtual environment

    python -m venv .venv
    
    # On Windows
    .venv\Scripts\activate
    
    # On macOS/Linux
    source .venv/bin/activate
    
  3. Install dependencies

    pip install -r requirements.txt
    
  4. Set up environment variables

    Create a .env file 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-here
    
  5. Create database tables

    • Go to your Supabase Dashboard
    • Navigate to SQL Editor
    • Copy and run the SQL schema from docs/complete_database_schema.sql
  6. Load sample data

    python setup_inventory_data.py
    
  7. Run the application

    CLI Mode:

    python main.py
    

    Web Interface (Gradio):

    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

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 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

  2. Push your code

    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

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:

  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

# 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


๐ŸŽ“ Learning Resources

Built With

Recommended Reading


๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.


๐Ÿ‘จ๐Ÿ’ป Author

Renzo


๐Ÿ™ 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:

  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! โญ


Made with โค๏ธ and AI

Report Bug ยท Request Feature ยท Documentation