This project is an Autonomous AI Agent System designed to optimize e-commerce operations. It acts as a super-intelligent "Operations Manager" that monitors your Shopify store 24/7.
Instead of checking spreadsheets or manually calculating reorder points, this system:
- Analyzes your entire product catalog using AI.
- Identifies risks (stockouts) and opportunities (price optimizations).
- Visualizes actionable insights on a real-time dashboard.
- Executes actions directly to your Shopify store (restocking, repricing) via an automated loop.
The system consists of four main pillars working in harmony:
- Role: Your live e-commerce store.
- Data: Contains Products, Variants, Inventory Levels, Prices, and Orders.
- Interaction: The system reads from Shopify to get the current state and writes back to Shopify to execute decisions.
- Role: The "Schedule Manager" and "Connector".
- Function:
- Runs on a schedule (e.g., every morning).
- Fetches raw data from Shopify.
- Sends this data to the AI Backend for analysis.
- Can handle downstream tasks like emailing suppliers or sending PDF reports.
- Role: The Intelligence Core.
- Tech Stack: Python, FastAPI, Pandas, LangChain, Groq (Llama 3).
- Function:
- Receives data from n8n.
- Runs the 3-Agent Pipeline (detailed below) to analyze every SKU.
- Serves the API endpoints for the dashboard.
- Handles the logic to update Shopify when a user clicks a button.
- Role: The Control Center.
- Tech Stack: React, TypeScript, Vite, TailwindCSS.
- Function:
- Displays the health of the store (Profitable vs Loss-making SKUs).
- Shows a prioritized "Alerts" list of items needing immediate attention.
- Allows the human user to "Resolve" issues (Restock/Price Change) with one click.
Here is exactly what happens from start to finish when the system runs:
- Trigger: The n8n workflow starts (e.g., scheduled or manual trigger).
- Fetch: n8n requests all Products and Orders from Shopify.
- Send: n8n sends this raw JSON data to the Python Backend endpoint:
POST /api/n8n/analyze.- Note: The backend waits in a "Listening" state until this data arrives.
Once the backend receives the data, it triggers the Multi-Agent System. The data is passed sequentially through three specialized AI agents:
-
Agent 1: The Profit Doctor 💰
- Goal: Calculate financial health.
- Logic: Looks at Selling Price vs. Cost (COGS), Platform Fees, and Ad Spend.
- Output: Determines
Profit Per Unit,Daily Loss, and categorizes items as "High Margin" or "Loss Maker".
-
Agent 2: The Inventory Sentinel 📦
- Goal: Prevent stockouts and overstocking.
- Logic: analyzing Sales Velocity (how fast items sell) vs. Current Stock.
- Output: Calculates
Days of Stock Leftand assigns aRisk Level(CRITICAL, WARNING, SAFE). - Example: "You have 5 units left, selling 2 per day -> Stockout in 2.5 days -> CRITICAL RISK."
-
Agent 3: The Strategy Supervisor 🧠
- Goal: Prioritize and Recommend.
- Logic: Takes inputs from the previous two agents. It asks: "Is this high-profit item running out of stock?" (High Priority) or "Is this low-profit item doing fine?" (Low Priority).
- Output: Assigns an
Impact Score(0-100) and aRecommended Action(e.g., "RESTOCK_URGENT", "PRICE_CHANGE", "LIQUIDATE"). - LLM Insight: It uses Llama 3 (via Groq) to generate a human-readable explanation (e.g., "Profitable hero product risking stockout in 3 days. Restock immediately to avoid ₹5,000 revenue loss.").
- Live View: The React Dashboard polls the backend API.
- Alerts Tab: The dashboard filters the data to show only Actionable Alerts (Critical Risks).
- Insights: Displays the AI's explanation and the calculated numbers.
- User Action: You see a "Critical Low Stock" alert. You click "Resolve" -> "Restock".
- Input: You enter the quantity (e.g., "50 units").
- Execution:
- The Dashboard sends this command to the Backend (
POST /api/alerts/action). - The Backend uses the Shopify Admin API to instantly update the inventory level on your real Shopify store.
- The Backend updates its local memory so the alert disappears immediately.
- The Dashboard sends this command to the Backend (
- Logging: The action is logged (
completed_user_actions), which provides an audit trail.
api.py: The main server. Handles APIs, runs the pipeline, and coordinates updates.pipeline.py: Orchestrates the flow of data through the 3 agents.shopify_loader.py: A specialized utility to talk to Shopify (Fetch Data / Update Stock / Update Price).config.py: manages settings and API keys (Shopify Tokens, Groq Keys).dashboard/: The frontend code (React).src/components/AlertsTab.tsx: The UI for the alerts feed and resolution modals.src/services/api.ts: The bridge between the frontend and the Python backend.
- Backend: Python 3.10+
- Framework: FastAPI
- AI/LLM: LangChain + Groq (Llama 3.3 70B)
- Data Processing: Pandas (DataFrames)
- Frontend: React + TypeScript + Vite
- Styling: TailwindCSS
- Automation: n8n