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.7+
- 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/arno756/multi-ai-agents-with-postgresql.git
cd multi-ai-agents-with-postgresql
- 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
- Which products with names are currently tracking in transit?
- Is Alice Johnson a Customer?
- I would like to create a stored orodcedure 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?