File size: 9,355 Bytes
0a84888
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
{
  "name": "Ask a human",
  "nodes": [
    {
      "parameters": {},
      "id": "a60c8572-56c1-4bf3-8352-a6419a475887",
      "name": "Simple Memory",
      "type": "@n8n/n8n-nodes-langchain.memoryBufferWindow",
      "typeVersion": 1.1,
      "position": [
        900,
        760
      ]
    },
    {
      "parameters": {
        "name": "dont_know_tool",
        "description": "Use this tool if you don't know the answer to the user's question, or if you're not very confident about your answer.",
        "workflowId": "={{ $workflow.id}}",
        "fields": {
          "values": [
            {
              "name": "chatInput",
              "stringValue": "={{ $('Chat Trigger').item.json.chatInput }}"
            }
          ]
        }
      },
      "id": "b4f2e26c-903b-46b8-bd8b-110fd64de9e4",
      "name": "Not sure?",
      "type": "@n8n/n8n-nodes-langchain.toolWorkflow",
      "typeVersion": 1,
      "position": [
        1120,
        760
      ]
    },
    {
      "parameters": {},
      "id": "951cc691-b422-4ce6-901f-b7feb3afd1ad",
      "name": "Execute Workflow Trigger",
      "type": "n8n-nodes-base.executeWorkflowTrigger",
      "typeVersion": 1,
      "position": [
        540,
        1360
      ]
    },
    {
      "parameters": {
        "content": "### Sub-workflow: Custom tool\nThe agent above can call this workflow. It checks if the user has supplied an email address. If they haven't it prompts them to provide one. If they have, it messages a customer support channel for help.",
        "height": 775.3931210698682,
        "width": 1118.3459011229047,
        "color": 7
      },
      "id": "194ba9c0-e256-449a-8da7-ac5339123a99",
      "name": "Sticky Note1",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        1020
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "### Main workflow: AI agent using custom tool",
        "height": 486.5625,
        "width": 927.5,
        "color": 7
      },
      "id": "38c6b363-45a7-4e72-9e40-8c0df3cc480f",
      "name": "Sticky Note2",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        500,
        460
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**This tool calls the sub-workflow below**",
        "height": 179.21380662202682,
        "width": 197.45572294791873,
        "color": 5
      },
      "id": "0389315b-e48d-4b00-b9a1-899302b1b094",
      "name": "Sticky Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        1060,
        700
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "**Set your credentials**",
        "height": 213.44323866265472,
        "width": 150,
        "color": 2
      },
      "id": "fb11064a-4cf5-4110-9e39-af24a3225164",
      "name": "Sticky Note5",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        700,
        680
      ]
    },
    {
      "parameters": {
        "content": "**Set your credentials and Slack details**",
        "height": 250.57252651663197,
        "width": 178.0499248677781,
        "color": 2
      },
      "id": "d689021d-0a46-4dff-a01a-0b01ecdd198b",
      "name": "Sticky Note4",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1020,
        1180
      ]
    },
    {
      "parameters": {
        "content": "## Try it out\n\nSelect **Chat** at the bottom and enter:\n\n_Hi! Please respond to this as if you don't know the answer to my query._",
        "height": 214.8397420554627,
        "width": 185.9375,
        "color": 4
      },
      "id": "0926cd61-c0b8-4bae-ae65-9afd130d17cd",
      "name": "Sticky Note3",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        340,
        520
      ],
      "typeVersion": 1
    },
    {
      "parameters": {
        "content": "## Next steps\n\nLearn more about [Advanced AI in n8n](https://docs.n8n.io/advanced-ai/)",
        "height": 144.50520156238127
      },
      "id": "cde69dfe-252e-4a05-8d56-fa79431df5d8",
      "name": "Sticky Note6",
      "type": "n8n-nodes-base.stickyNote",
      "typeVersion": 1,
      "position": [
        1580,
        1600
      ]
    },
    {
      "parameters": {},
      "id": "927b775a-47f6-4067-a1a5-5f13dea28e45",
      "name": "Chat Trigger",
      "type": "@n8n/n8n-nodes-langchain.chatTrigger",
      "typeVersion": 1,
      "position": [
        600,
        520
      ],
      "webhookId": "785e0c0c-12e5-4249-9abe-47bb131975cb"
    },
    {
      "parameters": {
        "jsCode": "response = {\"response\":\"I'm sorry I don't know the answer. Please repeat your question and include your email address so I can request help.\"};\nreturn response;"
      },
      "id": "971e7b90-c2d8-4292-9da8-732d7d399f04",
      "name": "Prompt the user to provide an email",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1060,
        1520
      ]
    },
    {
      "parameters": {
        "jsCode": "response = {\"response\": \"Thank you for getting in touch. I've messaged a human to help.\"}\nreturn response;"
      },
      "id": "6f5a21b3-c145-46c8-8e69-660100c4a6fc",
      "name": "Confirm that we've messaged a human",
      "type": "n8n-nodes-base.code",
      "typeVersion": 2,
      "position": [
        1300,
        1260
      ]
    },
    {
      "parameters": {
        "options": {
          "systemMessage": "Try to answer the user's question. When you can't answer, or you're not confident of the answer, use the appropriate tool. When you use the dont_know_tool, respond with the message from the tool."
        }
      },
      "id": "8b17da5e-e392-4028-91b0-bc02d34e46ed",
      "name": "AI Agent",
      "type": "@n8n/n8n-nodes-langchain.agent",
      "typeVersion": 1.2,
      "position": [
        820,
        520
      ]
    },
    {
      "parameters": {
        "conditions": {
          "options": {
            "caseSensitive": true,
            "leftValue": "",
            "typeValidation": "strict"
          },
          "conditions": [
            {
              "id": "5e21e7c5-db60-4111-bb17-c289ae0fc159",
              "leftValue": "={{ $('Execute Workflow Trigger').item.json.chatInput }}",
              "rightValue": "/([a-zA-Z0-9._-]+@[a-zA-Z0-9._-]+\\.[a-zA-Z0-9_-]+)/gi",
              "operator": {
                "type": "string",
                "operation": "regex"
              }
            }
          ],
          "combinator": "and"
        },
        "options": {}
      },
      "id": "990ecd3b-6aa0-4b17-8d01-d606b9164fa8",
      "name": "Check if user has provided email",
      "type": "n8n-nodes-base.if",
      "typeVersion": 2,
      "position": [
        760,
        1360
      ]
    },
    {
      "parameters": {
        "select": "channel",
        "channelId": {
          "__rl": true,
          "value": "",
          "mode": "name"
        },
        "text": "={{ \"A user had a question the bot couldn't answer. Here's their message: \" + $('Execute Workflow Trigger').item.json.chatInput }}",
        "otherOptions": {}
      },
      "id": "d14da0ae-06ca-422b-b5b6-e7759e74c787",
      "name": "Message Slack for help",
      "type": "n8n-nodes-base.slack",
      "typeVersion": 2.1,
      "position": [
        1060,
        1260
      ]
    },
    {
      "parameters": {
        "model": "gpt-4",
        "options": {
          "temperature": 0.2
        }
      },
      "id": "278391c7-6945-495e-a4f1-74fb8fcc3549",
      "name": "GPT4",
      "type": "@n8n/n8n-nodes-langchain.lmChatOpenAi",
      "typeVersion": 1,
      "position": [
        740,
        740
      ]
    }
  ],
  "pinData": {},
  "connections": {
    "Simple Memory": {
      "ai_memory": [
        [
          {
            "node": "AI Agent",
            "type": "ai_memory",
            "index": 0
          }
        ]
      ]
    },
    "Not sure?": {
      "ai_tool": [
        [
          {
            "node": "AI Agent",
            "type": "ai_tool",
            "index": 0
          }
        ]
      ]
    },
    "Execute Workflow Trigger": {
      "main": [
        [
          {
            "node": "Check if user has provided email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Chat Trigger": {
      "main": [
        [
          {
            "node": "AI Agent",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Check if user has provided email": {
      "main": [
        [
          {
            "node": "Message Slack for help",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Prompt the user to provide an email",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Message Slack for help": {
      "main": [
        [
          {
            "node": "Confirm that we've messaged a human",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GPT4": {
      "ai_languageModel": [
        [
          {
            "node": "AI Agent",
            "type": "ai_languageModel",
            "index": 0
          }
        ]
      ]
    }
  }
}