AI Agents

Chat with PostgreSQL database

11 nodes 228 129 Automatic trigger
Download

Workflow Description

A template that enables natural language conversations with a PostgreSQL database using an intelligent agent powered by OpenAI. The agent understands user questions and automatically executes database queries while maintaining conversation context and history.

How it works

  1. 1.Receive user message through the chat interface
  2. 2.Process text using OpenAI agent to understand intent and required data
  3. 3.Execute SQL query on PostgreSQL database based on agent understanding
  4. 4.Return results formatted as a natural response to the user
  5. 5.Store conversation in memory for context in subsequent interactions

Use cases

  • Query data and generate reports instantly without writing SQL manually
  • Build a smart chat interface for customers or employees to access company data
  • Analyze complex datasets and answer business questions in natural language

Requirements

  • Active OpenAI account with API key configured
  • PostgreSQL database set up and accessible remotely
  • Read and query permissions on required database tables

Service Value

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

Apps Used

Chat Trigger AI Agent OpenAI Postgres Memory

Details

Trigger Automatic trigger
Nodes 11
Apps 5
Views 228
Downloads 129

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 (11)

/

When chat message received

Chat Trigger

#1

AI Agent

Agent

#2

OpenAI Chat Model

OpenAI

#3

Get Table Definition

Postgres Tool

#4

Sticky Note

Sticky Note

#5

Chat History

Memory Buffer Window

#6

Sticky Note3

Sticky Note

#7

Sticky Note1

Sticky Note

#8

Sticky Note2

Sticky Note

#9

Execute SQL Query

Postgres Tool

#10

Get DB Schema and Tables List

Postgres Tool

#11