Skip to main content

Advent Calendar Day 5: How AI Agents Handle Price-Based Queries

· 9 min read
Norah Sakal

Advent Calendar Day 5: How AI Agents Handle Price-Based Queries

This December, I'm showing how naive chatbots fail at simple requests that matter to online shoppers, while AI agents rise to the challenge.

We've seen naive chatbots fail at clarifying questions, context shifts, numerical requirements and multiple requests in one query.

Today, the customer asks for a price filter: "I need women's heels under $75." The naive chatbot ignores the price filter and fails, but the AI agent applies the numeric filter to find the right match.

Source Code

For a deeper dive into this example, check out my GitHub repository for a detailed, step-by-step implementation in Jupyter Notebooks, breaking down the code and methodology used by the AI agent in today's scenario.

Introducing SoleMates

SoleMates is our fictional online shoe store we'll use to illustrate these concepts:

SoleMates is our fictional online shoe store

SoleMates is our fictional online shoe store

Today's Challenge: Price-Based Requests

Scenario

A customer asks our SoleMates chatbot:

Customer: "I need women's heels under $75":

A customer initiates a chat with SoleMates

A customer initiates a chat with SoleMates and asks about women's heels under $75

Naive Chatbot Response

The naive chatbot takes the entire message and turns it into a vector.

It pulls items from the database that mention women's heels but does not apply the under $75 requirement:

The naive chatbot pulls items from the database that mention women's heels

The naive chatbot pulls items from the database that mention women's heels but does not apply the under $75 requirement

It returns heels from various price points, all over $75:

The naive chatbot ends up failing to find heels under $75

The naive chatbot ends up failing to find heels under $75

Because it can't filter by price, it ends up saying that there are no heels under $75:

The naive chatbot ends up failing to find heels under $75

The naive chatbot ends replying: "There are no women's heels available under $75"

But we know from the product database that there are heels priced less than $75. The naive chatbot just doesn't know how to filter by price.

Why Did the Naive Chatbot Fail?

  • No numeric filtering for prices
  • Ignores the "under $75" part and treats the query as simple text
  • Ends up giving irrelevant or incorrect answers

Limitations Highlighted

  • No price-based reasoning
  • No metadata filtering on price
  • Inaccurate results because it cannot handle numeric conditions

AI Agent Solution

The AI agent sees the request and decides to apply a price filter. It uses metadata filters to pick out women's heels and then filters by price < 75.

  1. The agent creates a metadata filter: gender = women, product_type = heels, price < 75
  2. It queries the vector database with these filters
  3. It finds women's heels under $75 and returns them

Agent's Interaction:

Customer: "I need women's heels under $75"
Agent: "Understood. Let me find women's heels priced below $75":

The AI agent sees the request and decides to apply a price filter

The AI agent sees the request and decides to apply a price filter

How Did the AI Agent Succeed?

  • Checks for price and applies a numeric filter
  • Uses metadata to find women's heels specifically
  • Delivers accurate product matches within the price range

Key Takeaways

Naive Chatbot Limitation

  • Ignores price requirements and fails to apply numeric filters

AI Agent Advantages

  • Handles numeric price filters easily
  • Finds items within the requested budget
  • Returns results that match the user's exact needs

Conclusion

By applying numeric filters, the AI agent gives customers the products they actually want. This small detail - handling a price filter - makes a big difference.

Naive chatbots fail because they do not reason about numeric conditions, but AI agents process and filter data accurately.

About This Series

Each day in December, I show a different weakness of naive chatbots and how AI agents solve it. Follow along to learn how to build smarter and more helpful AI systems.

Coming Up: Understanding Context Shifts

In tomorrow's issue, we'll explore How AI Agents Offer Style Suggestions

Learn to Build Your Own AI Agent Chatbot

I'm preparing a course to teach you how to build and deploy your own AI agent chatbot. Sign up here!


Behind the Scenes: Code Snippets

Here's a simplified illustration of how the AI agent processes the query.

We're giving the agent access to two tools it can use freely:

  1. Vector database metadata filtering
  2. Vector database query

1. Vector database metadata filtering tool

This tool lets the agent break down user queries into multiple filters:

def create_metadata_filter(filter_string):

# For "women's heels under $75":
# Returns:
# [{"key": "gender", "value": "women", "operator": "=="},
# {"key": "product_type", "value": "heels", "operator": "=="},
# {"key": "price", "value": 75, "operator": "<"}]

filters = parse_filters(filter_string)
return filters

2. Vector database query

def search_footwear_database(query_str, filters_json):
embedded_query = embed_query_aws_titan(query_str)
results = vector_db.search(embedded_query, filters=filters_json)
return results
AWS Titan Multimodal Embeddings in Action

I use AWS Titan, a multimodal embedding model that converts both product texts and images into vectors, integrated as the function embed_query_aws_titan into the AI agent tool search_footwear_database.

This means the AI agent can process a query like "red heels" and match it to not only product descriptions but also actual images of red heels in the database.

By combining text and image data, the model helps the AI agent provide more relevant and visually aligned recommendations based on the customer's input.

Agent workflow

Construct agent worker with access to the two tools and initiate the agent:

from llama_index.core.agent import AgentRunner, FunctionCallingAgentWorker

agent_worker = FunctionCallingAgentWorker.from_tools(
[
create_metadata_filters_tool,
query_vector_database_tool,
])

agent = AgentRunner(
agent_worker,
)

Initiate conversation with agent:

agent.chat("I need women's heels under $75")
  1. Agent calls create_metadata_filter("women's heels under $75")
  2. Gets filters:
[
{"key": "gender", "value": "women", "operator": "=="},
{"key": "product_type", "value": "heels", "operator": "=="},
{"key": "price", "value": 75, "operator": "<"}
]
  1. Calls search_footwear_database("heels", filters)
  2. Finds women's heels priced under $75
  3. Returns them to user:

The AI agent sees the request and decides to apply a price filter

The AI agent sees the request and decides to apply a price filter

Here's the full agent output:

Added user message to memory: I need women's heels under $75
=== Calling Function ===
Calling function: create_metadata_filter with args: {"filter_string": "women's heels under $75"}
=== Function Output ===
[{"key": "gender", "value": "women", "operator": "=="}, {"key": "price", "value": 75, "operator": "<"}]
=== Calling Function ===
Calling function: search_footwear_database with args: {"query_str": "heels", "filters_json": [{"key": "gender", "value": "women", "operator": "=="}, {"key": "price", "value": 75, "operator": "<"}]}
=== Function Output ===
[{'color': 'brown', 'text': 'Catwalk women bronze brown heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 78, 'usage': 'casual', 'price': 70, 'similarity_score': 1.68853617}, {'color': 'blue', 'text': 'Nike women ten blue white shoe', 'gender': 'women', 'product_type': 'casual shoes', 'product_id': 44, 'usage': 'sports', 'price': 65, 'similarity_score': 1.21486032}, {'color': 'white', 'text': 'Nike women main draw white blue shoe', 'gender': 'women', 'product_type': 'sports shoes', 'product_id': 28, 'usage': 'sports', 'price': 65, 'similarity_score': 1.20944571}, {'color': 'white', 'text': "Adidas women's piona white shoe", 'gender': 'women', 'product_type': 'casual shoes', 'product_id': 26, 'usage': 'casual', 'price': 50, 'similarity_score': 1.20460951}, {'color': 'black', 'text': 'Senorita women black flats', 'gender': 'women', 'product_type': 'flats', 'product_id': 9, 'usage': 'casual', 'price': 70, 'similarity_score': 1.20130277}, {'color': 'green', 'text': 'Senorita women green sandals', 'gender': 'women', 'product_type': 'flats', 'product_id': 66, 'usage': 'casual', 'price': 70, 'similarity_score': 1.20000648}, {'color': 'brown', 'text': 'Catwalk women brown sandals', 'gender': 'women', 'product_type': 'flats', 'product_id': 82, 'usage': 'casual', 'price': 50, 'similarity_score': 1.18358696}, {'color': 'turquoise blue', 'text': 'Catwalk women turquoise casual shoes', 'gender': 'women', 'product_type': 'casual shoes', 'product_id': 40, 'usage': 'casual', 'price': 65, 'similarity_score': 1.16420531}]
=== LLM Response ===
Here are some women's heels under $75 that you might like:

1. **Catwalk Women Bronze Brown Heels**
- Color: Brown
- Price: $70
- Usage: Casual

If you need more options or have specific preferences, feel free to let me know!

Additional Resources

For a deeper dive into this example, check out my GitHub repository where I break down the code and methodology used by the AI agent in today's scenario.

Learn to Build Your Own AI Agent Chatbot

Want to build your own AI agent that applies price filters? Sign up here and learn how to create smarter chatbots.

Why use AI agents instead of simple chatbots?

If you need an AI chatbot that can handle price filters, numeric reasoning, and metadata-based product searches, AI agents can help.

By using retrieval augmented generation and product metadata, you can build chatbots that understand budget limits and return products that fit your price range.

This improves the shopping experience and helps users find what they want quickly.