Conversational AI shopping assistant with product search, real-time inventory checking, personalised recommendations, and shopping cart management — all orchestrated via Azure OpenAI function calling.
Project 8, Chapter 20 of "Prompt to Production" by Maneesh Kumar
The assistant accepts natural language queries such as "Show me blue running shoes under £80 in size 10" and automatically calls the right tools to fulfil the request:
| Tool | Backend |
|---|---|
search_products |
Azure AI Search (hybrid keyword + vector) |
check_inventory |
Redis cache (with mock fallback) |
get_recommendations |
Purchase-history engine |
add_to_cart |
In-memory cart store |
When Azure credentials are not configured the system operates entirely on built-in mock data so you can develop and test locally without any cloud dependencies.
┌─────────────────────────────────────────┐
│ ShopSmart UK Customer │
└──────────────────┬──────────────────────┘
│ natural language query
▼
┌─────────────────────────────────────────┐
│ FastAPI (src/main.py) │
│ POST /api/v1/chat │
└──────────────────┬──────────────────────┘
│
▼
┌─────────────────────────────────────────┐
│ ShoppingAgent (src/agent.py) │
│ Azure OpenAI GPT-4o tool-call loop │
└──┬──────────┬──────────┬──────────┬────┘
│ │ │ │
┌────────────▼──┐ ┌────▼────┐ ┌─▼──────┐ ┌▼──────────┐
│ ProductSearcher│ │Inventory│ │Recomm- │ │Shopping │
│(product_search │ │Checker │ │endation│ │Cart │
│ .py) │ │(inventory│ │Engine │ │(cart.py) │
└───────┬────────┘ │ .py) │ │(recom- │ └─────┬─────┘
│ └────┬────┘ │mendations│ │
│ │ │ .py) │ │
▼ ▼ └────────┘ ▼
┌──────────────┐ ┌──────────┐ ┌──────────────┐
│ Azure AI │ │ Redis │ │ In-Memory │
│ Search │ │ Cache │ │ Cart Store │
│ (or mock) │ │(or mock) │ │ (session) │
└──────────────┘ └──────────┘ └──────────────┘
│
▼
┌─────────────────────────────────────────┐
│ Azure OpenAI (GPT-4o) │
│ Function calling orchestration │
└─────────────────────────────────────────┘
- Python 3.11+
- Docker and Docker Compose (optional, for containerised deployment)
- Azure OpenAI resource with
gpt-4odeployment (optional — mock mode works without it) - Azure AI Search resource (optional — mock mode works without it)
- Redis (optional — mock fallback is built in)
cd ecommerce-assistant
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtcp .env.example .env
# Edit .env and fill in your Azure credentials.
# Leave values as "placeholder" to run in mock mode (no Azure required).uvicorn src.main:app --reload --port 8000The API is now available at http://localhost:8000.
Interactive docs: http://localhost:8000/docs
docker compose -f infra/docker-compose.yml up --buildThis starts the FastAPI app and a Redis container with health checks.
When Azure AI Search credentials are configured, run the indexer once to populate the search index with vector embeddings:
python -m indexer.index_cataloguepytest tests/ -vNo Azure credentials are required — all Azure calls are mocked.
Send a natural language shopping query.
Request body:
{
"message": "Show me blue running shoes under £100 in size 10",
"session_id": "my-session-id",
"customer_id": "customer-001"
}Response:
{
"response": "I found 2 blue running shoes under £100 in size 10 ...",
"session_id": "my-session-id",
"cart_items": 0,
"total": 0.0
}Retrieve cart contents for a session.
Clear all items from a session's cart.
Health check endpoint.
# Search for blue running shoes under £100 in size 10
curl -X POST http://localhost:8000/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message": "Show me blue running shoes under £100 in size 10", "session_id": "test-123"}'
# Ask for boot recommendations
curl -X POST http://localhost:8000/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message": "What boots do you recommend?", "session_id": "test-123", "customer_id": "customer-001"}'
# Add an item to cart
curl -X POST http://localhost:8000/api/v1/chat \
-H "Content-Type: application/json" \
-d '{"message": "Add the Nike Air Max in size 9 to my cart", "session_id": "test-123"}'
# View cart
curl http://localhost:8000/api/v1/cart/test-123
# Clear cart
curl -X DELETE http://localhost:8000/api/v1/cart/test-123ecommerce-assistant/
├── src/
│ ├── __init__.py
│ ├── main.py # FastAPI entry point
│ ├── agent.py # Shopping agent with tool-calling loop
│ ├── tools.py # 4 OpenAI function schemas
│ ├── product_search.py # Azure AI Search / mock product search
│ ├── inventory.py # Redis-cached inventory checks
│ ├── recommendations.py # Purchase history recommendations
│ ├── cart.py # Shopping cart CRUD
│ ├── prompts.py # System prompt
│ ├── config.py # Settings (pydantic-settings)
│ └── models.py # Pydantic data models
├── indexer/
│ ├── index_catalogue.py # Azure AI Search indexing script
│ └── sample_products.json # 20 sample products
├── tests/
│ ├── __init__.py
│ └── test_agent.py # pytest-asyncio test suite
├── infra/
│ ├── Dockerfile
│ └── docker-compose.yml # App + Redis
├── .env.example
├── requirements.txt
└── README.md
When AZURE_OPENAI_API_KEY or AZURE_SEARCH_API_KEY is set to "placeholder"
(the default), the system operates entirely on local mock data:
- Product search — filters the built-in
MOCK_PRODUCTSdict (20 products) - Inventory — reads from
MOCK_INVENTORY(no Redis required) - Recommendations — uses
MOCK_PURCHASE_HISTORY - Cart — in-memory dict (lost on restart)
This allows full local development and testing without any cloud resources.
This project is Project 8 from Chapter 20 of "Prompt to Production" by Maneesh Kumar Published 2026 — demonstrating production-grade agentic AI patterns with Azure OpenAI function calling.