与Supabase-PostgreSQL数据库对话的AI智能体
中级
这是一个Engineering, DevOps, Product, AI领域的自动化工作流,包含 11 个节点。主要使用 PostgresTool, Agent, ToolCode, ChatTrigger, LmChatOpenAi 等节点,结合人工智能技术实现智能自动化。 用于与Supabase/PostgreSQL数据库对话的AI智能体
前置要求
- •PostgreSQL 数据库连接信息
- •OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"nodes": [
{
"id": "0a4e65b7-39be-44eb-8c66-913ebfe8a87a",
"name": "便签3",
"type": "n8n-nodes-base.stickyNote",
"position": [
1140,
840
],
"parameters": {
"color": 3,
"width": 215,
"height": 80,
"content": "**替换 Supabase 的密码和用户名**"
},
"typeVersion": 1
},
{
"id": "2cea21fc-f3fe-47b7-a7b6-12acb0bc03ac",
"name": "便签5",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
320
],
"parameters": {
"color": 7,
"width": 280.2462120317618,
"height": 545.9087885077763,
"content": "### 设置步骤"
},
"typeVersion": 1
},
{
"id": "eacc0c8c-11d5-44fb-8ff1-10533a233693",
"name": "便签6",
"type": "n8n-nodes-base.stickyNote",
"position": [
-160,
-200
],
"parameters": {
"color": 7,
"width": 636.2128494576581,
"height": 497.1532689930921,
"content": ""
},
"typeVersion": 1
},
{
"id": "be1559ea-1f75-4e7c-9bdd-3add8d8be70b",
"name": "便签7",
"type": "n8n-nodes-base.stickyNote",
"position": [
140,
320
],
"parameters": {
"color": 7,
"width": 330.5152611046425,
"height": 239.5888196628349,
"content": "### ... 或观看设置视频 [20 分钟]"
},
"typeVersion": 1
},
{
"id": "4ea87754-dead-49ea-848c-ed86c98e217b",
"name": "当收到聊天消息时",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
720,
400
],
"webhookId": "6e95bc27-99a6-417c-8bf7-2831d7f7a4be",
"parameters": {
"options": {}
},
"typeVersion": 1.1
},
{
"id": "c20d6e57-eb41-4682-a7f5-5bb4323df476",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
760,
680
],
"parameters": {
"options": {}
},
"credentials": {
"openAiApi": {
"id": "zJhr5piyEwVnWtaI",
"name": "OpenAi club"
}
},
"typeVersion": 1
},
{
"id": "8d3b1faf-643c-4070-996d-a59cb06e1827",
"name": "数据库模式",
"type": "n8n-nodes-base.postgresTool",
"position": [
1180,
660
],
"parameters": {
"query": "SELECT table_schema, table_name\nFROM information_schema.tables\nWHERE table_type = 'BASE TABLE' AND table_schema = 'public';",
"options": {},
"operation": "executeQuery",
"descriptionType": "manual",
"toolDescription": "Get list of all tables in database"
},
"credentials": {
"postgres": {
"id": "AO9cER6p8uX7V07T",
"name": "Postgres 5minai"
}
},
"typeVersion": 2.5
},
{
"id": "d9346ade-79d1-44c2-8fa6-b337ad8b0544",
"name": "获取表定义",
"type": "n8n-nodes-base.postgresTool",
"position": [
1340,
660
],
"parameters": {
"query": "SELECT \n c.column_name,\n c.data_type,\n c.is_nullable,\n c.column_default,\n tc.constraint_type,\n ccu.table_name AS referenced_table,\n ccu.column_name AS referenced_column\nFROM \n information_schema.columns c\nLEFT JOIN \n information_schema.key_column_usage kcu \n ON c.table_name = kcu.table_name \n AND c.column_name = kcu.column_name\nLEFT JOIN \n information_schema.table_constraints tc \n ON kcu.constraint_name = tc.constraint_name\n AND tc.constraint_type = 'FOREIGN KEY'\nLEFT JOIN\n information_schema.constraint_column_usage ccu\n ON tc.constraint_name = ccu.constraint_name\nWHERE \n c.table_name = '{{ $fromAI(\"table_name\") }}' -- Your table name\n AND c.table_schema = 'public' -- Ensure it's in the right schema\nORDER BY \n c.ordinal_position;\n",
"options": {},
"operation": "executeQuery",
"descriptionType": "manual",
"toolDescription": "Get table definition to find all columns and types."
},
"credentials": {
"postgres": {
"id": "AO9cER6p8uX7V07T",
"name": "Postgres 5minai"
}
},
"typeVersion": 2.5
},
{
"id": "b88a21e0-d2ff-4431-bd84-dfd43edeb5c4",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
960,
280
],
"parameters": {
"width": 215,
"height": 80,
"content": "**微调助手的提示词**"
},
"typeVersion": 1
},
{
"id": "fbe9eb68-5990-485c-820f-08234ea33194",
"name": "AI 智能体",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
940,
400
],
"parameters": {
"text": "={{ $('When chat message received').item.json.chatInput }}",
"agent": "openAiFunctionsAgent",
"options": {
"systemMessage": "You are DB assistant. You need to run queries in DB aligned with user requests.\n\nRun custom SQL query to aggregate data and response to user.\n\nFetch all data to analyse it for response if needed.\n"
},
"promptType": "define"
},
"typeVersion": 1.6
},
{
"id": "7f82d6d9-d7d6-4443-bbaa-c9b276a376e3",
"name": "运行 SQL 查询",
"type": "n8n-nodes-base.postgresTool",
"position": [
1040,
660
],
"parameters": {
"query": "{{ $fromAI(\"query\",\"SQL query for PostgreSQL DB in Supabase\") }}",
"options": {},
"operation": "executeQuery",
"descriptionType": "manual",
"toolDescription": "Run custom SQL queries using knowledge about Output structure to provide needed response for user request.\nUse ->> operator to extract JSON data."
},
"credentials": {
"postgres": {
"id": "AO9cER6p8uX7V07T",
"name": "Postgres 5minai"
}
},
"typeVersion": 2.5
}
],
"pinData": {},
"connections": {
"DB Schema": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"Run SQL Query": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Get table definition": {
"ai_tool": [
[
{
"node": "AI Agent",
"type": "ai_tool",
"index": 0
}
]
]
},
"When chat message received": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 工程, 开发运维, 产品, 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
与Supabase存储中文件对话的AI智能体
与Supabase存储中文件对话的AI智能体
If
Merge
Switch
+15
33 节点Mark Shcherbakov
工程
AI智能助手与Airtable对话及数据分析
AI智能助手与Airtable对话及数据分析
If
Set
Merge
+12
41 节点Mark Shcherbakov
工程
数据分析师 Agent v3
用于电子表格的AI数据分析助手,基于NocoDB平台
Set
Noco Db Tool
Http Request
+5
10 节点Derek Cheung
工程
仅从数据库架构生成 SQL 查询 - AI 驱动
仅从数据库架构生成 SQL 查询 - AI 驱动
If
Set
Merge
+11
29 节点Yulia
工程
AI智能助手:与Supabase存储和Google Drive文件对话
AI智能助手:与Supabase存储和Google Drive文件对话
If
Set
Wait
+20
62 节点Mark Shcherbakov
工程
与PostgreSQL数据库对话
与PostgreSQL数据库对话
Postgres Tool
Agent
Chat Trigger
+3
11 节点KumoHQ
工程
工作流信息
难度等级
中级
节点数量11
分类4
节点类型6
作者
Mark Shcherbakov
@lowcodingdevI am a business analyst with a development background, dedicated to helping small businesses and entrepreneurs leverage cloud services for increased efficiency. My expertise lies in automating manual workflows, integrating data from multiple cloud service providers, creating insightful dashboards, and building custom CRM systems.
外部链接
在 n8n.io 查看 →
分享此工作流