This project demonstrates a robust and flexible order management system using decentralized agent orchestration. The system addresses two primary user needs: order tracking and order returns. The workflow considers the userβs login status during the initial interaction. Users can quickly track an order using a tracking number without logging in, while returns require authentication. This system leverages modular agents for triaging, tracking, login management, order management, and returns, ensuring a seamless user experience.
This project demonstrates the following AG2 features:
The system uses a decentralized agent orchestration pattern with the following agent flow:
flowchart TD
A["π€ Customer"] --> B["π― Order Triage Agent"]
%% Agent-level handoffs
B -->|"Track Order"| C["π¦ Tracking Agent"]
B -->|"Manage/Return Order"| D["π Login Agent"]
C -.->|"Need Login"| D
D -->|"β
Login Success"| E["π Order Management Agent"]
E -->|"Return Request"| F["β©οΈ Return Agent"]
F -.->|"Back to Orders"| E
%% GroupChat Pattern
subgraph GROUPCHAT ["π‘ GroupChat Pattern"]
direction LR
G["Shared Context<br/>user_info | order_info"]
H["LLM-Driven<br/>Agent Handoffs"]
end
%% Agent Tools
C --- TC["verify_order_number<br/>verify_user_information"]
D --- TD["login_account"]
E --- TE["get_order_history<br/>check_order_status"]
F --- TF["check_return_eligibility<br/>initiate_return_process"]
%% Styling
classDef agent fill:#e3f2fd,stroke:#1976d2,stroke-width:3px
classDef tools fill:#f1f8e9,stroke:#388e3c,stroke-width:2px
classDef groupchat fill:#fce4ec,stroke:#c2185b,stroke-width:2px
class B,C,D,E,F agent
class TC,TD,TE,TF tools
class G,H groupchat
groupchat
e-commerce
order-management
customer-service
order-tracking
returns-processing
authentication
workflow-automation
agent-orchestration
The system initializes 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 group chat is a decentralized orchestration, the transfer logic is distributed across each agent:
Routes order-related messages to the appropriate agent. Decides whether to transfer to the Tracking Agent or the Login Agent based on user intent.
Enables users to track orders without logging in. First requests a tracking number, then asks for additional verification information (email or phone number) to confirm identity. Can transfer to the Login Agent if order management is needed.
Tools:
verify_tracking_number
- Verifies if the tracking number is valid and updates context variables with order infoverify_user_information
- Validates user information and returns order details if correctHandles user authentication with the login_account
tool. Upon successful login, updates context variables with user info and transfers to the Order Management Agent. Can guide users through retry or account recovery processes. Currently uses a mock login system for demonstration.
Tools:
login_account
- Authenticates user credentials and updates contextGeneral-purpose agent for authenticated users with access to complete order history. Uses get_order_history
and check_order_status
tools to help users find and check past orders. Can transfer to the Return Agent for order returns.
Tools:
get_order_history
- Retrieves complete order history for authenticated userscheck_order_status
- Checks status of specific ordersManages the order return process. Verifies return eligibility with check_return_eligibility
and initiates returns with initiate_return_process
upon user confirmation. Can transfer back to the Order Management Agent as needed.
Tools:
check_return_eligibility
- Verifies if an order is eligible for returninitiate_return_process
- Starts the return process for eligible ordersuv sync
cp .env.example .env
# Edit .env with your API key
The primary dependency is the ag2
library.
uv run python main.py
The system will start running, and you can interact with it through the command line.
Example Interaction 1: Cancel orders
I want to cancel my order
TR14234
Example Interaction 2: Track orders
I want to track my order
TR13845
8453
(last 4 digits of phone number)For more information or any questions, please refer to the documentation or reach out to us!
This project is licensed under the Apache License 2.0. See the LICENSE for details.