A sample personal shopping AI Chatbot that can help with product enquiries, making sales, and refunding orders by transferring to different agents for those tasks.
Features:
- Multi-agent: LangGraph to orchestrate multi-agent interactions with Azure OpenAI API calls.
- Transactional data management: planet scale Azure Cosmos DB database service to store transactional user and product operational data.
- Persistent Memory: save chat memory and agent state using the native LangGraph checkpoint implementation for Azure Cosmos DB.
- Multi-tenant session storage: Hierarchical Partitioning is used to manage each user session (this can be adapted for multi-tenancy).
- Retrieval Augmented Generation (RAG): vector search in Azure Cosmos DB with powerful DiskANN index to serve product enquiries from the same database.
- Gradio UI: Gradio to provide a simple UI ChatBot for the end-user.
Run as an interactive session to see the agent handoffs in action...
Run the AI chat bot for the end-user experience...
The personal shopper example includes four main agents to handle various customer service requests:
- Triage Agent: Determines the type of request and transfers to the appropriate agent.
- Product Agent: Answers customer queries from the products container using Retrieval Augmented Generation (RAG).
- Refund Agent: Manages customer refunds, requiring both user ID and item ID to initiate a refund.
- Sales Agent: Handles actions related to placing orders, requiring both user ID and product ID to complete a purchase.
- Azure Cosmos DB account - ensure the vector search feature is enabled.
- Azure OpenAI API key and endpoint.
- Azure OpenAI Embedding Deployment ID for the RAG model.
Clone the repository:
git clone https://github.com/AzureCosmosDB/multi-agent-langgraph
cd multi-agent-langgraph
Install dependencies:
pip install -r src/app/requirements.txt
Ensure you have the following environment variables set:
COSMOSDB_ENDPOINT=your_cosmosdb_account_uri
COSMOSDB_KEY=your_cosmosdb_account_key
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint
AZURE_OPENAI_EMBEDDINGDEPLOYMENTID=your_azure_openai_embeddingdeploymentid
Once you have installed dependencies, run azure_cosmos_db.py to create the required Cosmos DB containers and load the sample data. Note: Ensure that you have enabled both vector search capability in your Cosmos DB account. Please wait at least 10 minutes after enabling this feature before running the sample code. Note: The Products container is initially created with 10000 RUs for faster loading of 1000 products. If you are using a free tier account, you may need to reduce the RUs to avoid exceeding the free tier limit. You can also reduce the RUs after the initial data load to avoid excessive charges.
python src/app/azure_cosmos_db.py
Then run the chat bot code below and click on url provided in the output:
python src/app/ai_chat_bot.py
To see the agent transfers, you can also run as an interactive CLI session using:
python3 src/app/multi_agent_service.py