AI Agents

Translate questions about emails into queries and run them

26 nodes 241 137 Automatic trigger
Download

Workflow Description

An intelligent agent converts natural language questions about emails into SQL queries, executes them on PostgreSQL, and exports results to files or social media channels. Powered by Ollama for language understanding and logical query construction.

How it works

  1. 1.Receive user question through chat trigger or manual input
  2. 2.Process text with Ollama LM to extract intent and parameters
  3. 3.Translate question to SQL query and execute on PostgreSQL database
  4. 4.Filter and format results into readable structured data
  5. 5.Save processed data as CSV or JSON files
  6. 6.Share results via Twitter/X or send to user

Use cases

  • Search stored emails with natural language questions without writing SQL
  • Generate automated reports and analytics from email database
  • Build an intelligent email assistant for non-technical users

Requirements

  • PostgreSQL database with email data tables and proper schema
  • Ollama language model installed and configured for local inference
  • File read/write permissions for CSV and JSON export
  • Twitter/X API credentials if social sharing is enabled

Service Value

Ready-made workflow template for automation delivery and service execution.

Apps Used

Read Write File Chat Trigger Postgres Lm Chat Ollama Twitter/X AI Agent

Details

Trigger Automatic trigger
Nodes 26
Apps 6
Views 241
Downloads 137

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

/

Add table name to output

Set

#1

Convert data to binary

Convert To File

#2

Save file locally

Read Write File

#3

Extract data from file

Extract From File

#4

Chat Trigger

Chat Trigger

#5

Sticky Note

Sticky Note

#6

When clicking "Test workflow"

Manual Trigger

#7

Combine schema data and chat input

Set

#8

Load the schema from the local file

Read Write File

#9

Extract SQL query

Set

#10

Check if query exists

If

#11

Format query results

Set

#12

Combine query result and chat answer

Merge

#13

List all columns in a table

Postgres

#14

List all tables in a database

Postgres

#15

Ollama Chat Model

Lm Chat Ollama

#16

Postgres

Postgres

#17

Add trailing semicolon

Set

#18

Check for trailing semicolon

If

#19

WorkflowTrigger

Execute Workflow Trigger

#20

If ran manually

If

#21

If file exists or already retried generating it

If

#22

Sticky Note1

Sticky Note

#23

AI Agent

Agent

#24

Format empty output

Set

#25

Sticky Note2

Sticky Note

#26