As AI agents become more practical for real-world systems, I wanted to experiment with building a conversational Shopify assistant capable of:
- Fetching Shopify orders
- Fetching products/items
- Fetching store details
- Generating human-readable insights using AI
- Running through a LangGraph workflow
- Exposing a Flask chatbot API
In this article, Iβll walk through how I built a Shopify AI Assistant using:
Traditional chatbots usually become difficult to scale once:- multiple tools are involved
- workflows become dynamic
- human interactions are needed
- state management becomes complex
LangGraph solves this elegantly by allowing us to create:
- Stateful AI workflows
- Conditional routing
- Tool execution graphs
- Human-in-the-loop systems
- Multi-step agent pipelines
This makes it perfect for AI commerce assistants.
Architecture
The workflow looks like this:
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"]
})
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
- Python Compatibility
Some AI libraries were not stable on Python 3.14.
I eventually standardized on:
Python 3.11
- 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.
- 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)