Skip to content

mrzasad/langGraph-superstore-ai-assistant

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

3 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ID: 001

πŸ›’ Target Superstore AI Assistant

An AI-powered shopping assistant built with Streamlit, LangGraph, and LangChain for the fictional US retail chain Target Superstore.

The assistant supports:

  • πŸ” Product search and filtering
  • πŸ›οΈ Cart management
  • πŸ‘€ User loyalty lookup
  • πŸ’° Final price calculation with loyalty points
  • βœ… Human-in-the-loop approval for cart additions
  • πŸ€– Tool-calling AI agent using LangGraph
  • πŸ’¬ Conversational UI with Streamlit

πŸš€ Features

βœ… AI Shopping Assistant

Users can chat naturally in English or Urdu to:

  • Search products
  • Add/remove products from cart
  • View cart contents
  • Checkout
  • Ask pricing questions

βœ… Human-in-the-Loop (HITL) Approval

Before adding products to the cart, the system pauses execution and asks for explicit approval using LangGraph interrupts.

Example flow:

  1. User says:

    Add Nestle Milk Pack

  2. AI triggers add_to_cart

  3. Graph pauses with:

    • Approve βœ…
    • Reject ❌
  4. Execution resumes after user decision


βœ… Tool-Based Architecture

The assistant uses LangChain tools:

Tool Description
get_product_info Product search/filtering
get_user_data Retrieve customer profile
calculate_final_price Loyalty discount calculation
add_to_cart Add item with approval workflow
view_cart Show cart
remove_from_cart Remove item from cart

πŸ—οΈ Tech Stack

  • Python
  • Streamlit
  • LangGraph
  • LangChain
  • Pandas
  • OpenAI / LLM Provider
  • dotenv

πŸ“‚ Project Structure

project/
β”‚
β”œβ”€β”€ app.py
β”œβ”€β”€ llm.py
β”œβ”€β”€ users_data.json
β”œβ”€β”€ superstore_products.xlsx
β”œβ”€β”€ .env
β”œβ”€β”€ requirements.txt
└── README.md

βš™οΈ Installation

1. Clone Repository

git clone <your_repo_url>
cd <project_name>

2. Create Virtual Environment

python -m venv venv

Activate it:

Mac/Linux

source venv/bin/activate

Windows

venv\Scripts\activate

3. Install Dependencies

pip install -r requirements.txt

πŸ” Environment Variables

Create a .env file:

OPENAI_API_KEY=your_api_key_here

You may also configure your custom LLM provider inside llm.py.


▢️ Run the App

streamlit run app.py

🧠 How It Works

LangGraph Workflow

User Input
    ↓
LLM Node
    ↓
Tool Decision
    ↓
Tool Execution
    ↓
Interrupt (if approval needed)
    ↓
Resume Execution
    ↓
Assistant Response

πŸ›οΈ Cart Workflow

Add Product

User β†’ "Add product X"
       ↓
AI calls add_to_cart
       ↓
Interrupt triggered
       ↓
User approves/rejects
       ↓
Cart updated

πŸ“Š Product Search

The assistant supports filtering by:

  • Product Name
  • Product ID
  • Brand
  • Category
  • Subcategory
  • Price Range
  • Tags

Example queries:

Show me imported chocolates
Find organic products under 1000 PKR
Search for Nestle products

πŸ‘€ User Data Example

get_user_data(user_id) returns:

{
  "user_id": "U1001",
  "name": "Ali Khan",
  "loyalty_points": 2500,
  "tier": "Gold"
}

πŸ’° Loyalty Price Calculation

calculate_final_price(price=5000, loyalty_points=1200)

Output:

Discount applied: 1200 PKR.
Final price: 3800 PKR.

🧩 Key LangGraph Concepts Used

StateGraph

Defines the agent workflow graph.


ToolNode

Executes LangChain tools automatically.


interrupt()

Pauses execution for human approval.


Command(resume=...)

Resumes graph execution after approval/rejection.


InMemorySaver

Persists conversation state across Streamlit reruns.


🎨 UI Components

Main Chat Area

  • User/assistant conversation
  • Approval prompts
  • Tool responses

Sidebar Cart

Displays:

  • Cart items
  • Quantity
  • Total price

πŸ“Œ Example Commands

Show me snacks under 500 PKR
Add P1001 to cart
View my cart
Remove P1001
Checkout

πŸ”’ System Prompt Rules

The AI strictly follows rules such as:

  • Only one cart tool per turn
  • Approval required for add-to-cart
  • No approval for remove-from-cart
  • Checkout triggered only on explicit request

πŸ› οΈ Future Improvements

  • Persistent database storage
  • Real payment integration
  • Inventory updates
  • Voice assistant support
  • Multi-user authentication
  • Recommendation engine
  • Order history
  • WhatsApp integration

πŸ“¦ Example Requirements

streamlit
pandas
langchain
langgraph
python-dotenv
openpyxl

πŸ“Έ Demo Flow

User: Add Milk Pack

AI:
Approval Required
[Approve] [Reject]

User clicks Approve

AI:
Added Milk Pack x1 to cart.
Cart total: PKR 450

🀝 License

MIT License


πŸ™Œ Acknowledgements

Built with:

About

This repository features a conversational AI shopping assistant designed for a Superstore. It is built using LangGraph and Streamlit, providing an interactive interface where users can search through inventory, check item details, build a shopping cart, and get real-time assistance.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages