DEV Community

Chandan Pattanayak
Chandan Pattanayak

Posted on

Building an AI-Powered Shopify Assistant Using LangGraph, Flask, and Mistral AI

As AI agents become more practical for real-world systems, I wanted to experiment with building a conversational Shopify assistant capable of:

  1. Fetching Shopify orders
  2. Fetching products/items
  3. Fetching store details
  4. Generating human-readable insights using AI
  5. Running through a LangGraph workflow
  6. Exposing a Flask chatbot API

In this article, I’ll walk through how I built a Shopify AI Assistant using:

πŸ›  Tech Stack

  • Workflow Engine: LangGraph
  • LLM Framework: LangChain
  • AI Model: Mistral AI
  • API Layer: Flask
  • Commerce Backend: Shopify Admin API
Traditional chatbots usually become difficult to scale once:
  1. multiple tools are involved
  2. workflows become dynamic
  3. human interactions are needed
  4. state management becomes complex

LangGraph solves this elegantly by allowing us to create:

  1. Stateful AI workflows
  2. Conditional routing
  3. Tool execution graphs
  4. Human-in-the-loop systems
  5. Multi-step agent pipelines

This makes it perfect for AI commerce assistants.
Architecture

The workflow looks like this:


User Request
↓
LangGraph Analyzer Node
↓
Conditional Router
β”œβ”€β”€ Orders Tool
β”œβ”€β”€ Products Tool
β”œβ”€β”€ Shop Tool
↓
Mistral AI Formatter
↓
Human Readable Response
↓
Flask API Response

Tech Stack
Component Technology
Workflow Engine LangGraph
LLM Framework LangChain
AI Model Mistral AI
API Layer Flask
Commerce Backend Shopify Admin API
Language Python 3.11
Shopify API Client

First, I created a lightweight Shopify Admin API client.

Click to see the Shopify API Client implementation

python
import os
import requests

SHOP_DOMAIN = os.getenv("SHOP_DOMAIN")
ADMIN_TOKEN = os.getenv("SHOPIFY_ADMIN_TOKEN")

def _fetch(path):

    url = f"https://{SHOP_DOMAIN}{path}"

    response = requests.get(
        url,
        headers={
            "X-Shopify-Access-Token": ADMIN_TOKEN,
            "Content-Type": "application/json"
        }
    )

    response.raise_for_status()

    return response.json()


def get_orders(limit=5):
    return _fetch(
        f"/admin/api/2026-04/orders.json?limit={limit}"
    )


def get_products(limit=5):
    return _fetch(
        f"/admin/api/2026-04/products.json?limit={limit}"
    )


def get_shop():
    return _fetch(
        "/admin/api/2026-04/shop.json"
    )

Creating LangGraph State

LangGraph workflows operate on a shared state object.

from typing_extensions import TypedDict

class GraphState(TypedDict):

    user_input: str
    intent: str
    tool_result: str
    final_response: str

This state flows across all nodes in the graph.

Creating Tool Nodes

I used LangChain tools for Shopify operations.

from langchain_core.tools import tool

@tool
def orders_tool():

    orders = get_orders(limit=5)

    return str(orders)

Similarly:

products_tool()
shop_tool()
Intent Analyzer Node

The analyzer determines which tool to call.

def analyze_input_node(state):

    user_input = state["user_input"].lower()

    if "order" in user_input:
        intent = "order"

    elif "product" in user_input:
        intent = "item"

    elif "shop" in user_input:
        intent = "shop"

    else:
        intent = "unknown"

    return {
        "intent": intent
    }
Conditional Routing

LangGraph supports conditional edges beautifully.

workflow.add_conditional_edges(
    "analyze_node",
    router
)

The router dynamically decides which node executes next.

Using Mistral AI for Human Readable Output

Raw JSON from Shopify isn’t user friendly.

So I added Mistral AI to transform the response into:

summaries
bullet points
recommendations
business insights
from langchain_mistralai import ChatMistralAI

llm = ChatMistralAI(
    model="mistral-large-latest",
    temperature=0.3
)

Prompt:

prompt = """
Convert Shopify data into:
- human readable format
- professional summary
- business insights
"""

This dramatically improved the user experience.

Flask Chat API

Finally, I exposed the workflow using Flask.

@app.route("/chat", methods=["POST"])
def chat():

    data = request.get_json()

    result = graph.invoke(
        {
            "user_input": data["message"],
            "intent": "",
            "tool_result": "",
            "final_response": ""
        }
    )

    return jsonify({
        "response": result["final_response"]
    })
Enter fullscreen mode Exit fullscreen mode

Example Request
{
"message": "show recent orders"
}
Example AI Response
Here are your latest Shopify orders:

β€’ Order #1001

  • Customer: John Doe
  • Total: $120
  • Status: Paid

β€’ Order #1002

  • Customer: Alice Smith
  • Total: $340
  • Status: Pending

Business Insight:
Most recent orders are successfully paid, indicating healthy transaction flow.
Challenges I Faced

  1. Python Compatibility

Some AI libraries were not stable on Python 3.14.

I eventually standardized on:

Python 3.11

  1. LangGraph State Errors

I encountered:

InvalidUpdateError

This happened because every LangGraph node must update at least one state field.

Once I ensured every node returned a valid state update, the workflow stabilized.

  1. Human Readable AI Formatting

Initially the responses were raw JSON.

Adding Mistral AI transformed the chatbot into something actually useful for business users.

Why This Architecture Is Powerful

This setup enables:

AI agents
tool orchestration
conversational commerce
workflow automation
scalable multi-agent systems

The same architecture can later support:

WhatsApp bots
Slack bots
React chat UIs
Inventory forecasting
AI recommendations
customer support automation
Final Thoughts

LangGraph + LangChain + Mistral AI creates an incredibly powerful combination for building production-grade AI systems.

Combining it with Shopify opens interesting possibilities for:

commerce copilots
operational assistants
analytics bots
AI support systems

This project started as an experiment but quickly evolved into a scalable AI workflow architecture.

Top comments (0)