Skip to content

Autonomous Supply Chain Agent | Full-Stack AI System that monitors inventory and drafts orders with Human-in-the-Loop approval. Built with Next.js, FastAPI, CrewAI & Supabase.

License

Notifications You must be signed in to change notification settings

MLaitarovsky/auto-procure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

11 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿค– Auto-Procure: Autonomous Supply Chain Agent

A Full-Stack AI Agent that autonomously monitors inventory levels, detects shortages, and drafts Purchase Orders for human approval.

Project Status Docker AI Model Stack


๐Ÿ“– Overview

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.


๐Ÿ—๏ธ Architecture

The system is built as a monorepo with a clear separation of concerns:


System Architecture

1. The Brain (Backend)

  • Framework: Python FastAPI
  • AI Orchestration: CrewAI & LangChain
  • LLM: OpenAI GPT-4
  • Database: Supabase (PostgreSQL)

2. The Interface (Frontend)

  • Framework: Next.js 15 (App Router)
  • Styling: Tailwind CSS & Shadcn UI
  • State: Server Actions & React Hooks

โšก Key Features

  • 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).

๐Ÿš€ Getting Started

Prerequisites

  • Docker Desktop (Recommended method)
  • OR: Node.js 18+ & Python 3.10+ (Manual method)
  • OpenAI API Key & Supabase Credentials

Option A: Run with Docker ๐Ÿณ (Recommended)

The fastest way to test the system. No need to install Python or Node locally.

  1. Clone the repository:
git clone [https://github.com/yourusername/auto-procure.git](https://github.com/yourusername/auto-procure.git)
cd auto-procure
  1. Configure Environment: Create a .env file in the backend/ 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=...
  1. Launch the System: Run this command in the root folder:
docker-compose up --build

The Dashboard will be available at http://localhost:3000 and the API at http://localhost:8000.


Option B: Manual Installation ๐Ÿ› ๏ธ

Use this if you want to modify the code or debug locally.

  1. Backend Setup
cd backend
python -m venv venv
# Windows: venv\Scripts\activate  |  Mac/Linux: source venv/bin/activate

pip install -r requirements.txt
  1. Configure Keys Create a .env file in backend/ as shown in Option A.

  2. Run Backend

python run.py
# Server starts at [http://127.0.0.1:8000](http://127.0.0.1:8000)
  1. Frontend Setup Open a new terminal:
cd frontend
npm install
npm run dev
# Dashboard runs at http://localhost:3000

โ–ถ๏ธ Usage / Demo

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

Option 2: Via Dashboard

  1. Navigate to http://localhost:3000.

  2. View the Live Inventory Feed.

  3. If an order is needed, the "AI Drafted Orders" section will appear automatically.

  4. Click "Approve" to finalize the order.


๐Ÿง  How the Agent Works

The Supply Chain Analyst agent follows a strict logic loop:

  • OBSERVE: Calls the check_low_stock tool to scan the products table in Supabase.

  • REASON: Identifies items where current_stock < min_threshold.

  • ACT: Groups items by vendor and calls the create_draft_order tool.

  • RECORD: Writes a new row to the purchase_orders table with status pending_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."


๐Ÿ“ธ Screenshots

The Dashboard Interface Real-time inventory tracking with the AI Approval Queue active.

Screenshot 2026-02-06 184406

๐Ÿ”ฎ Future Improvements

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


๐Ÿ”ง Troubleshooting

  • Backend Connection Refused?

    Ensure your SUPABASE_URL in .env uses http://host.docker.internal:54321 if running Supabase locally. localhost inside 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, and localhost for client-side fetches.


๐Ÿค Contributing

Contributions, issues, and feature requests are welcome!


๐Ÿ“ License

This project is MIT licensed.

About

Autonomous Supply Chain Agent | Full-Stack AI System that monitors inventory and drafts orders with Human-in-the-Loop approval. Built with Next.js, FastAPI, CrewAI & Supabase.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published