An AI shopping assistant accepts natural language queries like "find me wireless headphones under $100 with good reviews" and returns ranked product recommendations backed by live Amazon data. This type of assistant combines an LLM for intent parsing and recommendation generation with a real-time product search API for fresh inventory and pricing. This tutorial builds such an assistant using LangChain, ScavioSearch configured for Amazon, and a simple conversational loop.
Prerequisites
- Python 3.10 or higher
- pip install langchain langchain-scavio langchain-openai
- A Scavio API key
- An OpenAI API key
Walkthrough
Step 1: Configure the Amazon search tool
Instantiate ScavioSearch with the amazon platform. This gives the LangChain agent access to live Amazon product search.
from langchain_scavio import ScavioSearch
amazon_tool = ScavioSearch(
api_key="your_scavio_api_key",
platform="amazon",
marketplace="US",
max_results=10
)Step 2: Build the system prompt
Define a system prompt that instructs the LLM to act as a shopping assistant and format recommendations clearly.
SYSTEM_PROMPT = (
"You are a helpful shopping assistant. When the user asks for product recommendations, "
"use the search tool to find current Amazon listings. Always mention price, rating, and "
"a brief reason for each recommendation. Keep responses concise."
)Step 3: Create the agent
Wire the Amazon tool into a LangChain agent with the shopping assistant system prompt.
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", SYSTEM_PROMPT),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, [amazon_tool], prompt)
executor = AgentExecutor(agent=agent, tools=[amazon_tool])Step 4: Run a shopping query
Invoke the assistant with a natural language shopping request and print the response.
response = executor.invoke({
"input": "Find me the best wireless headphones under $150 with noise cancellation"
})
print(response["output"])Python Example
import os
from langchain_scavio import ScavioSearch
from langchain_openai import ChatOpenAI
from langchain.agents import create_tool_calling_agent, AgentExecutor
from langchain_core.prompts import ChatPromptTemplate
os.environ["OPENAI_API_KEY"] = "your_openai_key"
tool = ScavioSearch(api_key=os.environ["SCAVIO_API_KEY"], platform="amazon", marketplace="US")
llm = ChatOpenAI(model="gpt-4o", temperature=0)
prompt = ChatPromptTemplate.from_messages([
("system", "You are a helpful shopping assistant. Use the search tool to find products."),
("human", "{input}"),
("placeholder", "{agent_scratchpad}"),
])
agent = create_tool_calling_agent(llm, [tool], prompt)
executor = AgentExecutor(agent=agent, tools=[tool], verbose=True)
if __name__ == "__main__":
result = executor.invoke({"input": "Best noise-canceling headphones under $150"})
print(result["output"])JavaScript Example
const { ChatOpenAI } = require("@langchain/openai");
const { DynamicTool } = require("@langchain/core/tools");
const { AgentExecutor, createToolCallingAgent } = require("langchain/agents");
const { ChatPromptTemplate } = require("@langchain/core/prompts");
const API_KEY = process.env.SCAVIO_API_KEY;
const amazonTool = new DynamicTool({
name: "amazon_search",
description: "Search Amazon for products. Input is a product search query.",
func: async (query) => {
const res = await fetch("https://api.scavio.dev/api/v1/search", {
method: "POST",
headers: { "x-api-key": API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ platform: "amazon", query, marketplace: "US" })
});
const data = await res.json();
return JSON.stringify((data.products || []).slice(0, 5));
}
});
async function main() {
const llm = new ChatOpenAI({ model: "gpt-4o" });
const prompt = ChatPromptTemplate.fromMessages([
["system", "You are a helpful shopping assistant."],
["human", "{input}"],
["placeholder", "{agent_scratchpad}"]
]);
const agent = await createToolCallingAgent({ llm, tools: [amazonTool], prompt });
const executor = new AgentExecutor({ agent, tools: [amazonTool] });
const result = await executor.invoke({ input: "Best wireless headphones under $150" });
console.log(result.output);
}
main().catch(console.error);Expected Output
Based on current Amazon listings, here are the top noise-canceling headphones under $150:
1. Anker Soundcore Q45 — $59.99 (4.4 stars, 28,000+ reviews)
Great ANC for the price, up to 50 hours battery life.
2. Sony WH-CH720N — $149.00 (4.5 stars, 15,000+ reviews)
Lightweight with Sony's proprietary ANC, folds flat.