Inspired by OpenAI Swarm and LangGraph - 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: the sample implements a custom multi-agent orchestration framework using Spring AI and Azure OpenAI as building blocks.
- Transactional data management: agents interact with the planet scale Azure Cosmos DB database service using Spring AI tool calling to store transactional user and product operational data, implemented via Spring Data.
- Retrieval Augmented Generation (RAG): the sample uses vector search in Azure Cosmos DB with powerful DiskANN index to serve product enquiries from the same database that is used for transactions. Implemented via the Spring AI vector store plugin for Azure Cosmos DB.
- Long term chat memory persistence: the sample implements Spring AI's
ChatMemoryinterface to store and manage long term chat memory for each user session in Azure Cosmos DB. - Multi-tenant/user session storage: Hierarchical Partitioning is used in Azure Cosmos DB to store and manage each user session, this is integrated into the UI. A "default"
tenantIdis used, and the user's local IP address is captured as theuserId. - UI: front end is built as a single-page application (SPA) using HTML, CSS, and JavaScript located in the resources/static folder. The UI talks to REST API endpoints exposed by the backend Spring Boot application.
The personal shopper example includes 3 agents to handle various customer service requests, and an orchestrator for initial routing. The agents are implemented using Spring AI to interact with the Azure OpenAI API. The agents are designed to be modular and can be easily extended or replaced with other implementations.
- 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 account.
- Azure OpenAI Embedding Deployment for the RAG model of
text-embedding-ada-002(with deployment ID of the same). - Azure OpenAI Chat Deployment for the chat model of
gpt-4o-mini(with deployment ID of the same). - Maven 3.8.1 or later installed.
- Java 17 or later installed.
Clone the repository:
git clone https://github.com/AzureCosmosDB/multi-agent-spring-ai.git
cd multi-agent-spring-aiEnsure you have the following environment variables set:
AZURE_COSMOSDB_ENDPOINT=your_cosmosdb_account_uri
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpointEnsure that your Azure OpenAI account has the following models deployed (references in application.properties):
gpt-4o-minifor chattext-embedding-ada-002for embeddings
The sample uses DefaultAzureCredential when connecting to both Azure OpenAI and Azure Cosmos DB. Be sure you have appropriate data plane RBAC access to your Azure Cosmos DB account and for your Azure OpenAI account, then authenticate to Azure locally:
az loginmvn clean packagejava -jar target/multi-agent-spring-ai-cosmos-1.0-exec.jarhttp://localhost:8080/swagger-ui/index.html
java -jar target/multiagent-dataloader.jarjava -jar target/multiagent-cli.jar