How it works
Agents and Workflow We initialize the context variables with two fields:user_info to store user information (and order list when a user logs in) and order_info to store the retrieved order information. Since swarm is a decentralized orchestration, we will transfer logic in each agent:
- Order Triage Agent: When the user sends a message related to orders, it will be routed to the Order Triage Agent. This agent will further decide whether to transfer to the Tracking Agent or the Login Agent.
-
Tracking Agent:
Helps the user track an order without login. It will first ask the user to provide a tracking number. If the number is valid, it will ask for additional information (email, last name, phone number) to confirm the user’s identity. It can also transfer to the Login Agent if the user needs to manage the orders.
- Tools:
verify_tracking_number: verifies if the tracking number is valid and updates the context variables with the order info if valid.verify_user_information: validates the user’s information and returns the order details if correct.
- Tools:
-
Login Agent:
Prompts the user to log in and checks login status. This agent has a tool
login_accountto initiate a login session for the user. Upon successful login, it updates the context variables with the user’s info and transfers control to the Order Management Agent. If login fails, it can guide the user to try again or help them start the process to find their account or reset their password. Currently, we have a dummy login system that logs in directly without any authentication. -
Order Management Agent:
A general-purpose agent used after the user is logged in. It has access to the user’s entire order history, so it can help the user find past orders through the
get_order_historyorcheck_order_statustool. It can also hand off to a Return Agent for returning orders. -
Return Agent:
Helps the user return an order. It first verifies if the order is eligible for return via the
check_return_eligibilitytool, and then starts the process upon the user’s confirmation withinitiate_return_process. It can transfer back to the Order Management Agent as needed.
Installation
To set up the environment, run the following command:ag2 library.
Running the code
First, set up theconfig_list in the main.py file (line 10). Read more about configurations here.
I want to cancel my orderTR14234- .. Continue to interact with the system ..
I want to track my orderTR138458453(last 4 digits of phone number)- .. Continue to interact with the system ..