16-MultiAgentShoppingMallSystem

Multi Agent Shopping Mall System

Open in ColabOpen in GitHub

Overview

Hello, everyone! In this tutorial, we will build a shopping mall system using Multi Agent! By the end of this tutorial, you will become the owner of a very impressive shopping mall! An impressive owner with several solid agents as employees!

Our shopping mall will be structured with one manager who oversees the purchasing and sales systems, a purchasing specialist dedicated to the purchasing system, and a sales specialist dedicated to the sales system.

Each role will perform the following tasks:

Manager

  • Validate Login: Determines whether the user is a legitimate user of our service.

  • Assign Tasks: Assigns appropriate tasks to specialists based on user requirements.

Purchase Specialist

  • Recommend Items: Suggests suitable items based on user needs.

  • Purchase Items: Buys the items confirmed through recommendations.

  • Cancel Purchase: Cancels the purchase if the item has not been dispatched. If it is in transit, unfortunately, we will need to follow exchange/refund procedures (not covered in this tutorial due to its extensive nature).

  • Check Item Status: Shows the status of items purchased by the user. There are four possible statuses: Pre-dispatch, In transit, Delivered, and Cancelled.

Sales Specialist

  • Check Sales History: For sellers, knowing how many items they have sold is crucial. They check their sales history.

  • Restock Inventory: Popular items often sell out quickly. This function allows for restocking.

  • Update Item Status: When a buyer places an order, we need to dispatch the item. Once safely delivered to the buyer, the shipment status should be updated. This function is for updating the item status.

Once these three roles are implemented, we will have the following type of service.

service graphOur Fabulous Service!

Then, let's embark on building our shopping mall service!

Table of Contents

References


Environment Setup

Setting up your environment is the first step. See the Environment Setup guide for more details.

[Note]

The langchain-opentutorial is a package of easy-to-use environment setup guidance, useful functions and utilities for tutorials. Check out the langchain-opentutorial for more details.

You can set API keys in a .env file or set them manually.

[Note] If you’re not using the .env file, no worries! Just enter the keys directly in the cell below, and you’re good to go.

Data Preparation

Let's prepare our shopping mall data. First, we will use the fashion-clothing-products-catalog available on Kaggle. This dataset contains the following information:

  • productId

  • productName

  • productBrand

  • Gender

  • Price

  • Description

  • Primary Color

There are two ways to obtain the data.

  1. Download the data directly from the site. The platform we will be using to download the data is Kaggle, which hosts a variety of datasets for data analysis competitions. Among these, the dataset we will use can be found at the URL below:Fashion Clothing Products Dataset There is a detailed description of the dataset on the site, along with various insightful materials. Please refer to them for more information!

  2. Using code. Kaggle provides a api, which allows us to download datasets available on Kaggle very easily.

We will use the second method.

To download the dataset, first log in to Kaggle, then click on your profile picture in the top right corner and select 'Settings' from the menu that appears.

service graphKaggle Menu

Below 'Settings,' there is an 'API' section where you need to click Create New Token.

service graphKaggle Settings

Then, a file named kaggle.json will be created. Using this json file, you can authenticate the API and utilize the Kaggle API.

Once you move the file to the .kaggle folder, you will be ready to use the API. The path is as follows.

  • mac : ~/.kaggle

  • windows : C:/User/{username}/.kaggle

[Note] : How to Use Kaggle

The data is ready, so we need a database to store it. We will use PostgreSQL. Refer to the code below to set up a PostgreSQL database using a Docker container.

However, instead of just PostgreSQL, we plan to use an image of pgvector, which allows for vector data types in PostgreSQL.

Now that the database is up and running, let's insert our prepared data into the DB!

The database preparation is now complete! So, how should we insert the data into the database for our service? In our tutorial, we plan to implement only very simple features, so we have also designed the ERD in a simple way, as shown below.

ERDOur shopping mall service ERD

Noteworthy in the data configuration is description_ebd of inventory. This is the reason why we use pgvector. This data is used when recommending items. When a user inputs what kind of item they want, it compares the features of the item described by the user with description_ebd using COSINE distance and recommends the item with the highest similarity.

In short, a Semantic Search is conducted.

[NOTE] pgvector github

Let's load dummy data for buyers and sellers.

Creating fictional characters one by one could be one way, but... Since we have a reliable tool called GPT, let's actively utilize it!

Let's create 10 dummy data entries each for buyers and sellers.

This concludes the preparation of buyer and seller data!

Next, let's load information about the items that the seller will sell into a table called inventory!

Here, we are going to do something a bit interesting... We will be giving character to our dummy data!

Once character is given, we expect to see unique and lively product descriptions! Doesn't it sound fun? Let's create it together!

Shall we check the personalities of our buyers?

Quite unique and colorful sellers have been created! I look forward to seeing how these unique sellers create product descriptions.

Now all the data preparation is complete! Let's officially start building the service!

Define State

Define Tools

Let's define a tool for administrators.

The tasks that administrators can perform are straightforward:

  • Verify whether the login is valid or not.

Once the validity is determined, they can call an expert.

The obtained user information will be stored in the config and can be utilized throughout the service usage.

Once the user is verified as valid, the administrator delegates the task to the expert.

Let's define tools for sales experts.

As mentioned in the overview, sales experts can perform the following four tasks:

  1. Recommend products

  2. Purchase products

  3. Cancel purchases

  4. Check product status

Next, let's define the tools of a purchasing expert.

A purchasing expert can perform the following three tasks:

  1. Checking sales records

  2. Replenishing stock

  3. Updating product conditions

The Sales Expert and Purchase Expert will define a common tool called CompleteOrEscalate. This tool will check whether the current user has completed their task, wants to cancel their task, or has changed their mind about the current task. If the task is finished, it will proceed to return to the administrator.

Define Nodes

Since all the tools have been defined, we need to define the agents that will use these tools!

  • Administrator Agent

  • Purchase Expert Agent

  • Sales Expert Agent We will define these three types of agents.

Let's define the nodes necessary for these agents.

Build the Graph

png

Let's run our service

With this, our shopping mall system is now complete. Although it is, in fact, almost incomplete. And I realized while making this tutorial that the example I created was not very suitable for applying the concept of multi-agent.

Still, I believe you were able to grasp the concept of how multi-agents are structured and how they operate by following this tutorial.

By using the concepts you have learned, I believe you will be able to create more suitable and impressive services!

Thank you for your hard work this time as well! Thank you.

Last updated