Skip to content
AI Agents

AI SQL Agent Chat Querying a Postgres Database

5 nodes 43 4 Manual trigger
Download

Loading workflow…

Workflow Description

A chat-driven workflow where a Chat Trigger passes the user's chatInput to an AI Agent configured as an sqlAgent with a Postgres data source. An OpenAI Chat Model node supplies gpt-4 as the language model, enabling natural-language questions to be answered as SQL queries against the connected database.

How it works

  1. 1.Chat Trigger receives the user's message from the chat panel.
  2. 2.The message text (chatInput) is passed as the agent's input.
  3. 3.The AI Agent runs in sqlAgent mode with Postgres set as its data source.
  4. 4.The OpenAI Chat Model node (gpt-4) connects to the agent as its language model.

Use cases

  • Ask which tables exist in a Postgres database via plain language.
  • Let non-technical users explore database contents through chat.

Requirements

  • A valid OpenAI API credential in n8n with access to gpt-4.
  • A configured Postgres credential attached to the agent's data source.
  • n8n instance with LangChain nodes (chat trigger, agent, LM) installed.

Setup and testing in n8n

  1. Open the workflow in n8n and click the chat button at the bottom of the canvas.
  2. Paste a question such as 'Which tables are available?'
  3. Verify the agent responds after OpenAI and Postgres connections resolve.

Service Value

Ideal as a smart automation service combining integrations and AI to produce ready-to-use results.

Apps Used

OpenAI AI Agent Chat Trigger

Details

Trigger Manual trigger
Nodes 5
Apps 3
Views 43
Downloads 4

How to Use

  1. 1.Click "Download Template"
  2. 2.Open your n8n dashboard
  3. 3.Go to Workflows > Import from File
  4. 4.Select downloaded file and configure credentials

Nodes Used (5)

OpenAI Chat Model

OpenAI

#1

AI Agent

Agent

#2

Chat Trigger

Chat Trigger

#3

Sticky Note

Sticky Note

#4

Sticky Note1

Sticky Note

#5

Source and license

Sticky Note

#6
Stay in the loop

Fresh workflows, straight to your inbox

Get newly published DROPIDEA workflows, a clear overview of what they do, and a link to explore them.

  • New workflows
  • Clear overviews
  • Setup guides

Be first to discover what is new

Your name, your email, and one confirmation.

Email confirmation · Unsubscribe anytime