How AI agents work, from basic chatbots to tool-calling agents, including product search, RAG, and reranking.
This article is part of the Building an E-commerce AI Agent with AWS Serverless series:
- Understanding AI Agents (here)
- Choosing the Right Runtime
- Building Product Search and RAG
- Conversation Memory and Context Management
- Connecting the Agent to Your Webshop
- Security, Privacy, and Observability
- The Sample Application
Source code: https://github.com/ServerlessLife/ecommerce-ai-agent
What we are building
We are building an AI-powered shopping assistant for an e-commerce website. It will provide a chat-based interface where visitors can find products, ask questions, and interact with the shop using natural language.
Our goal is to integrate the assistant into an existing webshop with as few changes as possible, rather than rebuilding the website around AI.
What the assistant will do
The assistant should help visitors throughout their shopping journey:
- Find products: Understand what customers are looking for, even when they describe their needs rather than use exact product names.
- Answer product questions: Explain product features, provide additional information, and help customers compare alternatives.
- Assist with shopping: Help customers select products and add them to their cart.
- Answer common questions: Provide information about delivery, returns, and other shop-related topics.
- Support registered customers: Access relevant account information, such as past orders, and perform operations available to authenticated users.
The assistant will be available to both anonymous visitors and registered customers, with different capabilities depending on whether the user is authenticated.
We also want to support non-English webshops. This is an important requirement because language affects our choice of LLM, embeddings, search and ranking techniques, and guardrails.
Why build a shopping assistant?
A conversational interface gives visitors another way to interact with an online shop. Instead of figuring out which keywords to enter or navigating through multiple product categories, customers can simply explain what they need.
This can make product discovery easier, encourage exploration, and potentially improve the shopping experience.
There is also the novelty factor. AI is still interesting to many customers, and a shopping assistant may attract attention simply because it offers something different from a traditional webshop.
Technical considerations
We want the assistant to be practical to integrate, operate, and maintain. A few requirements will influence our architecture:
- Minimal integration effort: Add the assistant to an existing webshop without major changes to the application.
- Multilingual support: Handle customer conversations and product information in languages other than English.
- User context and permissions: Distinguish between anonymous and authenticated customers, especially when accessing personal information or performing account-specific operations.
- Cost control and abuse prevention: Since the chat is publicly accessible and every LLM request costs money, we need to prevent individual users or bots from consuming resources without limits.
These requirements will guide the technical decisions we make throughout the series.
Before choosing the architecture and implementation, let's look at how a simple chat interface can evolve into a more capable e-commerce AI agent.
Evolution of an e-commerce AI agent
We can build the experience in three stages, adding capability at each step.
A simple chat
The first version has a chat window, but it follows the same steps for every question.
- The customer asks a question in the chat.
- An embedding model converts the question into numbers (a vector).
- Vector search compares that vector with product embeddings prepared earlier in the product vector database.
- The search returns matching products.
- We send the question and matching products to an LLM, which writes an answer with product links.
- The answer is returned to the customer in the chat.
The LLM writes the answer, but does not choose what to search or call tools. Each message starts a fresh search, so it cannot understand “What about a cheaper one?” as a follow-up.
Improving chat
Next, we improve the fixed path by rewriting questions and reranking search results.
- The customer asks a question, such as “My feet get wet when I run in the rain. What should I buy?”
- An LLM rewrites the question as a better product search query, such as “waterproof running shoes.”
- We search the product vector database using the improved query.
- The search returns candidate products.
- We send those search results to a reranking model.
- The reranker compares the products with the query and selects the most suitable ones.
- We send the top products to an LLM to generate an answer.
- The answer is returned to the customer in the chat.
There is still no conversation history at this stage.
A real AI agent
With a real agent, the LLM receives the conversation and decides which tools to call, rather than following a fixed sequence. It can understand follow-up questions like “What about a cheaper one?”, search for products, fetch details, or request an add-to-cart action. The harness executes tool calls and returns their results to the LLM until it can answer. We will explore how this works in more detail later.
How AI agents work
An AI agent repeatedly asks a large language model (LLM) what to do next. The LLM can ask to use a tool. A tool is simply a function with a name and inputs. The agent's code, called a harness, runs the tool, sends the result back, and asks the LLM again. The loop stops when the LLM gives a final answer.


