Skip to main content

Advent Calendar Day 11: How AI Agents Handle Special Occasions

· 8 min read
Norah Sakal

Advent Calendar Day 11: How AI Agents Handle Special Occasions

This December, I'm showing how naive chatbots fail and how AI agents make shopping easier.

We've seen naive chatbots fail at clarifying questions, context shifts, numerical requirements, multiple requests in one query, price filters, style suggestions, unavailable colors, negations, new color requirements and multi-color requests.

Today, we focus on how agent handle special occasions.

When a customer says, "I need women's shoes for a gala night", a naive chatbot returns casual items.

An AI agent, however, understands the need for formal shoes, filtering the database to find elegant heels perfect for the occasion.

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: Finding Formal Footwear for a Gala

Scenario

Customer: "I need women's shoes for a gala night":

A customer initiates a chat with SoleMates

A customer initiates a chat with SoleMates and asks about women's shoes for a gala night

Naive Chatbot Response

The naive chatbot treats the entire query as text and searches:

The naive chatbot treats the entire query as text and searches

The naive chatbot treats the entire query as text and searches

Without proper filtering none of the pulled shoes are formal, which the simple chatbot acknowledge:

The naive chatbot can filter for formal shoes and fails to find suitable shoes for the event

The naive chatbot can filter for formal shoes and fails to find suitable shoes for the event

Finally, the simple chatbot suggests the casual shoes it managed to pull from the vector database, while it reasons "While these options are more casual, you might want to look for something more formal for a gala night":

The naive chatbot ends up failing to find suitable shoes for a gala event

The naive chatbot ends up failing to find suitable shoes for a gala event

Why Did the Naive Chatbot Fail?

  • It has no concept of "gala" or "formal" usage
  • Treats the request as plain text and returns random women's shoes
  • Cannot filter by occasion or dress code

Limitations Highlighted

  • No event-based filtering
  • No metadata usage for style or formality
  • Inaccurate results that don't meet the user's event needs

AI Agent Solution

The AI agent applies metadata filters for formal usage. When the customer says, "I need women's shoes for a gala night," the agent:

  1. Identifies gender: women
  2. Interprets "gala night" as formal usage
  3. Applies filters:
    • gender=women
    • usage=formal

It then returns elegant heels suitable for a gala:

The AI agent applies metadata filters for formal usage

The AI agent applies metadata filters for formal usage

All of these are formal, stylish, and fit the event.

How Did the AI Agent Succeed?

  • Recognizes the need for formal footwear
  • Filters by usage=formal and gender=women
  • Delivers results that match the event's dress code

Key Takeaways

Naive Chatbot Limitation

  • Does not understand event requirements and returns casual products

AI Agent Advantages

  • Handles event-driven filtering with metadata
  • Ensures the products match the occasion
  • Delivers a better shopping experience by focusing on suitability

Conclusion

Events like a gala night call for formal attire, but naive chatbots fail to differentiate casual from formal shoes.

An AI agent uses metadata to find products that align with the user's event needs.

This makes shopping easier, more efficient, and tailored to the customer's occasion.

About This Series

In this series, we show the weak spots of naive chatbots and how AI agents overcome them using metadata and intelligent reasoning.

Follow along to learn more about building smarter, user-focused AI solutions.

Coming Up: Handling Numeric Height Queries

In tomorrow's issue, we'll explore how AI Agents Handle Numeric Height Queries

Upcoming AI agent course

Sign up here for my upcoming course to learn how to build your own AI agent chatbot


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

def create_metadata_filter(filter_string):
# For "women's shoes for a gala night"
# Extract gender=women and usage=formal
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 shoes for a gala night")

Agent workflow:

  1. Customer: "I need women's shoes for a gala night"
  2. Agent calls create_metadata_filter("women's gala night shoes")
  3. Gets filter:
[
{"key": "gender", "value": "women", "operator": "=="},
{"key": "usage", "value": "formal", "operator": "=="}
]
  1. Returns formal heels suitable for a gala night:

The AI agent applies filters and finds suitable shoes

The AI agent applies filters and finds suitable shoes

Here's the full agent output:

Added user message to memory: I need women's shoes for a gala night
=== Calling Function ===
Calling function: create_metadata_filter with args: {"filter_string": "women's gala night shoes"}
=== Function Output ===
[{"key": "gender", "value": "women", "operator": "=="}, {"key": "usage", "value": "formal", "operator": "=="}]
=== Calling Function ===
Calling function: search_footwear_database with args: {"query_str": "shoes", "filters_json": [{"key": "gender", "value": "women", "operator": "=="}, {"key": "usage", "value": "formal", "operator": "=="}]}
=== Function Output ===
[{'color': 'black', 'text': 'Catwalk women corporate leather black heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 88, 'usage': 'formal', 'price': 155, 'heels_height': 1, 'similarity_score': 1.19167948}, {'color': 'black', 'text': 'Carlton london women black heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 86, 'usage': 'formal', 'price': 200, 'heels_height': 2, 'similarity_score': 1.18591034}, {'color': 'nude', 'text': 'Carlton london women nude heels', 'gender': 'women', 'product_type': 'heels', 'product_id': 87, 'usage': 'formal', 'price': 200, 'heels_height': 2, 'similarity_score': 1.18491364}]
=== LLM Response ===
Here are some elegant women's shoes perfect for a gala night:

1. **Catwalk Women Corporate Leather Black Heels**
- Color: Black
- Heel Height: 1 inch
- Price: $155

2. **Carlton London Women Black Heels**
- Color: Black
- Heel Height: 2 inches
- Price: $200

3. **Carlton London Women Nude Heels**
- Color: Nude
- Heel Height: 2 inches
- Price: $200

These options are stylish and suitable for a formal event. Let me know if you need more information or other options!

Additional Resources

Check out my GitHub repository for more code samples and instructions on building AI agents that handle multiple attributes.

Upcoming AI agent course

Sign up here for my upcoming course to learn how to build your own AI agent chatbot

Why use AI agents instead of simple chatbots in e-commerce?

Shoppers often need formal footwear for special occasions like gala nights. While naive chatbots return casual shoes, AI agents use metadata filtering to find elegant heels that fit the event perfectly. This event-based search approach helps customers find the right products quickly, improving their online shopping experience and increasing satisfaction.