带记忆功能的SQL代理
中级
这是一个AI领域的自动化工作流,包含 13 个节点。主要使用 Set, Compression, HttpRequest, ManualTrigger, ReadWriteFile 等节点,结合人工智能技术实现智能自动化。 使用LangChain AI代理与您的SQLite数据库对话 🧠💬
前置要求
- •可能需要目标 API 的认证凭证
- •OpenAI API Key
使用的节点 (13)
分类
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
"id": "AQJ6QnF2yVdCWMnx",
"meta": {
"instanceId": "fb924c73af8f703905bc09c9ee8076f48c17b596ed05b18c0ff86915ef8a7c4a",
"templateCredsSetupCompleted": true
},
"name": "带记忆功能的 SQL 代理",
"tags": [],
"nodes": [
{
"id": "3544950e-4d8e-46ca-8f56-61c152a5cae3",
"name": "窗口缓冲内存",
"type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
"position": [
1220,
500
],
"parameters": {
"contextWindowLength": 10
},
"typeVersion": 1.2
},
{
"id": "743cc4e7-5f24-4adc-b872-7241ee775bd0",
"name": "OpenAI 聊天模型",
"type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
"position": [
1000,
500
],
"parameters": {
"model": "gpt-4-turbo",
"options": {
"temperature": 0.3
}
},
"credentials": {
"openAiApi": {
"id": "rveqdSfp7pCRON1T",
"name": "Ted's Tech Talks OpenAi"
}
},
"typeVersion": 1
},
{
"id": "cc30066c-ad2c-4729-82c1-a6b0f4214dee",
"name": "当点击\"测试工作流\"时",
"type": "n8n-nodes-base.manualTrigger",
"position": [
500,
-80
],
"parameters": {},
"typeVersion": 1
},
{
"id": "0deacd0d-45cb-4738-8da0-9d1251858867",
"name": "获取 chinook.zip 示例",
"type": "n8n-nodes-base.httpRequest",
"position": [
700,
-80
],
"parameters": {
"url": "https://www.sqlitetutorial.net/wp-content/uploads/2018/03/chinook.zip",
"options": {}
},
"typeVersion": 4.2
},
{
"id": "61f34708-f8ed-44a9-8522-6042d28511ae",
"name": "解压 zip 文件",
"type": "n8n-nodes-base.compression",
"position": [
900,
-80
],
"parameters": {},
"typeVersion": 1.1
},
{
"id": "6a12d9ac-f1b7-4267-8b34-58cdb9d347bb",
"name": "本地保存 chinook.db",
"type": "n8n-nodes-base.readWriteFile",
"position": [
1100,
-80
],
"parameters": {
"options": {},
"fileName": "./chinook.db",
"operation": "write",
"dataPropertyName": "file_0"
},
"typeVersion": 1
},
{
"id": "701d1325-4186-4185-886a-3738163db603",
"name": "加载本地 chinook.db",
"type": "n8n-nodes-base.readWriteFile",
"position": [
620,
360
],
"parameters": {
"options": {},
"fileSelector": "./chinook.db"
},
"typeVersion": 1
},
{
"id": "d7b3813d-8180-4ff1-87a4-bd54a03043af",
"name": "便签",
"type": "n8n-nodes-base.stickyNote",
"position": [
440,
-280.9454545454546
],
"parameters": {
"width": 834.3272727272731,
"height": 372.9454545454546,
"content": "## 仅运行此部分一次"
},
"typeVersion": 1
},
{
"id": "6bd25563-2c59-44c2-acf9-407bd28a15cf",
"name": "便签1",
"type": "n8n-nodes-base.stickyNote",
"position": [
400,
240
],
"parameters": {
"width": 558.5454545454544,
"height": 297.89090909090913,
"content": "## 每次聊天消息时:"
},
"typeVersion": 1
},
{
"id": "2be63956-236e-46f7-b8e4-0f55e2e25a5c",
"name": "将聊天输入与二进制数据结合",
"type": "n8n-nodes-base.set",
"position": [
820,
360
],
"parameters": {
"mode": "raw",
"options": {
"includeBinary": true
},
"jsonOutput": "={{ $('Chat Trigger').item.json }}\n"
},
"typeVersion": 3.3
},
{
"id": "7f4c9adb-eab4-40d7-ad2e-44f2c0e3e30a",
"name": "便签2",
"type": "n8n-nodes-base.stickyNote",
"position": [
980,
120
],
"parameters": {
"width": 471.99692219161466,
"height": 511.16641410437836,
"content": "### LangChain SQL 代理在生成最终答案前可能进行多次查询。"
},
"typeVersion": 1
},
{
"id": "ac819eb5-13b2-4280-b9d6-06ec1209700e",
"name": "AI Agent",
"type": "@n8n/n8n-nodes-langchain.agent",
"position": [
1020,
360
],
"parameters": {
"agent": "sqlAgent",
"options": {},
"dataSource": "sqlite"
},
"typeVersion": 1.6
},
{
"id": "5ecaa3eb-e93e-4e41-bbc0-98a8c2b2d463",
"name": "聊天触发器",
"type": "@n8n/n8n-nodes-langchain.chatTrigger",
"position": [
420,
360
],
"webhookId": "fb565f08-a459-4ff9-8249-1ede58599660",
"parameters": {},
"typeVersion": 1
}
],
"active": false,
"pinData": {},
"settings": {
"executionOrder": "v1"
},
"versionId": "fbc06ddd-dbd8-49ee-bbee-2f495d5651a2",
"connections": {
"Chat Trigger": {
"main": [
[
{
"node": "Load local chinook.db",
"type": "main",
"index": 0
}
]
]
},
"Extract zip file": {
"main": [
[
{
"node": "Save chinook.db locally",
"type": "main",
"index": 0
}
]
]
},
"OpenAI Chat Model": {
"ai_languageModel": [
[
{
"node": "AI Agent",
"type": "ai_languageModel",
"index": 0
}
]
]
},
"Window Buffer Memory": {
"ai_memory": [
[
{
"node": "AI Agent",
"type": "ai_memory",
"index": 0
}
]
]
},
"Load local chinook.db": {
"main": [
[
{
"node": "Combine chat input with the binary",
"type": "main",
"index": 0
}
]
]
},
"Get chinook.zip example": {
"main": [
[
{
"node": "Extract zip file",
"type": "main",
"index": 0
}
]
]
},
"When clicking \"Test workflow\"": {
"main": [
[
{
"node": "Get chinook.zip example",
"type": "main",
"index": 0
}
]
]
},
"Combine chat input with the binary": {
"main": [
[
{
"node": "AI Agent",
"type": "main",
"index": 0
}
]
]
}
}
}常见问题
如何使用这个工作流?
复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。
这个工作流适合什么场景?
中级 - 人工智能
需要付费吗?
本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。
相关工作流推荐
仅从数据库架构生成 SQL 查询 - AI 驱动
仅从数据库架构生成 SQL 查询 - AI 驱动
If
Set
Merge
+11
29 节点Yulia
工程
使用Qdrant、Mistral.ai和OpenAI构建税法助手
使用Qdrant、Mistral.ai和OpenAI构建税法助手
Set
Wait
Filter
+18
38 节点Jimleuk
财务
使用正则表达式和 AI 发现隐藏的网站 API 端点
使用正则表达式和人工智能发现隐藏的网站API端点
If
Set
Html
+19
58 节点Yulia
工程
AI智能助手:与Supabase存储和Google Drive文件对话
AI智能助手:与Supabase存储和Google Drive文件对话
If
Set
Wait
+20
62 节点Mark Shcherbakov
工程
在Braze中更新现有邮件模板
使用AI为Instagram、Facebook、LinkedIn和X自动化社交媒体内容
Set
Gmail
Merge
+22
73 节点LukaszB
设计
使用GraphRAG与PDF/MD/文本文件对话(无需向量存储)
使用GraphRAG与PDF/MD/文本文件对话(无需向量存储)
Set
Switch
Google Drive
+10
20 节点InfraNodus
客户支持