今天我们不写一行代码,通过 n8n 搭建一个真正“聪明”的 AI 助手。
很多初学者用 AI 时会发现:它记不住名字!你上一句告诉它“我是小明”,下一句问它“我是谁”,它就懵了。
本教程的目标:教你用 n8n 的 AI Agent 节点,配合 Memory(记忆)模块,打造一个能记住上下文的专属聊天机器人。
在开始之前,只需理解一个简单的区别:
在 n8n 中,我们就是用 AI Agent 节点把这些能力组装起来。
任何自动化都需要一个“触发器”。
+ (Add first step)。这是本教程的核心。
+ 号。AI Agent 需要一个大脑来思考。
Chat Model 的插槽,点击 +。Credential (凭证)。将你的 API Key 填入即可。gpt-4o-mini,便宜且速度快。想让你的 AI 变成“暴躁程序员”还是“温柔心理师”?
Options。Add Option -> 选择 System Message。为了让它记住你是谁:
Memory 插槽。+ 号,搜索 Window Buffer Memory (简单记忆)。我为你准备了完整的 JSON 代码。复制下面的代码,在 n8n 画布上按 Ctrl+V (或 Cmd+V) 即可直接导入,配置好你的 API Key 就能跑!
{
"name": "Basic AI Chat with Memory",
"nodes": [
{
"parameters": {},
"id": "1",
"name": "When chat message received",
"type": "n8n-nodes-base.chatTrigger",
"typeVersion": 1.1,
"position": [
460,
340
],
"webhookId": "b1f8c7a2-1234-4567-8901-abcdef123456"
},
{
"parameters": {
"options": {
"systemMessage": "You are a helpful assistant with a great memory."
}
},
"id": "2",
"name": "AI Agent",
"type": "n8n-nodes-base.aiAgent",
"typeVersion": 1,
"position": [
680,
340
]
},
{
"parameters": {
"model": "gpt-4o-mini",
"options": {}
},
"id": "3",
"name": "OpenAI Chat Model",
"type": "n8n-nodes-base.openAiChatModel",
"typeVersion": 1,
"position": [
680,
540
],
"credentials": {
"openAiApi": {
"id": "YOUR_CREDENTIAL_ID_HERE",
"name": "OpenAI account"
}
}
},
{
"parameters": {
"contextWindowLength": 10
},
"id": "4",
"name": "Window Buffer Memory",
"type": "n8n-nodes-base.memoryBufferWindow",
"typeVersion": 1,
"position": [
800,
540
]
}
],
"connections": {
"When chat message received": {
"main": [
[
{
"node": "AI Agent",
"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
}
]
]
}
}
}[1] 官方文档: https://docs.n8n.io/advanced-ai/intro-tutorial/
[2] n8n系列教程: https://www.undsky.com/blog/?category=n8n%E6%95%99%E7%A8%8B#