Transcription
In this video, I'll be breaking down AI agents and how to build them so simply that a kid could watch this and build their first agent.
You see, there's no shortage of information online on how to build AI agents, but a lot of it is super confusing and full of jargon. So, I'll be walking you through everything as clearly as possible. So, even if you're brand new to this, you'll be able to do it, too.
I'm going to be building a research and email agent from scratch to show you how easily you can get one up and running. Let's not waste any more time, and I'll explain the diagram you're currently looking at.
So AI agents are often called digital employees or digital workers. To understand the different components of an AI agent, let's imagine that an AI agent is like a person. And here we can see that the way this is basically set up in this diagram is a task is coming in. Our AI agent will then work through that task and eventually reach an outcome. So it could be a task like, "Hey, go and tidy your room." We then need to process that task and eventually reach an outcome, which will be a tidy room, but more importantly, happy parents.
So when we, a person, needs to process a task, first of all, we need to be able to think about how we would do that task, and for that, we're going to be using our brain. And for AI agents, the brain is basically made up of two parts. First of all, an AI model and large language model like ChatGPT, Gemini, Claude, but also memory. And memory is what gives our AI agents the ability to remember past interactions. So in the same example we had before, if your mom tells you to go and clean up your room and an hour later she asks, "Are you finished?" you will know exactly what she is referring to. And it's the same way here in our AI agent. So the model gives our agent the ability to, uh, process and make decisions, whereas the memory allows the agent to remember past interactions.
So while the brain gives our AI agent the ability to make decisions, what really guides those decisions, and it's the same in people, is their conscience. How well are you going to do at the task? How motivated are you going to be, and what you think is actually a completed task? And when it comes to AI agents, the way we can basically guide this conscience is by creating or, um, giving our agent a system prompt. And this is often referred to as the AI agent's instructions. So this is a very long list of instructions that we can give to our AI agent that should form its conscience and tell it exactly how it should behave.
So, so far, with just a brain and a conscience, our agent has the ability to think and make decisions. But in order for it to actually act on those decisions, it needs to be able to use something else. And here, in this example of people, we have the different body parts. So, for instance, when we're cleaning our room, we need to use our eyes to see what is dirty. Potentially, if it's that bad, even our nose to smell. Then we have our hands and our legs allowing us to move, and our mouths to communicate. And with AI agents, this is basically referred to as the different tools that the agent has in its arsenal to be able to complete a task. And there are two different categories of tools that I want to showcase here.
And the first category is all about providing our AI agent with context. Information about the systems around it. So, if we're comparing it to body parts here, really, eyes, ears, and nose, these are all to do with our senses so that we can pull in information from our environment and make decisions. In the case of AI agents, this context is typically from pulling in information from different business tools, whether that's, uh, your emails, your CRM, wherever it may be, is understanding context. And what this really allows is so that the agent's reaching the outcome won't purely be based on what the model has been trained on, but rather the real context of a business or whatever your agent is trying to achieve.
Now, the second category of tools, very, very important, is tools that allow our agent to take action. So, in the case of a human, hands could be an agent typing a keyboard, giving us the ability to send an email. We also have mouths so that we communicate, and legs so we can move around. And it's the very same for AI agents. This will be giving our agent the ability to act in different tools that we use each and every day.
Now, if we take a look at the agent that we'll be building today in N8N, you can see here it's kind of similar, has some similarities to this diagram. First of all, when it comes to the task, this one's going to be provided to the agent from a chat message. So, anyone can basically write the agent a message and give the agent its task. Now, when it comes to the brain of the AI agent, remember that's made up of the AI model and also memory. And then finally, the tools of the agent. And instead of, uh, the agent's tools being different body parts of a person, here, this is different business tools that we would use.
And in our case, we're setting up a Santa's helper agent. So, what's going to happen is any person or kid can talk to our Santa's helper agent, tell the agent a little bit about themselves, how old they are, what their interests are, and our agent is going to get to work. It's going to use its brain, its memory, process the task. It's got its system instructions underneath its conscience, and then it has access to two different tools. First of all, one to find the appropriate toys for that person. And then secondly, once the person has agreed on exactly what toys they want for Christmas that year, we can send the wish list off to that person's parents or whoever's buying them their Christmas presents.
All right, so let's build this out in N8N. And so here I'm just in a new N8N workflow. Rule number one, always name your workflow. So let's call this one Santa's helper AI agent. And now to start building this out, we're just going to click here on "Add a first step." And we want to search for "AI agent." And let's click on this one here. And now you'll be seen here shown here the different settings. I'm just going to click out and we'll take a look at what's actually happened.
So what N8N have automatically done is we have an AI agent dropped in here, but we also have a chat trigger. So the way that this one works is basically we're just going to be able to chat with our agent here. And inside our AI agent settings, we can see the message that the agent receives. This is the agent's task is automatically taking the chat input. So whatever gets sent in the chat is automatically being fed through to our agent. But right now, for instance, if we, uh, test this one out. So here I can even type something in the chat like, "Hi there." We can see we get an error. And that's because right now our agent is completely empty. It doesn't have a brain whatsoever.
So let's go ahead and add a brain to our agent. The way we do that is first of all by adding a chat model. And you can basically pick from any number of the different large language model providers. What you'll need to have is for each of these, you'll need to have an API key. And I'll leave a link in the description. I've got, um, videos showing you how to get your Gemini API key, your ChatGPT API key, and also your Claude. Um, or you can just follow the documentation. But let's use Gemini for this example. And what you'll need to do is add some credentials. So, I already have, um, my Gemini account connected. If you're new to this, you just need to hit "Create new credential." And here, this is where you'll be pasting that API key. So, check out the other video, grab your API key, paste it in here, and then you'll be good to go, whether you're using Gemini, Chat, GBT, Claude, or any other model.
All right. So, now our agent has the first part of its brain. We have a large language model, in this case, Gemini. So, let me try this one again. If I say, "Hi there," and we can see our agent is running. It's using its model and just says, "Hi, how can I help you today?" So, our agent has one part of its brain, its large language model, and it's able to respond to some text.
But let me show you now why memory is such an important component of AI agents' brain here. So, I'm going to write something like, "When was Albert Einstein born?" And this is something that any large language model should know. So, here it says, "Albert Einstein was born on March 14, 1879." If I now write, "How old would he be today?" we can see our agent has come up with quite a weird reply. "I can help you figure that out, but I need more information. Who is he? Who are you talking about?" And that's because right now, whenever we're sending these individual, uh, messages to our agent, it has no idea about what's happened before.
So, in order to fix this, what we're going to do is give our agent some memory. And here, I'm just going to use the simple memory function from N8N to set this one up. We can see what's automatically being passed here is a session ID. I'll show you exactly where you can find this in a second. But we can also change here the context window length. And this is how many messages back and forth should our agent remember. And let me, I'm just going to update this to something like 20. So you can have a bit longer, uh, conversations with your agents. And this session ID here, you can see in this chat, every chat has a certain session ID. And if I click to reset, this will have basically a different ID. And that will allow you to have different conversations with your agent about different topics. But within that chat, it will remember everything that has been said.
So let's test this one out again. "When was Einstein born?" And we can see our agent now used both its memory and its model, giving us Einstein's birthday. "How old would he be today?" And we can see now it remembers that we're talking about Albert Einstein when we say "he," and that he would be 145 years old.
All right. So now that we have our AI agent's, uh, brain set up and we have the ability to chat with it, let's go ahead and set up its conscience. Remember that is the system prompt for our agent, or system message, our AI agent's instruction. So I'm just going to click into the AI agent. And first thing I'm going to do is actually rename this, um, to give it a little bit more guidance. This is going to be our Santa's helper AI agent. And we can see already we have the chat message that is being sent to our agent. But we want to add these system instructions or the system prompt. So underneath here, under "Add option," we just want to select "System message." And now you can see here by default, all that it has is, "You are a helpful assistant." That is not enough to guide its conscience. We now need to tell it exactly how it can be Santa's helper AI agent.
Now, what I would recommend, do not start writing out your system message in here. The process that I like to follow is always start writing out in simple language what you want your agent to do. So, here I basically say, "Here's what I want my Santa's helper agent to do. It will receive some details from a kid about their agent interests. It's then going to use its find toys tool to find the top three relevant toys. The kid will then give feedback about those toys, whether they're good or whether more should be suggested. And finally, it should use its send wish list tool to send the wish list of the kid to the parent or whoever is shopping for Christmas."
So now that I've got it written out in plain language, what I'm going to do is I'm simply going to copy this one and then open up any AI chat tool. So here I'm in Claude. Whether you use Gemini, ChatGPT, it doesn't matter. Basically, do not write your own system prompts. Have AI write them for you. So, all I've added to what I have in that doc there is, "I'm working on setting up an AI agent in N8N. Could you please help me with writing the system prompt?" And here I've basically just copied in, um, me just describing in plain language what I want my agent to do. So, I can send this one off.
And here we can see Claude is now carefully crafting a detailed system prompt. Way better than anything we would have written if we started writing this out manually. So, we can take a look at everything that Claude has added to our agent system prompt. So it's given it a role and personality, which is cheerful and enthusiastic. Then it lays out its core workflow. What workflow should this agent always follow? Step one, step two, step three, all the steps, uh, needed. Giving some instructions about the different tools that it has access to, the find toys tool and the send wish list tool. And then also some communication guidelines, error handling, and example interaction, even some important notes. And what's really good about this process is you can read through this. If you're not happy with those instructions, you can simply continue back and forth chatting with ChatGPT, Claude, Gemini until you nail your system instructions.
So here's a version that I actually went back and forth with Claude with. It also included, like, an HTML template of the email. So I'm just going to copy this one. And then back in N8N, we can simply paste that long, uh, system prompt here. If you want a copy of the exact system prompt that I'm using in this example, in the description below, um, you'll find a link where you have access to the full prompt.
All right, so now we've got our brain set up and our conscience with the system prompt, the agent instructions. Now, before we can actually go and test this out, first of all, always, as you're building these, make sure you're hitting save along the way. But now we can basically add the agent's tools. And as we know, this agent is going to have two tools: one to find toys and another to send the wish list email.
So let's first start by looking for our Perplexity, uh, tool. And again, this one you need to have a connection and add an API key. So very easily in your, um, Perplexity account, you can find your API key. You do need to add some credits to it. Um, and then you can easily paste this in there. And whenever you're setting up these agent tools, naming them is also very important because that's what our agent is going to see. So in this case, I'm going to call this "find toys tool" because that is what this, uh, tool's purpose is. We have a few options here in Perplexity. We want to keep this as "Message a model," but the model that I'm going to use is probably one of the more advanced ones. I'm going to use Sonar, uh, Pro. And now we have a message. So the way that Perplexity works is it will go and do an AI search of the internet. And whatever it searches for is based on the message that is being sent here. And what I'm actually going to do is I'm going to click on this little button which says "Let the model define this parameter." And the reason why I'm going to do this is all of the instructions on what should be searched for has already been provided in our AI agent conscience in the system instructions. And then we just want to have "Simplify output" toggled on. This is just a way that we're not sending too much information back to our agent, only the information that it needs to know.
So now we have our find toys tool set up. We need to add our second tool for our agent, and that is going to be our send wish list tool. And for this, we're going to be using the Gmail tool here in N8N so that we have the ability to send an email. Again, here I already have my Gmail account, uh, connected. If you do want to create, connect any Google services, I actually have a separate video where in less than five minutes, you'll know how to create, connect any, uh, Google application to N8N, and I'll also leave a description to that below and probably on screen as well. But I've got my Gmail connected, and what I want to do is I want to use the "Message" resource. This is basically an email, and I want it to send a message. So the first thing, remember whenever we're setting up these agent tools, let's, uh, adjust the name slightly. So this is going to be the "send wish list tool." And now, in order to have the information about who should be sending the email to, what should be the subject, and what should be the message for all of these, we're simply going to let our AI agent decide because again, all the information is provided in that system prompt.
All right, so our AI agent, our Santa Helper AI agent, is looking quite complete now. We've got the brain with the model, the memory set up, and now our two different tools to find toys and then send the wish list email. Now comes the most critical part whenever you're building AI agents, and that's actually testing them out.
So let's open the chat. I'm just going to start with something simple like, "Hi there." And what's happening now? You see, we got quite a quick response. All that we needed to use here was the model and the memory. Um, but you can see it's responding totally different to when it was just a helpful assistant. "Ho ho ho. Hello there, friend. I'm Santa's helper." So it already has a personality. It's totally changed the way it communicates. Um, it's asking to get started. "Can you tell me how old you are and what are your favorite things to do? Do you love building, drawing, playing outside, or something else super fun?"
So, I've just prepared a little mock message here saying, "Hi, Santa's helper. My name is Molly. I'm 3 years old. I love all things pink. My parents prefer when I play with toys that are also educational as well as fun." So, quite mature. Let's have a look what happens now.
So, now when this message gets sent off, we can see our AI agent kick in straight away and using its find toys tool. And now we're presented with a perfectly formatted message. So, we have the top three picks for that child. We can see listed in order with a short description, um, including the price as well, uh, of each toy. So, imagine Molly's going to read through this and say, "Okay, these all look good. Um, let's say they are great, but can you put the princess dress up in spot number one and send the wish list to," and I'm just going to add an email address here that will blur out. So, this will be the email address of Molly's parent. And we can see what's happening now. So, the Gemini model is working. And then straight away, we've used the send wish list tool.
And let's most importantly now take a look in my email address. First of all, what's also happened here is the agent has confirmed with Molly that that email has been sent and asking if there's anything else that Santa's helper can help with. And we can see now we've received the email, "Molly's Christmas Wish List from Santa's Helper." And we can see there is a perfectly formatted, uh, email here with the Disney princess now up in number one. So, if I'm the parent, I can simply just copy this and let's do a quick Google search. And here we can see the princess dress up kit. Very, very cool. Nice and pink.
And remember, all of this is possible because A, we equipped our agent with very clear, guided system instructions, which allows it to create well-formatted emails like this one, but also the fact that we equipped our agent with the relevant tools to go and search for toys and then obviously send this email.
And now, if you perhaps are not a kid and watching this and want to see, okay, what would be the business context of an agent like this? Maybe instead of searching for toys, it's searching through business databases like your CRM, your content base, whatever it needs to be. Basically, always think about, do I need to give my agent context around different business items, performing searches on the web, and then what actions do I want my agent to take?
Now, if you're here, you might be a beginner, which means you're probably looking to get some agents up and running. The issue is I didn't go into as much depth in this video since this is literally how I would teach AI agents to a kid so that beginners watching this could follow along. But if you head over to this video on the screen now, you can get a more intermediate level understanding of building AI agents yourself step by step and literally just follow along to see what I personally do. If you've been wanting to learn the behind-the-scenes of actually building AI agents, this is your ticket to learn it. I'll see you over there.