1 00:00:00,06 --> 00:00:02,00 - [Instructor] Let's start building our first 2 00:00:02,00 --> 00:00:04,01 AI agent inside n8n. 3 00:00:04,01 --> 00:00:07,07 Make sure you create a new workflow. 4 00:00:07,07 --> 00:00:11,01 And let's also rename this workflow to Presales AI Agent. 5 00:00:11,01 --> 00:00:14,09 (keyboard keys tapping) 6 00:00:14,09 --> 00:00:18,01 First, we'll begin by adding a chat trigger. 7 00:00:18,01 --> 00:00:21,03 This will be the main way to interact with the agent. 8 00:00:21,03 --> 00:00:24,00 (mouse clicking) 9 00:00:24,00 --> 00:00:26,02 We'll come back to this in a second. 10 00:00:26,02 --> 00:00:29,04 Next, add an AI agent node. 11 00:00:29,04 --> 00:00:32,08 (keyboard keys tapping) 12 00:00:32,08 --> 00:00:35,00 This will be the heart of our workflow. 13 00:00:35,00 --> 00:00:37,02 It's what brings together the model memory 14 00:00:37,02 --> 00:00:39,08 and the tools the agent can later use. 15 00:00:39,08 --> 00:00:41,07 You can leave the default settings here for now, 16 00:00:41,07 --> 00:00:45,05 we'll also come back to this in a bit. 17 00:00:45,05 --> 00:00:48,02 To make our AI agent an AI agent, 18 00:00:48,02 --> 00:00:49,06 it, of course, needs some AI, 19 00:00:49,06 --> 00:00:52,05 so let's connect it to a Google Gemini model. 20 00:00:52,05 --> 00:00:55,05 (mouse clicking) 21 00:00:55,05 --> 00:00:57,03 At this point, you can really use any model, 22 00:00:57,03 --> 00:00:58,07 but we're using Gemini here 23 00:00:58,07 --> 00:01:00,06 because it has a generous free tier, 24 00:01:00,06 --> 00:01:05,06 and the models work pretty well for agenetic workflows. 25 00:01:05,06 --> 00:01:06,05 If you haven't, 26 00:01:06,05 --> 00:01:09,04 make sure to select a Gemini credential here. 27 00:01:09,04 --> 00:01:12,05 To create one, click Create New Credential, 28 00:01:12,05 --> 00:01:14,03 leave this window open, 29 00:01:14,03 --> 00:01:20,08 head over to Google and search for Gemini AI Studio. 30 00:01:20,08 --> 00:01:26,09 Click on aistudio.google.com, 31 00:01:26,09 --> 00:01:29,00 and click Get Started or Log In. 32 00:01:29,00 --> 00:01:30,07 You'll need a free Google account for that, 33 00:01:30,07 --> 00:01:33,04 but this is how it should look like once you're logged in. 34 00:01:33,04 --> 00:01:35,05 On the left, you will see Get API Key. 35 00:01:35,05 --> 00:01:40,05 Click this one and click Create API Key. 36 00:01:40,05 --> 00:01:41,08 If you're doing this the first time, 37 00:01:41,08 --> 00:01:44,07 it might be that you need to create a new project here. 38 00:01:44,07 --> 00:01:46,05 In this case, just click Create New Project 39 00:01:46,05 --> 00:01:48,01 and give this new project a name. 40 00:01:48,01 --> 00:01:49,05 I already have a project. 41 00:01:49,05 --> 00:01:54,09 I select this and give my key a name. 42 00:01:54,09 --> 00:01:58,03 Make sure to delete this key later on after our demo. 43 00:01:58,03 --> 00:02:00,05 You don't need a credit card to set this up. 44 00:02:00,05 --> 00:02:02,06 There's a pretty generous free tier. 45 00:02:02,06 --> 00:02:06,06 Next, copy the key, head over back to n8n, 46 00:02:06,06 --> 00:02:10,01 and paste the API key in here. 47 00:02:10,01 --> 00:02:13,03 Click Save, and you're all set. 48 00:02:13,03 --> 00:02:15,02 Let's close this window, 49 00:02:15,02 --> 00:02:17,07 and you should now be able to select the Gemini models 50 00:02:17,07 --> 00:02:19,09 here from this dropdown menu. 51 00:02:19,09 --> 00:02:22,08 Make sure you select Gemini 2.5 Flash, 52 00:02:22,08 --> 00:02:25,08 that's one we're using in this course. 53 00:02:25,08 --> 00:02:30,00 Let's close this for now, 54 00:02:30,00 --> 00:02:33,01 and we'll also add a simple memory component. 55 00:02:33,01 --> 00:02:35,06 The goal behind this, that the agent should be able 56 00:02:35,06 --> 00:02:37,07 to remember the current conversation. 57 00:02:37,07 --> 00:02:42,02 So, in this case, click plus and select Simple Memory. 58 00:02:42,02 --> 00:02:44,05 This will allow the agent to, in this case, 59 00:02:44,05 --> 00:02:47,04 remember the last five messages. 60 00:02:47,04 --> 00:02:50,07 Let's set this to 20, 61 00:02:50,07 --> 00:02:53,05 so that means the agent can remember 62 00:02:53,05 --> 00:02:56,04 up to the last 20 conversations. 63 00:02:56,04 --> 00:02:58,08 Note that this is a really basic implementation. 64 00:02:58,08 --> 00:03:00,09 The memory will be deleted once the user 65 00:03:00,09 --> 00:03:04,02 closes the browser window or refreshes the current session. 66 00:03:04,02 --> 00:03:05,04 There are more advanced ways 67 00:03:05,04 --> 00:03:07,02 to persist memory between chats. 68 00:03:07,02 --> 00:03:12,01 But, for now, this basic implementation will do. 69 00:03:12,01 --> 00:03:14,06 Let's open the AI agent node again 70 00:03:14,06 --> 00:03:17,02 and come back to our system prompt. 71 00:03:17,02 --> 00:03:20,01 Click Add Option, and select System Message. 72 00:03:20,01 --> 00:03:22,02 This will define how the agent 73 00:03:22,02 --> 00:03:24,06 will behave and interact with us. 74 00:03:24,06 --> 00:03:27,03 I've already prepared a system message for that. 75 00:03:27,03 --> 00:03:30,02 In order to see this message or system prompt, 76 00:03:30,02 --> 00:03:32,02 go to the GitHub repository, 77 00:03:32,02 --> 00:03:37,00 and here navigate to Agent and agent_system_prompt. 78 00:03:37,00 --> 00:03:39,02 As you can see, this is quite long. 79 00:03:39,02 --> 00:03:40,09 Feel free to pause this video here 80 00:03:40,09 --> 00:03:43,00 and read through it in your own time. 81 00:03:43,00 --> 00:03:45,09 What this prompt does is essentially telling the agent 82 00:03:45,09 --> 00:03:47,01 the goal it should solve 83 00:03:47,01 --> 00:03:51,01 and the tool it has eventually available for doing this, 84 00:03:51,01 --> 00:03:53,08 which, of course, it doesn't have right now at this point, 85 00:03:53,08 --> 00:03:55,02 but that's fine for now. 86 00:03:55,02 --> 00:04:00,01 So let's copy this prompt and go back to our n8n, 87 00:04:00,01 --> 00:04:03,00 and paste the prompt in here. 88 00:04:03,00 --> 00:04:05,04 Let's close this window, 89 00:04:05,04 --> 00:04:06,08 and we have set everything up 90 00:04:06,08 --> 00:04:09,01 to try our agent for the first time. 91 00:04:09,01 --> 00:04:10,08 Click Open Chat, 92 00:04:10,08 --> 00:04:12,03 and then type a quick message, 93 00:04:12,03 --> 00:04:13,09 maybe "hello." 94 00:04:13,09 --> 00:04:22,01 (keyboard keys tapping) 95 00:04:22,01 --> 00:04:25,02 And you can see here how the agent responds. 96 00:04:25,02 --> 00:04:28,07 We can now also ask a follow-up question like, 97 00:04:28,07 --> 00:04:35,02 "What can I do here?" 98 00:04:35,02 --> 00:04:37,03 You'll probably notice something interesting. 99 00:04:37,03 --> 00:04:41,04 The agent at this point might claim that it can send emails, 100 00:04:41,04 --> 00:04:42,09 generate quotes, 101 00:04:42,09 --> 00:04:45,09 or help you to answer questions about the exhibition. 102 00:04:45,09 --> 00:04:47,03 But that's not true yet, 103 00:04:47,03 --> 00:04:49,03 because, at this point, our agent 104 00:04:49,03 --> 00:04:51,02 doesn't have any tools connected, 105 00:04:51,02 --> 00:04:52,06 so it might hallucinate 106 00:04:52,06 --> 00:04:55,05 or say it can't perform those actions, 107 00:04:55,05 --> 00:04:57,05 and that's exactly what we'll fix next. 108 00:04:57,05 --> 00:04:58,05 In the next videos, 109 00:04:58,05 --> 00:05:01,00 will give our agent the very first tool 110 00:05:01,00 --> 00:05:03,08 so it can actually do something useful for us. 111 00:05:03,08 --> 00:05:07,04 (keyboard keys tapping) 112 00:05:07,04 --> 00:05:09,08 So, in this case, you can see that when I ask, 113 00:05:09,08 --> 00:05:11,02 "When is the exhibition," 114 00:05:11,02 --> 00:05:12,05 it just returns an empty output 115 00:05:12,05 --> 00:05:14,02 because the tool isn't available. 116 00:05:14,02 --> 00:05:16,06 But there's also a good chance that it could have replied 117 00:05:16,06 --> 00:05:19,07 with a hallucination and just a made-up exhibition date. 118 00:05:19,07 --> 00:05:22,01 So that's what we are gonna fix in the next videos 119 00:05:22,01 --> 00:05:24,07 and give our agent its very first tool 120 00:05:24,07 --> 00:05:28,00 so it can actually do something useful for us.