Skip to content

a1mp33100Block/multi-agent-spring-ai

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Multi-agent Java sample with Spring AI and Azure Cosmos DB

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 ChatMemory interface 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" tenantId is used, and the user's local IP address is captured as the userId.
  • 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.

UI demo

Demo

Overview

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.

  1. Product Agent: Answers customer queries from the products container using Retrieval Augmented Generation (RAG).
  2. Refund Agent: Manages customer refunds, requiring both user ID and item ID to initiate a refund.
  3. Sales Agent: Handles actions related to placing orders, requiring both user ID and product ID to complete a purchase.

Prerequisites

Setup

Clone the repository:

git clone https://github.com/AzureCosmosDB/multi-agent-spring-ai.git
cd multi-agent-spring-ai

Ensure you have the following environment variables set:

AZURE_COSMOSDB_ENDPOINT=your_cosmosdb_account_uri
AZURE_OPENAI_ENDPOINT=your_azure_openai_endpoint

Ensure that your Azure OpenAI account has the following models deployed (references in application.properties):

  • gpt-4o-mini for chat
  • text-embedding-ada-002 for embeddings

Running the app

Authenticate

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 login

Compile

mvn clean package

Start the web server

java -jar target/multi-agent-spring-ai-cosmos-1.0-exec.jar

Swagger UI

http://localhost:8080/swagger-ui/index.html

Load the data

java -jar target/multiagent-dataloader.jar

Test via CLI

java -jar target/multiagent-cli.jar

Test via UI

http://localhost:8080

About

A sample for multi-agent orchestration in Java using Azure Cosmos DB with Spring AI

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Java 81.6%
  • JavaScript 8.1%
  • CSS 6.8%
  • HTML 3.5%