8
n8n 中文网amn8n.com

带记忆功能的SQL代理

中级

这是一个AI领域的自动化工作流,包含 13 个节点。主要使用 Set, Compression, HttpRequest, ManualTrigger, ReadWriteFile 等节点,结合人工智能技术实现智能自动化。 使用LangChain AI代理与您的SQLite数据库对话 🧠💬

前置要求
  • 可能需要目标 API 的认证凭证
  • OpenAI API Key
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 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)可能需要您自行付费。

工作流信息
难度等级
中级
节点数量13
分类1
节点类型10
难度说明

适合有一定经验的用户,包含 6-15 个节点的中等复杂度工作流

作者
外部链接
在 n8n.io 查看

分享此工作流