A Full-Stack AI Agent that autonomously monitors inventory levels, detects shortages, and drafts Purchase Orders for human approval.
Auto-Procure solves the "Blank Page Problem" in supply chain management. Instead of a human manually checking spreadsheets for low stock, an Autonomous AI Agent wakes up, scans the database, and proactively drafts orders when inventory hits a critical threshold.
The system features a Human-in-the-Loop workflow: the AI proposes the order with reasoning (e.g., "Stock is 5, minimum is 10"), but a human manager must click "Approve" on the dashboard to finalize it.
The system is built as a monorepo with a clear separation of concerns:
- Framework: Python FastAPI
- AI Orchestration: CrewAI & LangChain
- LLM: OpenAI GPT-4
- Database: Supabase (PostgreSQL)
- Framework: Next.js 15 (App Router)
- Styling: Tailwind CSS & Shadcn UI
- State: Server Actions & React Hooks
- Autonomous Monitoring: The Agent connects directly to the SQL database to check real-time stock levels.
- Intelligent Reasoning: It doesn't just match numbers; it generates a natural language explanation for why an order is needed.
- Human-in-the-Loop UI: A dedicated "Approval Queue" in the dashboard allows managers to review AI drafts before execution.
- Real-Time Updates: The frontend refreshes instantly upon approval, providing immediate feedback (Optimistic UI).
- Docker Desktop (Recommended method)
- OR: Node.js 18+ & Python 3.10+ (Manual method)
- OpenAI API Key & Supabase Credentials
The fastest way to test the system. No need to install Python or Node locally.
- Clone the repository:
git clone [https://github.com/yourusername/auto-procure.git](https://github.com/yourusername/auto-procure.git)
cd auto-procure- Configure Environment: Create a
.envfile in thebackend/folder:
OPENAI_API_KEY=sk-...
SUPABASE_URL=http://host.docker.internal:54321 # Use this for local Docker (Windows/Mac)
# OR use your cloud URL: https://xyz.supabase.co
SUPABASE_KEY=...- Launch the System: Run this command in the root folder:
docker-compose up --buildThe Dashboard will be available at http://localhost:3000 and the API at http://localhost:8000.
Use this if you want to modify the code or debug locally.
- Backend Setup
cd backend
python -m venv venv
# Windows: venv\Scripts\activate | Mac/Linux: source venv/bin/activate
pip install -r requirements.txt-
Configure Keys Create a
.envfile inbackend/as shown in Option A. -
Run Backend
python run.py
# Server starts at [http://127.0.0.1:8000](http://127.0.0.1:8000)- Frontend Setup Open a new terminal:
cd frontend
npm install
npm run dev
# Dashboard runs at http://localhost:3000Once both servers are running, you can manually trigger the AI Agent to perform a supply chain check cycle.
Option 1: Via Terminal (API) Open a new terminal and run:
# Windows (PowerShell) - Note the .exe usage
curl.exe -X POST http://localhost:8000/run-agent
# Mac / Linux / Git Bash
curl -X POST http://localhost:8000/run-agentOption 2: Via Dashboard
-
Navigate to
http://localhost:3000. -
View the Live Inventory Feed.
-
If an order is needed, the "AI Drafted Orders" section will appear automatically.
-
Click "Approve" to finalize the order.
The Supply Chain Analyst agent follows a strict logic loop:
-
OBSERVE: Calls the
check_low_stocktool to scan theproductstable in Supabase. -
REASON: Identifies items where
current_stock < min_threshold. -
ACT: Groups items by vendor and calls the
create_draft_ordertool. -
RECORD: Writes a new row to the
purchase_orderstable with statuspending_approval.
Example AI Output: "I have detected low stock for RTX 3080 (Count: 2, Min: 10). I am creating a draft order for 8 units to restore healthy levels."
The Dashboard Interface Real-time inventory tracking with the AI Approval Queue active.
-
Email Notifications: Send an alert to the manager when a draft is created.
-
Multi-Agent System: Add a "Price Negotiator" agent to check competitor prices.
-
Historical Analysis: Use vector search to predict seasonal trends.
-
Backend Connection Refused?
Ensure your
SUPABASE_URLin.envuseshttp://host.docker.internal:54321if running Supabase locally.localhostinside a container refers to the container itself, not your machine. -
Frontend Fetch Failed?
Ensure your frontend code uses the Docker service name (
http://backend:8000) for server-side fetches, andlocalhostfor client-side fetches.
Contributions, issues, and feature requests are welcome!
This project is MIT licensed.
