This repository demonstrates how to build a multi-agent AI system using:
- LangChain for natural language to SQL translation.
- AutoGen for coordinating AI agents in collaborative workflows.
- Azure OpenAI GPT-4 for intelligent language understanding and generation of SQL queries in PostgreSQL.
- Azure Database for PostgreSQL for data storage and querying.
The application showcases a shipping company where agents manage shipments, customers and product informations. The main goal of this repository is to illustrate how easy it is to have agents not just reading data but also acting on them. It extends the "Chat With Your Data" to "Chat and Act on Your Data". ** We welcome contributions to help make those agents more reliable and under guardrails. Feel free to contribute to more agents as well! **
- 🌐 Gradio UI: User-friendly interface for natural language interactions.
- 🤖 AutoGen Multi-Agent System: Agents collaborate to handle specific tasks:
- SchemaAgent: Manages database schema retrieval and sharing.
- ShipmentAgent: Handles shipment-related queries and updates. It can use the stored procedure send_shipment to create shipments.
- CRMAgent: Manages customer and product-related data. It can use the stored procedure add_customer to create new customers.
- 🧠 Azure OpenAI GPT-4: Generates SQL queries and natural language responses.
- 🛢️ Azure PostgreSQL: Stores shipment, customer, and product data.
- Python 3.9+ and <3.13
- An Azure account with:
- Azure OpenAI Service (GPT-4 deployed). Note: I am looking to see how we can use other GPT models but they keep adding ``` sql which returns an error
- Azure Database for PostgreSQL (configured with necessary tables).
- Environment setup:
python-dotenv
for environment variables.- PostgreSQL client library (
psycopg2
or similar).
git clone https://github.com/Azure-Samples/azure-postgresql-openai-langchain-autogen-demo.git
cd azure-postgresql-openai-langchain-autogen-demo
- Use the file SQL_Queries.sql to set your database.
Create a .env file in the root directory to store sensitive credentials. Use the following template:
# Azure OpenAI
AZURE_OPENAI_KEY=your_openai_api_key
AZURE_OPENAI_ENDPOINT=https://your-openai-endpoint
AZURE_OPENAI_DEPLOYMENT=gpt-4
# PostgreSQL Database
POSTGRES_USER=your_username
POSTGRES_PASSWORD=your_password
POSTGRES_HOST=your_postgresql_host
POSTGRES_PORT=5432
POSTGRES_DB=your_database_name
Replace the placeholder values with your actual credentials. The Jupyter Notebook is configured with .env been located in the same root folder in my machine.
If you use Google Collab and you want to upload .env file, you will have to add the following code:
from google.colab import files
files.upload() # Upload your .env file
- I recommend using Jupyter Notebook in VS Code
- You should create a virtual environment to avoid any library conflicts:
-
Go to your root folder where you have cloned the files
-
Create a virtual environment named
.venv
in your current directory:python3 -m venv .venv
-
Activate:
a. On Windows:
.venv\Scripts\activate
b. On Mac/Linux:
source .venv/bin/activate
-
Install the Requirement File:
pip install -r requirements.txt
-
- Which products with names are currently tracking in transit?
- Is Alice Johnson a Customer?
- I would like to create a stored Procedure to delete customers. What would be the best way to do this?
- Can you add Marc with email address [email protected], phone number +1 123 456 7890 and address in 1 Main Street, Redmond?
- Can you add Marc with email address [email protected], phone number +1 123 456 7890? Note: the information is incomplete and the agents should not perfom an operation
- Can you create a new shipment of 1 Laptop and 1 Smartphone to Marc and ensure shipment is updated to Departed Origin from the location in New York and towards Los Angeles date is today?