How I'd Teach a 10 Year Old to Build AI Agents (No Code, n8n)

Dr. Violet Howard builds a simple email-sending AI agent in n8n using three core parts: an LLM brain, memory, and a system prompt that defines available tools. She connects Gmail and Google Sheets so the agent can send emails to contacts by name, using natural language requests to drive the recipient, subject, and body.
Chapters
Today I'm going to be walking through the simplest way to understand what an AI agent is, the different components, how they actually take action and do things. And then I'm going to show you guys how to build a super simple one in minutes. There's a lot of information out there on the internet about AI agents, so I'm going to try to break it down for you guys as simple as possible using this little pretty diagram that I built. And then we're going to get into N8N and I'm going to walk you through step by step how to get an email agent up and running. Really, really easy. I think you guys will be surprised by how quick you can spin one up. So don't want to waste any time. Let's get straight into it. As you can see right here, we're looking at an AI agent sort of diagram with the different aspects, right? So in the blue here, we're looking at the actual AI agent, and you can just think of this as kind of an entity, a human, um, an employee, anything that you can pretty much talk to, anything that has a brain and understands instructions. Just think of it like that, right? So when we are talking about an AI agent, the two main components within one are the brain, which is basically a large language model like ChatGPT. Claude 3.5, something like that. And then some sort of aspect of memory. So memory just basically means giving the agent context of what's been going on in a conversation. That way it feels more human-like, it's more conversational. Rather than asking a question and then getting an answer and then the slate is wiped clean, we pretty much have a running history of, you know, a window of the agent's able to understand that so that its answers in the future make more sense or its actions and tools make more sense. Based on what we've talked about in the past. Then we also have instructions. So instructions within an AI agent basically just define, this is your role, this is what you should be doing, this is how you act, these are the tools you have, this is how you take action. It's just, it's commonly known as a system prompt within an AI agent or a system message. Not to be confused by user messages, which is more of the actual input going in. So once we get into N8N and we're looking at the agent, I'll break this down, it'll make a little more sense. But the user message is the actual input. This is how we're talking to the agent. And the system message is the agent's instructions that don't change. The input kind of changes every time based on every interaction. Finally, of course, it outputs something to us, whether that's, hey, you know, we were able to take action for you, or whether that's explicitly using a tool like a vector database to pull information back and then returning you that information. There's usually some aspect of output. So as far as this section of this little diagram, input, AI agent with a large language model memory system prompt and then outputting something. This is like just kind of like a ChatGPT thing that you would do, um, on your laptop or whatever, and you're talking to it. That's ChatGPT. But then when you start to introduce tools, this is where the magic really happens because now the large language model has the ability to actually take action. And let's say you just have one tool. That's, that's pretty cool. But what we want to do is we ultimately start to add multiple tools and the agent uses its brain to understand, sorry, it uses its brain in combination with the instructions to understand what just came in, what was the user message, what tool do I need to do, because what tool does what function, and then how do I actually go out there and take action. So this is what it looks like, right? And now if we go over here, this is pretty much the agent we're going to be building today. It's similar. So as you can see, we have the input right here. which is on chat message receive. So we're just going to be chatting with our agent in the N8N environment. So that's the user message coming through to the agent. The agent uses the user message along with its system message to understand, what do I need to do here? So here's its brain, here's the chat model, here's another aspect of the brain, which is the memory. And then finally, our tool here is going to be sending an email. So it understands to take the message from the user, craft an email, and then it spits out back to us. It basically says, The email was sent to blank. So, um, I hope that all made sense. I am going to hop into N8N now and we're going to walk through step by step how to build this really simple email agent. Okay, we are now in N8N. So first thing I'm going to do is hit add first step and we are going to type in AI agent. We're going to grab this AI agent here. And as you can see, it put in this AI agent, um, entity. And right now it automatically connected with the chat message received trigger. We can come in here and we can say hello. This is how we talk to our agent. This is the user message. This is the input going into the agent. However, as you can see, there was an error because there's no chat model subnode, which basically means the agent has no brain. It doesn't know how to respond. So under the agent, we can see that we have chat model, memory, and tool options. We're going to add a chat model because we just got that error. So let's give it the brain. It pulls up a list of large language models on the right, and we're going to click on OpenAI chat model. Okay, so now that we have the OpenAI chat model pulled up, we have different options. We have different models to choose from. But first, what we need to do is connect a credential if we haven't done so already. So you'll click into this arrow and you'll click Create New Credential. And as you can see, what we need to get from OpenAI is an API key that basically allows us to access their different models. So you can click on Docs and it will give you a good sort of walkthrough documentation of how to do this. But basically, you're going to go to OpenAI. On the left-hand side, you'll see API keys. And then you're going to come up here and click Create New Secret Key. We're going to name it whatever we want, and then it's going to give you an API key. You'll copy this, and then you're just going to paste it into N8N right here. Once you paste that in, you'll hit save. It will think about it. It will go green to let you know that it was connected successfully, and then you're good to go. You can click out of there, and then you can explore all the different models that we have. So right now I'm just going to leave this as GPT. 4o Mini. One thing to note about your OpenAI, you have to connect a few credits or some sort of source. Otherwise, it's going to say insufficient funds. So if you're getting that error, just add some money into your account. Now, if we were to click on chat, we could come in here and just say hello, and it's going to be able to respond to us because it has a brain. As you can see, it said, hello, how can I assist you today? Okay, now that we see that the brain is working, let's try to add some memory. First, what we're going to do is I'm going to tell the agent my name. Is Nate. So it's going to say like something like, hi Nate. Okay, so nice to meet you, how can I assist you? Now I'm going to say what's my name, and it's probably not going to know my name. I'm sorry, but I don't know your name. So as you can see, it has no context of what we just talked about. So now if we click on this plus for memory, and there's a couple different options here, and we're going to use window buffer memory. It's super easy, especially if you're chatting within N8N. Very, very easy and very quick to set up. As you can see, it's referencing our connected chat trigger node. The session ID is coming from that chat trigger node, and the context window length is 5. So it just means it's going to remember 5 messages, past interactions. So if you're interested in the session ID, it's basically going to be different for the different ways of communication. So right now, within the chat input, we can see it's an action of send message. Actually, I'll go to table view real quick. The chat input that I just typed in was, what's my name? And then we have a session ID. So basically what's going on here is that is what is being kept in the context window length is based on the session ID. That's dynamic because we have the JSON variable, as you can see right here. Anyways, now that we have memory connected, I'm going to say, hi, my name is Nate. And it will say, hello, nice to meet you, Nate. And then we're going to say, what is my name? And you can see that it's going to say, your name's Nate. Okay, awesome. So we have memory. We know that it's working. We just tested that. We have our input over here. We have our actual agent with its brain. We have the output coming right here. And what we could do is if we just want to make things look a little more visually appealing, we could pretty much just add the output right here. This isn't doing anything. This is basically just for me to show you guys how it looks. So input, agent, output, right? It says, your name is Nate. How can I help you today? And then bring. So now we need to add the tool, and then after we add the tool, we can configure the system message. So we're gonna click on the plus and we're gonna add a Gmail tool. What we have to do here is connect our Google credentials. So if you need to do this and you haven't set it up yet, you're gonna click on Docs. From there, it'll walk you through how to do it pretty much. But also, I made a video, I'll tag it right up here, how to connect your Google credentials within 5 minutes, so you can watch that. It it will all make sense. What we're gonna do here is leave everything as is for sending a message, and we need to fill out the to, the subject, and the message to pass over to Google to actually send this off. So the first thing I'm gonna do is I'm gonna change the email type to text because we want to do that rather than HTML. And then for to, we're gonna come in here and make this an expression. This basically just means rather than putting in a fixed email that would every single time this tool ran, it would go to that email, We want this to be dynamic, so we're going to click on expression. So that way the to is going to change based on every interaction we have with the agent asking it to send a message for us. So what we're going to do is type in two curly braces and then we're going to grab fromAI. This is a really, really cool function because it lets us define a key and potentially descriptions about the keys and the type of data it's looking for. But really, I found that you can pretty much do it, just do a key. So in this case, we're going to do a key called email address, or no, actually let's do, just be a little more specific, email recipient. So this is telling the AI that when it wants to fill out this parameter of the to field, all it has to do is look through the query that's coming in from the user message, the input. It's going to look through that input and then it's going to decide who is the actual email recipient. It's going to pull that out of the query. Because it's gonna use AI to do so. And we're gonna do the same thing for the rest of this node. So subject, we'll paste that in here, make sure it's an expression, and then the key is going to be subject. And then we're gonna do the same thing for message. The expression is going to be email body. So now we have those 3 fields set up. Automatically, AI is gonna be looking through the query based on the user input, and it's going to fill out the parameters. And then finally, I'm just gonna click on add option. Click on Append N8N Attribution, and then turn this off. All this does is otherwise it's going to, at the bottom of an email, it's going to say something like this email was, you know, sent by N8N. So finally, we're just going to name this node Send Email, just so that in the future if we wanted to start to add more tools, we were able to define to the agent what each tool is called and what each tool does. We pretty much have everything: the input, the output, the agent, the brain, the tool. Now we need to set up the system message. So in this agent, we are going to click on add option and add system message. By default, it's going to say you're a helpful assistant, which is fine. It probably would work, but we want to define exactly what tools it has and when to use them. And so as you can see, we have the system message down here. Like I said, this tells the agent how to act. This is the instructions, but then the user message up here is going to be the input every time. So right here, as you can see, it was what is my name. So I'm gonna be using this custom GPT that I've built to help me prompt my AI agents. If you want to access this, you can do so in my free school community. The link for that will be down in the description. And I know I'm going through this a little fast, but if you're looking to dive deeper with N8N, feel free to check out my paid community. Link for that will also be down in the description. We've got a great community of people also trying to learn N8N, always asking questions, always sharing resources, a great classroom section, as well as 5 live calls per week to make sure you can hop in there and get all of your questions answered. So I'd love to see you guys in here. Anyways, back to the GPT. I pasted a screenshot of our workflow into the GPT, and then I said an AI agent that uses the send email tool to send emails based on the user's query. It is a helpful assistant that is friendly. So let's send this off to the GPT and we'll see what kind of system message we get back. As you can see, it's outputting it in Markdown format, which is really, really nice because that helps the AI agent sort of establish, um, different sections of the prompt. As you can see, we've got overview, context, instructions. Tools, examples, standard operating procedure, and then final notes. So we're able to copy this prompt, come back into N8N, and then paste this as an expression. I just like to do expression so I can go full screen in here and it's fully Markdown formatted, which is really easy for us for readability as well as for the AI agent to read through. So we'll hit save and now let's test this out by asking it to actually send an email for us. So we're going to say, can you send an email to nateherk88@gmail.com asking him how his day was. Okay, so we're gonna see this in live time, which I always think is cool. That is going to take place really quick, but essentially what happened here was we got the input. The user message was, can you send an email? It's what I just asked, right? So then it used the brain and the system message to understand what it needed to do. And then it hit the email tool. If we click into here, we can see that we got the correct email, the correct to. The subject was made, which was, how's your day? And then the actual message was made, which was, hi Nate, I hope this message finds you well. I wanted to check in and see how your day has been going. Looking forward to hearing from you. Best, placeholder, your name. So that's something I wanted to show you guys. By default, it's going to sign off like that because in the system message, it doesn't know who to send an email from. So if we came into the system message real quick, and at the very bottom we just said, um, always sign off the emails from, um, Frank. And now we save this and we pretty much just rerun this exact same query. We'll watch this happen. And there we go, new email was sent. and as you can see, now it was signed off, Best, Frank. So let's hop into Gmail and actually see this email. Okay, so here it is. Hi Nate, I hope this message finds you well. I just wanted to check and see how your day's been going, and then you can see it signed off, Best regards, Frank. So something else important to understand here is the logs, but let's pull it up within the AI agent just 'cause it's a little bit bigger. So we'll click in the agent, we'll click on logs, and now we can see basically what the agent did. So we can see the steps that it took. First thing that it did was it put our chat message into the window buffer memory. That way we can store it later if it needs to reference it. From there, it went to the OpenAI chat model, which all it did was it looked through its prompts so it could understand what it needs to do based on the input coming in from us. So it realized based on the prompt that it needed to use the tool called send email. So we can see that it created this, these 3 parameters, which was the email recipient, the subject, and the email body. And if you remember, those are the 3 that we set up as keys in this email tool right here. Email recipient, subject, and email body. So anyways, after it created those parameters using AI, it actually sent out the email. This is just a response from Gmail basically saying it went through. Here's the ID of that email. It came back to the OpenAI chat model to check if there was anything else it needed to do and also to craft a response to us. And as you can see, the response down here was, I've sent the email to Nate Hurk asking how his day was. If you need anything else, feel free to ask. And finally, it hits the window buffer memory again. In order to update the memory. So that's really cool. We had that working. We're able to chat with it and it's able to send emails on our behalf. But what if we don't want to type in an email address every time? Well, what we can do is we can connect a contact database. In this case, I'm just going to be using this Google Sheet database, um, just for simplicity's sake. But this could always be something from your CRM or an Airtable or a vector database even. So right now what we're going to be looking at is just this contact database. We're going to be asking to send an email to Phil, which is the email that we just used, of course. And then we've got some dummy data here to make sure that it's searching through and finding the right one. So all we're gonna do in our agent is move this guy over, add a new tool, and we're gonna grab a Google Sheets tool. Once again, your credentials will have to be connected. This should be easier now that you've already done it once with Gmail, but we don't really have to set anything up. All we have to do is grab the right document, which is contact database, and then just choose the right sheet, which in this case there was only one sheet. And then we just want to name this something like contact database. That way it knows how to look through it based on our prompt. But you may have realized that in our prompt, we didn't mention anything about a contact database. So what we're going to do is we're going to go into ChatGPT and we're going to utilize the memory aspect of a large language model and just say, can you refine this prompt and add a tool called contact database that the agent will use to retrieve contact data like email addresses. Okay, so there we go. We'll fire that off. It'll pretty much keep all the same content that it already knows of, you know, from the previous prompt. It's just going to add in the tool about contact data. So as you can see now, we have the contact database tool. Retrieves contact data such as email addresses based on the user's query. Um, it comes back with some more examples and stuff like that. Um, so we're going to copy this back into our prompt right here. So we're going to save this and we're going to try to chat with the agent again. Um, so remember this time we don't want to give an email address. We want to say send an email to Phil and then we want to make sure that it goes to the contact database to get Phil's information and then it will use that to send the email. So, can you send an email to Phil, um, letting him know that I will not be at work today? Okay, so it's gonna hit the contact database, going back to the brain, going back to the Gmail node, back to the brain. We'll look at the logs in a sec, but let's just see what happened. So first of all, the agent responded to us with, I have sent the email to Phil. Letting him know that you'll not be at work today. If there's anything else you need, just let me know. So click on the contact database. We can see that it looked through all, how many rows there are, it looked through those, right? And then we can click into the Gmail node and see that it got the correct email. The subject was not attending work today, and the email body that it created was, hi Phil, I wanted to let you know that I will not be at work today. Please let me know if you need anything urgent in my absence. Thanks, Nate. But yeah, that's basically gonna be it for today's video. I know that it was kind of a simple build, but I just wanted to show you guys how quick and easy you can spin some of this stuff up, especially if you haven't built one before. It may seem a little daunting, but especially with these cool tools and the fromai function, it's really, really easy to continuously add more tools as well as get them up and running really quick. So, you know, once you've done this, there's other ways that you can have outputs and inputs. Sorry, I should have gone the other way around, inputs and outputs. Right now, obviously we're chatting with it within N8N and we're able to get the output within N8N as well. But you could connect this to, you know, your Telegram, you could connect it to your phone, you could connect it to Slack, anything you want. And they can be triggers as well. It doesn't have to be just hosted within the N8N environment. And then similarly, you could get the outputs pushed somewhere else to you. So this could be a complete backend application that you're able to hook up and, you know, talk to however you want. I actually just made a video very similar to this about an email agent where I connected the input and the output to ElevenLabs. So that I was having a phone conversation basically with this agent. And in real time, when I was asking it to send emails, it was doing so, and we kind of saw it take place. And then it would respond to me after the email was sent and say, I sent that off for you. Um, so really cool stuff that you can do once you understand sort of the basics. But as always, if you guys enjoyed, please leave a like, definitely helps me out. Let me know in the comments what else you guys want to see. And I really appreciate you guys making it to the end of this video. So I'll see you guys in the next one.










