From the course: Build with AI: Create Custom Chatbots with n8n
Creating the basic n8n chatbot flow
- [Instructor] All right. So let's create our first basic chat bot in n8n. To get started to click create workflow over here, and then add a chat trigger as the first step. We can close this for now. We'll come back to the chat trigger later on. Next, let's add the actual AI node over here. There are a couple of options in n8n. For our purposes, we are choosing the AI agent node, which allows us to flexibly evolve our simple chat bot as we go. So let's select AI agent, and make sure it's connected to the chat trigger node. For now, let's close this, and make sure that we also connect a chat model here. This is the actual AI service. So click plus and you see there are various options you can choose from. I'm choosing Google Gemini here. Why? Well, because it's pretty easy to set up. If you haven't connected Gemini to n8n before, just simply click this create new credential menu over here, and then you need to insert an API key. Where do you get this API key from? Well just visit AIStudio.Google.com. And you will see that there is a button saying Get API key. And the nice thing about Google Gemini is that, you get a pretty generous free tier. So that means you don't need to put in a credit card, you can just go ahead and create an API key, which gives you a couple of thousand tokens every day to work with. So click create API key, and you might see this little window over here or not, if this is an account which is connected to Google Cloud. If not, you will just directly see the API key instead. But in the end, you should see something like this. So let's copy the key. Go back to n8n and insert the API key over here. Hit save and you're all set. Okay. So now you have a list of models to choose from, and one of the most powerful models right now is Gemini 2.5. So let's go ahead, and search that by putting it in here. You can use the Flash version, which is faster, and a little cheaper or Pro. Let's use the Pro version for now, but it's also a little slower. You can try out different models as you like. Now let's close this one for now, and this is actually the only thing we need to set up in order to make our chat bot work. So let's try it out. You see this chat window over here, and in this chat window you can interact with your agent or with your chat bot immediately. So far it's not really an agent because it can't do anything, but it's a simple chat bot. So let's say hi. And we see the response here. "Hello, how can I help you today?" Again, you might get a different response, but the essence here is that our chat bot configuration is working. Let's ask it a different question. Like for example, "What's your name?" You see, it doesn't have a name, but there's one more thing I wanted to show you here. So let's say we give this model some instruction or something to remember. So I could say, for example, "Remember the number two." It'll probably come back to me and say, "Yes, of course. like I remembered that number." Now let's ask it, "Which number did you remember?" You can see that the chat here that the AI here has no idea what I'm talking about. So what happened? Even though in this little interface, everything looks like a single chat, what happens under the hood actually is that we make separate API calls to the model. So the model has no idea what I mentioned one, two, or three messages before that. In order to make this possible, we will need to give our chatbot a memory, and this is exactly what we will do in one of the next videos. We'll give our chatbot a personality to make it actually helpful, and help us to ask questions, and also remember what is being said in one conversation. So with that said, I'm looking forward to seeing you in the next video.