Build Your OWN AI Agent That Can SEE And SPEAK With Ease β
n8nRecentπ
2025-01-21
Build Process β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β BUILD AI AGENT WORKFLOW β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ€
β β
β PLANNING β
β ββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Define βββββΊβ Choose βββββΊβ Setup β β
β β Scope β β Stack β β Project β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEVELOPMENT β
β βββββββββββ β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β Build βββββΊβ Add AI βββββΊβ Test & β β
β β Features β β Logic β β Debug β β
β βββββββββββββββ βββββββββββββββ βββββββββββββββ β
β β β
β βΌ β
β DEPLOYMENT β
β ββββββββββ β
β βββββββββββββββ βββββββββββββββ β
β β Deploy βββββΊβ AI Agent β βββ LIVE! β
β β to Cloud β β Running β β
β βββββββββββββββ βββββββββββββββ β
β β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββKey Components β
- Project architecture
- Core features implementation
- Best practices
Transcript β
[00:00] In this video, I'm going to teach you how to build AI agents that can see, speak, and think for themselves without writing any code. And don't worry if you're a complete beginner, this tutorial is for you. The adoption of AI agents is absolutely exploding. It's clear that 2025 will be the year of the AI agent, so you definitely don't want to be left behind. Right, now let's have a look at what we'll be building. This workflow might seem intimidating, but it's really not.
[00:30] We'll go through the process step by step. We will integrate our AI assistant into Telegram so that we can access it from absolutely anywhere. You can use the techniques that you learn in this video to integrate it with WhatsApp or any other platform. Let's have a look at a few capabilities of this agent. First, it can read and create events in our calendar. So I can say something like, "What's my schedule for today?" And we can see we have this budget discussion with Sally from 5 to 6 pm today.
[01:00] And switching over to our calendar, that is indeed correct. We can also use voice to communicate with our agent, and our agent will then respond back with audio as well. Thanks for that. Please can you also give me a summary of my unread email? Alright, and let's listen to this. You have one unread email in your inbox from leonvansil, leon.vansil at gmail.com, deployment status, summary. The email is a follow-up regarding the latest release for Project X, asking if everything is set to go live on Friday.
[01:32] If you need help responding to it or anything else, just let me know. Awesome. And by the way, you can change the voice as well. Our agent also has multimodal support, which means we can ask it to analyze images. So I'll simply upload an image, and let's ask it, is this character happy or sad? And of course, our agent is correct in saying this character appears to be happy. Our agent also has access to a custom knowledge base. So to demo this, I created this very simple CSV file that contains a list of contacts, along with
[02:03] their email addresses. So let's ask our agent to send an email to John. And what our agent will do is find the email address related to John and send the email. Let's try this. Please send an email to John asking if he's keen to play squash on Saturday. Right. Our agent says the email was sent. So we are expecting the email to be sent to John.do at example.com. So going to our sent items, we can see this message to John. And we're just receiving this message saying that the address failed because it
[02:34] doesn't exist, which was expected. But what we are interested in is the message that was sent to John, which is very well formatted. And if we look at the email address, it was indeed sent to John.do at example.com. And finally, our agent can also go online and perform research for us. So we could ask it, what is the latest AI news from OpenAI? And our agent will now perform a Google search and then summarize the results for us, making this an effective research assistant. And here we can see all the headlines as
[03:06] well as these links that will take us to the original article. And indeed, this article was posted today. Now, if all of this seems intimidating to you, please don't worry, as I'm going to show you in the next few minutes how anyone can build AI assistance without having to write any complex code. Let's begin. In order to build our assistant, we will be using a platform called N8N. N8N is exploding in popularity and definitely worth learning. What's great about N8N is you can't sell
[03:37] those that for free. Or if you don't want to deal with the setup process yourself, you can definitely sign up for their cloud service. If you would like to learn how to sell post N8N, then I've got other videos on my channel going through that. But for this tutorial, I highly recommend using their cloud service. If you use the link in the description of this video and it will greatly help my channel. So then all you have to do is sign into your account if you already have an account or click on get started, complete your full name, your email address, a password and set a unique
[04:08] account name and then click on try for free. And afterwards, you will be presented with the N8N dashboard. You can change the theme to dark mode by going to settings, then go to personal, scroll down to the bottom and change the theme to dark theme and save. You can go back to the dashboard and for you, you won't have any workflows, but we can create a new workflow by clicking on create workflow. Then the first thing we need to do is set a project name. So let's rename this from my workflow to
[04:40] AI agent tutorial and press enter. Then I highly recommend setting your time zone. So click on these three dots, click on settings, then on the time zone, select your local time zone. This will affect the time and date that's used when doing research, sending emails, etc. So I highly recommend setting this and let's click on save. Let's add our first trigger node. Here we have plenty of options. We can trigger the workflow manually or on an app event, which is what we'll use.
[05:13] We can also run a workflow on a fixed schedule, on a web or call or on a form submission. We can also search for triggers and in our example, we'll search for telegram. But of course, if you wanted to use something like WhatsApp or some other platform, you should find a trigger for that. Again, we'll be using telegram as it's super simple to set up and the specific trigger that we want is on message. This simply means that when we receive a message on telegram, it will trigger this workflow. The first thing we need to do is select
[05:44] our telegram credentials. It's defaulted these credentials for me because I've already set up credentials. But what you need to do is click on create new credential. Then we can rename this by clicking on this name and let's call this AI agent tutorial. Now we need to provide this access token. Where do we get this from? Thankfully, NNN is very helpful in this regard. Go to the section that says need help filling out these fields and click on open docs. Then scroll down with this page and find
[06:16] this bot father link. Click on bot father and you should be prompted to sign into telegram at this stage, which I recommend you do. And afterwards, you can either start bot father on the web or using the telegram app. Either way will work. Personally, I'm going to use the desktop app. Creating new bots are super simple. Simply enter front slash and select new bot. Now let's give our bot a name. I'll simply call mine AI agent tutorial and let's send this.
[06:47] Now we need to set a unique username and this username must end with the word bot. So I'll just call mine AI agent tutorial bot. Now this is saying our bot was created, but very importantly, we get this API token. So let's copy this token and let's paste it into this access token field in NNN. Let's click on save and we should see this green connection tested successfully message. Great. And let's go back to the canvas.
[07:18] This is optional, but I do like doing this for my agents. We can give it an avatar image by typing front slash, then set user pick this option over here. It will now ask us which agent we want. We can then select our agent from the list and now we can send any image that we want to use as a profile image. I'll just use this image. Let's send it and cool. Our image has been set in order to access this bot simply go back to this message with the API token and
[07:49] click on this link over here. Now we can start a conversation with this bot and we can see a little avatar image showing up on the left as well. Now, obviously we can send something like, hey, but nothing happens. That is because NNN isn't listening for events quite yet. So back in NNN, let's click on test workflow and now NNN is waiting for a message from telegram. Let's try this again by saying hello. Now back in NNN, we can see that we received one item and in this output, if
[08:19] we go to schema, we can see the name of the sender. And if we scroll down, we can also see the text that was sent to NNN. We will add the ability to send voice messages and images in a second, but let's first build out the process to respond to simple text. So what we can do is add an action. Then under advanced AI, click on AI agent and from this node, let's change the source of the prompt by clicking on this dropdown and let's change this to define below. Now what we can do is grab the text that
[08:51] we received from telegram. So this is a load text every year and paste that into this prompt field. Now, if we execute the step by itself, this won't work yet because we haven't designed a large language model, which is effectively the brain for this agent to attach a model to this agent. We can click on chat model and navigate a list of many different service providers. If you want to try free models, you can definitely try Grok and I do have separate videos on my channel showing how to set up Grok with NNN.
[09:23] But for this video, I will be using open AI or if you want to use an anthropic, you can definitely do that as well. Just be sure to use Claude 3.5 sonnet. So I'm going to add this open AI chat model. The first thing we need to do is set our open AI credentials. So in this dropdown, click on create new credential. Then for the API key, go to platform.openai.com slash API keys. You do need to create and sign into your account and this is a paid service.
[09:53] So you do need to load a little bit of credit. Then let's click on create new secret key. Let's give it a name like AI agent tutorial. Let's create this key. Let's copy this key and paste it into NNN and click on save. Then select your credentials and then we should be able to click on this dropdown to select a large language model. For this video, we will be using GPT-40 Mini, which is a really fast and cheap model. Let's go back to the canvas and let's also assign a memory node.
[10:25] Let's simply select window buffer memory. Let's also change the session ID to define below. The memory node simply allows the agent to recall past messages from our conversation and each conversation will have a unique identifier. So we can actually get a conversation ID from telegram by going to mapping. Then within this telegram trigger, you can simply add this chat ID. The context window length is the amount of messages that should be included. So let's simply say we want the previous
[10:56] 20 messages to be included. Now let's go back to the AI agent node and now I'm going to show you the correct way to prompt these agents. Under options, let's add an option and let's add the system message. Then I'm going to switch over to expression and we can click on this button to expand this view. This is something that people seem to overcomplicate and in this video, I'll show you the correct way of writing a system prompt. What I like to do is to start off with a heading called role and within this heading,
[11:26] we can assign a role and explain things like the behavior of this agent. So we can keep it simple by saying you are a friendly and helpful assistant called Sammy. Keep your answer short and to the point. What I also like to do is to create another heading called additional information. Here we can say things like you are currently chatting to and now we can provide the name of the person that it's interacting with. Now we obviously don't want to hard code this name, but instead we can grab the name from the
[11:56] telegram trigger and add it to this template. Great! And on the right hand side, we can see a preview of the final result, which does include my name and that's all we have to do for now. We will add to the system prompt as we go along. So we can close out of that and let's go back to the canvas. Let's test this agent again and this time we do get our response back from our AI model. How cool is that? All we need to do now is send this message back to telegram and we effectively created a telegram agent.
[12:28] Let's go back to the canvas. Let's add a new node and let's search for you guessed it telegram and let's scroll down with this list and select send a text message. Select your credentials, which you created earlier in the chat ID. Grab the same chat ID from the telegram trigger. Then for the text, all we have to do is go to your AI agent and assign this output value like so. Now watch what happens when we press test step. We get our response in telegram, but we
[12:59] also seem to get this text, which is not great. We can remove that by clicking on add field, append n8n attribution and disable this toggle. Let's run this step again and indeed we get our response without the attribution. Awesome. So let's also have a look at sending audio back in n8n. Let's click on test workflow then back in telegram. I'll simply hold in this button and I'll just say anything. Let's release to send it and back in our flow. We can see that we received a new message
[13:30] and looking at the schema. This looks a little bit different instead of receiving the text. We now get this voice node over here, which contains a file ID. So this means we have to handle the situation slightly different depending on the type of message that we received. We can simply add a new node between the telegram trigger node and the AI assistant node. And what we want is the switch node. The switch node will simply allow us to branch down different parts.
[14:00] So in the first rule for the value, what we can do is we can look at this file ID within this voice object. So we'll simply add that to this value field. We want to check if this field exists. So in this drop down, we can go to string and select exists. If this voice file ID exists, we want to branch down the audio path. So I'm actually going to just rename this output to audio. And if you go back to the canvas, you can see we only have this one route at the moment called audio.
[14:31] But of course, we want to do something different if we receive text. So just to simplify this, I'm going to click on test workflow. Back in telegram, I'll just send some basic text and let's open up the switch node. Now this is showing red because this actually doesn't exist. But instead, we have this text property that we received from the telegram trigger. So let's add a new routing rule. Let's add this text field as a value and you guessed it, we'll change this drop down to string and exists. Let's rename this output to text.
[15:03] So back in the canvas, we now have a route for audio and for text. So if we receive text, we can pass that to the AI agent. That's simple enough. But if we receive audio, we have to do something a little bit different. Let's add a new node. Let's just pass an audio file into this flow again. So hello there. How are you doing? Now we can see that this audio triggered this audio route. So the first thing we want to do is to download that audio file. So let's click on add action.
[15:34] Let's search for telegram and let's select get a file. So all we have to do is pass in that file ID, which we can receive on the left hand side under voice. You can grab this file ID and watch what happens when we test this node. This downloaded the file that we received from telegram. I'm just going to rename this node to get audio. Let's click on rename and let's go back to the canvas. Now that we've downloaded this file, we want to transcribe it back into text. So let's click on add nodes.
[16:04] Let's go to open AI and in this list, let's go to transcribe a recording and we actually don't have to change anything in this node. We can test it and now we get the transcribed text from that audio file. And all we have to do now is pass this text to our AI agent. So I'm just going to scoot all of these up and let's pass our text into the AI agent. Now there's one issue with this though. If we have a look at our AI agent, we can see the agent isn't quite happy with us. For the normal text scenario, we're
[16:35] receiving the text within an object called message and within this object is a property called text. However, from the transcription, the value is simply stored in a field called text, not in a messages object. So what I recommend we do is standardize this request that we pass to the agent. After this switch node, let's click on add, then let's search for the set node. Let's select manual mapping, then let's click here to add a new field. Let's call this field text and I would
[17:06] just have to map a value. Let's do that by testing this workflow. Let's pass in some text from Telegram. All right, now let's go back to edit fields. Then let's search for our Telegram trigger node and this is what I was referring to within the Telegram trigger node. We first received this eye level node called message and within message, we received the property called text. So we're just going to simplify this by grabbing text and assigning it to a value called text within this edit field node. I'm just going to rename this node to agent input.
[17:38] Cool, let's go back to the canvas and I'm just going to clean up this canvas a little bit by moving things around. Great, so this simply means whether we received the text from this transcription node or the agent input node, we will always expect a property called text to pass in that value. Well, let's run this workflow to make sure that everything is working. Let's send some text like hello and we get our response back. Great, let's test the audio. So I'll run this again and it's a why is the sky blue?
[18:09] Right, we get the text back from our agent, but usually there's a reason why I send the voice node to begin with. I might be on the move and I don't have time to stop and read. So if I send the voice node, I want this agent to respond with voice as well. So what we can do is add a new node between the agent and this telegram node and what we'll do here is add an if condition and let's just expand this a bit. So what we want to say is let's go to our telegram trigger and
[18:39] what we want to say is if the voice file ID exists, so I'll select string exists and then we want to respond with audio else will simply return text. So we'll leave this node as is. You will now see we have these true and false conditions. So true would mean that we do have audio, false would mean everything else. So we'll simply attach this sent text message to the false condition and if it's true, we want to generate audio instead.
[19:10] So let's click on add nodes. Let's search for open AI and let's go to audio actions and generate audio. Select your open AI credentials. I'm actually just going to rename this node to generate audio and let's just run this scenario so that we can get some data into this flow. So again, I'll just say, hi, how are you doing? Okay, let's let this run. Okay, let's go into our generate audio node. Then for the text input, we'll simply grab the output from our AI agent and add it to
[19:42] this. This is where we can select the voice. I'll simply select Nova, which is that female voice that you heard in the demo. And after this generate audio node, we'll add a new node. We'll search for telegram. Then under message actions, let's look for send an audio file. I'm just going to rename this to audio response like so. And for the chat ID, we can click on schema and let's search for our telegram trigger and let's add the chat ID.
[20:12] Let's enable binary file. And this simply means that it will use the audio file that was generated from the previous node and that's actually it. So let's go back to the canvas. Let's test this workflow. Let's say, hey, how are you doing? All right, so we received the file and let's have a listen. I'm doing well. Thank you. How about you? Great stuff. So we've achieved a lot. We can add text and audio to our agent and our agent is able to respond back with audio as well. Next, let's add vision to our agent.
[20:43] Let's start by testing the workflow and let's send an image via telegram. I'll simply send this. All right, so back in N8N, we can see that our workflow was triggered, but the switch statement realized that this is not audio and it's not text. So what is this? And looking at the input from the trigger, we can see that we now get this photo object, which contains a file ID as well. So what we'll do is we'll add a new routing rule and for the value, I'm actually going to grab this very first photo object,
[21:14] which is an array of images. Well, then change this dropdown to array and exists. An array is simply a list of values. And what telegram does is it actually sends us the image in different file sizes, like the very first result as a width of 90 pixels by 90 pixels. The second image has a size of 320 by 320 pixels. And then the third one is the original image. So all we're saying is if this list
[21:45] exists at all, then we want to go down the image path. So if we go back to the canvas, we now get this image route. And if we receive an image, we want to do the following. I'm simply going to drag it up here. Then we want to download the image first. So we'll search for the telegram node. Let's select get a file, select your credentials. Then for the file ID, I'm simply going to run this node again, which now takes us to this image route. And within this node, I'm just going to
[22:15] rename this to download image. Right then for the file ID, we'll simply go down to photo. And now we can decide which of these images we want to use. I'm going to grab the file ID from the original image, like so. Let's test a step. This simply means the image was indeed downloaded. Then let's go back to the canvas. Let's add a new node. And what we want to do now is use a large language model to analyze the image. So let's add the open AI node. Within this node, let's go to image
[22:45] actions and let's select analyze image. We'll leave the resources image, the operation is analyze image. Then for the model, we can simply select chatgpt40 latest. Then for the prompt, we'll simply leave it as what's in this image for now, but we will change that in a second. This will simply describe the image. Then for the input type, let's select binary file. This simply means it will grab the image from the previous node and that's really it. However, if we run this, we will run into an issue.
[23:17] This is saying that the MIME type is invalid. This node is actually expecting an image like a JPEG, a PNG or something like that. The problem however, is if we have a look at this binary file from the previous node, this is giving us a MIME type of this thing over here, which is not seen as an image. So what we need to do is simply convert this MIME type to an image. Let's go back to the canvas. In between these two nodes, let's add a new node.
[23:48] Let's search for code and let's add the code node. Now please don't run away. This is really not that scary. In fact, you don't have to write this code at all. You will find the code snippet in the description of this video. So simply copy that code and paste it into this field. Then let's go back to the canvas. Let's execute this node again. Let's execute the code node. And in the result of this code node, all we did was change the MIME type to whatever the type was that the user passed originally.
[24:18] Now in this openAI node, I'm just going to rename this by the way to analyze image. Let's rename this. Let's run this step. And look at that. We now get the description of that image. So you guessed it. All we have to do is I'll send this description back to Telegram. And this is really easy. You can simply attach this to the Telegram sent message node. That's it. In Telegram, let's upload an image. But let's also add a caption. This will allow us to ask very specific
[24:49] questions about the image. So let's do, why is this funny? Let's send this. Right. And we actually have an error. And this was expected. And this is kind of the same issue we had with the AI agent where the source field could have different names, depending on where it's being passed from. The Telegram node is expecting the text to come in from a field called output. But to analyze image node, call the field content instead. So we can simply fix that in a very simple way by adding a new node.
[25:22] And as we did earlier, we'll add this edit fields node. We'll add a new field over here. And we know we have to call this field output. And for the value, we'll simply assign content from our analyze image node. Great. Let's test this. Now we're getting the result in this output field. Great. Let's move this edit field up here. I'm just going to rename it as well to format image output. So let's test this again by clicking on test workflow. Then let's send an image again.
[25:53] Let's add a caption like, why is this funny? And we get this response back, simply describing the image. Now of course we asked it why this image is funny, but instead it simply described the image. That is because in this analyze image node, we simply hard coded this instruction, what is in this image. Instead we want to make this dynamic. So we can go to schema. And if we scroll down to our telegram node, all the way to the bottom, we get this caption
[26:24] field which we want to add to this text input. So I'm just going to remove this text. Now we're grabbing the value from the caption. But do keep in mind the caption is optional. And it's possible to send the image without the caption. So what I like to do is to specify a fallback value just in case the user did not supply this. We can add two pipe values. Then in quotes, we can say, describe the image. So we'll first try to use the caption.
[26:54] Otherwise we'll simply run the prompt, describe the image. Great. Let's try this again. So let's upload this image. Let's say, why is this funny? And now we're getting the specific result that we wanted. You now have an AI agent with vision and voice. Our agent is very impressive, but we can greatly improve it. The whole purpose of building a genteq workflows is to have it interact with the world around it. Like answering emails, setting calendar events, searching the
[27:25] internet, and whatever else. So this means that agents are able to execute tools. And tools allow it to interact with its environment. So let's get our agent to read our email and respond to emails on our behalf. Let's click on tools. Then within tools, let's search for Gmail. Under credentials, let's click on create new credential. If you're using the N8 in cloud service, I believe you don't have to specify the client ID and client secret. You should see a button asking you to
[27:56] authenticate with Google. But if you are seeing this client ID and secret, like I am, then this is what you need to do. Go to cloud.google.com and go into the console. Then click on this dropdown to create a new project or select one of your existing projects. Let's create a new project. I'll call mine AI agent tutorial and let's create it. This will only take a few seconds to start up. And afterwards we can select our project. Then let's click on the menu. Let's go to APIs and services.
[28:27] Let's go to library and let's search for the Gmail API. Like so. Let's select Gmail API. Let's enable this API. Then while we're here, let's also set up the calendar API. So let's go to library. Let's search for calendar. Let's select the Google calendar API. Let's enable this. Great. The next thing we need to do is to set up our OAuth consent screen. So let's click on OAuth consent screen. For the user type, let's select external.
[28:58] Let's click on create. Let's give our app a name like AI agent tutorial. Select your support email and scrolling down. Let's enter our developer contact information and let's click on save and continue. We don't have to do anything on this page. Simply click on save and continue. We don't have to do anything on this page either. Simply click on save and continue. And under summary, scroll down to the bottom, click on back to dashboard. And finally, click on publish app.
[29:30] And confirm. We're almost done. Let's click on credentials. Let's click on add credentials and let's select OAuth client ID. Under application type, select web application. Let's give it a name like n8n. Then under authorized redirect URIs, click on add URI and back in n8n, simply copy this redirect URL and paste it into this field. Then click on create. That was a lot, but we finally got there. We now have our client ID, which we can
[30:01] copy and paste into n8n. And we can also copy our client secret and add it to n8n as well. But as I mentioned, I think the cloud service allows you to simply sign in with Google. So let's do that now. Select your email address. If you get this screen, it's perfectly fine. Simply click on advanced and go to whatever your URL might be. Select everything, click on continue. We get our closest pop up as our account is connected. What we want this now to do is to read our emails.
[30:32] So I'm going to rename this to read emails. Let's rename this. Then under operation, let's select get many. I'm going to change the amount of emails to five. Then under filters, I'm going to add label names and IDs. And what I want to select is my inbox only and only unread emails. Right let's go back to the canvas and let's actually move our tools to the bottom of the screen. So let's test this out. I've got this unread email in my inbox.
[31:04] So let's click on test workflow. Back in telegram, let's say summarize my unread emails. So back in eight, we can see the read emails note was indeed called and this is 100% correct. Now we will be adding additional tools to this agent and in order to assist the agent in selecting which tools to call and when I do recommend enhancing the system prompt. This is really easy. In our AI agent node, let's open up our system prompt and under additional information, let's
[31:35] add a new heading called tools. And within this I'll create a sub heading called read emails, which is effectively the name of the tool. And now we can provide a short description to tell the agent when and how to use this tool. So let's simply say use this tool to retrieve unread emails. Right so let's allow our agent to send emails as well. Let's click on tools. Let's open up Gmail. Let's add this node. We'll select our credentials.
[32:05] Make sure the operation is set on send. And now we have to figure out how to get the two email address, the subject and the email body. Now this information should be passed from the large language model. In other words, it's supposed to intelligently figure out what the email address is, the subject line and the body and then pass those values into these fields. So we're not hard coding anything. We're leaving this up to the AI agent. Now how the heck do we do this? NNN makes it super simple.
[32:36] They give us this tip up here. They say simply copy this expression. So let's go ahead and copy this all the way to the closing curly braces. Then in the to field, switch over to expression, then paste in that expression and change the placeholder name to something like email address. Now what we can also do, and this is optional, is we can add a comma, then with in quotes, we can describe this field and this could assist the agent in
[33:07] figuring out how to retrieve this information and in what format this information should be. So I'll simply say the recipient email address. So let's copy this. Then let's do the same thing for the subject line. So let's simply change the name of this field to email subject and let's change the description to the email subject line. And let's remember to change this to an expression. Then let's do the same thing for the message. This changes to expression, then it's
[33:37] pasting this example. It's changed this from email address to email underscore body. And for the description, I'll simply enter the email body. Let's change the email type from HTML to text. Then finally, let's go to add options. Let's go to a paint in NNN attribution and disable this. That should be everything we need. Let's go back to the canvas. Let's move our tool down here. Let's also rename it to send email. I'm actually going to copy this name and
[34:08] in our AI agent, we can add to the system message. So let's add a new tool and paste in that tool's name and it's a use this tool to send emails. This tool requires the recipient email, the email subject and body text. Simple enough. So let's go back to the canvas. Let's click on test workflow. Back in Telegram, I'm just going to send an email to myself. So let's say send an email to Leon Fonsai, dev at Gmail dot com asking Leon if you remember
[34:39] to close his GRI tickets today. It sent this. This is saying the email was sent and back in NNN, we can indeed see that send email was triggered. And if I refresh my inbox, we can see this email coming through with a subject line of GRI ticket follow up. And how awesome is that? Let's do the same thing for setting up calendar events. Let's click on tools. Let's search for Google Calendar tool. I'm going to rename this to get calendar. Other credentials. Let's click on create new credential.
[35:11] Again if you're using the cloud service, you might not need to enter the client ID and secret but for the rest of us, we've already done that hard work. So we can simply copy and paste as values from Google cloud platform and add them to NNN. Let's authenticate ourselves. So I'll select my email address. I'll pick an advanced, continue. Select all these options. Continue. And that's it. Our calendar is now connected. So be sure to select your credentials. Then for operation, let's select get many. Then from list, I'll
[35:42] select my email address. I'll limit the amount of events to 50. And this will simply select all the calendar events from the current date and time. And this is why it was so important to set the time zone at the start of the project. And it will look for events up until a week from now. That's all we have to do. So let's go back to the canvas. Let's just move this tool down and let's add a new entry to the calendar. So let's add something like Jira ticket follow up. Okay, that seems good. Then back in N8N, let's test this workflow.
[36:14] Let's ask it, what are my meetings for today? And indeed we see our Jira ticket follow up session for later this evening. And of course we can see the calendar tool was called. We can also create calendar events by clicking on add nodes. Just search for Google calendar tool, select your credentials under operation, leave it on create. Then for the calendar, simply select your email account. And now we have to figure out what the start and end times will be. Again, we're expecting this information to be populated by the
[36:45] large language model. So we can use that technique that we learned earlier by using this from AI expression. So I'm simply going to copy this expression. Then in the start field, let's paste this in. Let's rename this placeholder to start and let's replace the end node with end. Then under additional fields, let's add the summary field. This is effectively the title of the meeting. And again, I want the AI agent to populate this field. So let's switch over to expression.
[37:16] Let's paste in that placeholder expression. Let's rename this to email title. And that should be it. Go back to the canvas. Let's move this tool down. Let's test this workflow. And in Telegram, let's say create a new event for 8pm today and titled feed the dogs. Now you'll notice something interesting. It's saying that it created this event and we can see the tool was called as well. However, if we refresh our calendar, so
[37:48] let's reload, you will notice that we actually don't see that event. Although it was definitely created. So what the heck happened? We can see the start time was actually set for 2023. That is because the large language model thinks the current date is the 3rd of October 2023. And that was most likely the cut off date of its training data. So we can tell the agent exactly what the current date and time is by going to the system message and under additional information, we can say the current
[38:18] date and time is then in double curly braces, we can select this now variable. And in the preview window, we can see that this is now injecting the current date and time into the prom. So now if we test this again, we can ask it the exact same instruction. And now if we go back to our calendar, we can see that that event was now successfully created. I just want to rename this note. So instead of it being called Google calendar, let's say create event like so.
[38:51] We also want to tell the agent that these two tools are available just to improve its performance. So within this note, let's go to system message. Then let's add a new tool here like get calendar. And let's describe it as use this tool to retrieve events from Google calendar. And it's also do create events and use this tool to create Google calendar events. For the most part, these agents are really good at figuring out which tools to call. But depending on the model that you use, setting the system prompts can definitely
[39:21] make a massive difference. Now we notice that these agents have a training cut off date. That's what the agent thought it was still living in 2023. So this also means that agents do not have access to real time data. But thankfully, we can fix that we can assign a tool that will allow the agent to go online and perform a web search like a Google search. So let's do that now. Let's add a new tool. Then let's search for SERP API, the Google search tool. Then under credentials, let's click on
[39:52] create new credential for the API key, go to SERP API.com and sign in or register for your account. Then simply copy your private key and add it to in it in. Let's save this. The connection was successful. And that's actually all we have to do is test this workflow. And in telegram, let's say, what is the latest AI news? All right, and we just got all of this back, which is super cool. And of course, in it, and we can see that this tool was called
[40:22] and agents are intelligent enough to call more than one tool at a time. So what we could do is the following get the latest AI news from Nvidia and email the report to Leon van Sal dev at gmail.com. So in it, we can see that it's using the SERP API tool to do research. And then it called the send email tool in telegram. It's saying that it sent the email. And if we refresh our emails, we can see this email saying latest AI news from Nvidia, along with those results.
[40:53] This is phenomenal. Now for the final tool. And that is a custom knowledge base. This really is a subject all by itself. And I have several videos on this on my channel. But for this video, we'll load a very simple knowledge base just to demonstrate how this works. Because in the real world, you can upload PDF documents, you can connect us to a database, it could be anything. For this example, I've simply got a list of names along with their email addresses, because
[41:23] realistically, I don't want to specify the entire email address every time I interact with my agent, I simply want to tell it to send an email to john, and it needs to figure out what john's email address is from the knowledge base. This uses a technique called rag. Effectively, the agent will reach out to a database to say, hey, I've got this query, return all the relevant documents related to this query. For instance, the email addresses for someone called john, and those email addresses will
[41:53] then be injected into the AI's prompt. Now that database is a special type of database called a vector database. This is really simple to set up. Go to pinecone.io and sign up for an account. To sign in, click on create index, let's give it a name like n8n tutorial, then under configuration, select text embedding three small, and then simply click on create index. Now we have a vector database, and all we
[42:25] have to do is load documents into this database. Now there's no way to do it directly within pinecone, and you typically won't want to upload it directly in the database either. So what I like to do is within n8n, I'm just going to save this flow, then let's go back to our dashboard, and let's create a new workflow. Let's call this load contacts to knowledge base. And what we can do is add a new trigger. Let's add the on form submission trigger.
[42:56] Let's give this form a title like contacts. Then for the label, let's call this my contacts. Let's change the field type from text to file. We'll only upload one file at a time, and this is actually it. So let's click on test step. This will open up our form. So I'll select my CSV document containing all the contacts, and let's submit this. All right, we can go ahead and close this form, and we can see that the contacts were indeed loaded. So all we have to do now is click on add
[43:26] node, then under search nodes, let's search for pinecone and add documents to vector store. Under credentials, click on create new credential. And for the API key, we can get that from pinecone by going to API keys. Then let's create a new key. Let's call this n8n tutorial. Click on create key. Let's copy this key and add it to n8n. Let's close this popup. Then for the index, let's select the one we created earlier.
[43:56] And what I also like to do is to set a namespace. And that is because you can reuse this index for all your different projects. I'll simply call this contacts. Then let's go back to the canvas. And this node requires an embedding. So let's go to embeddings. Let's select embeddings open AI. Let's select text embedding 3 small. And then under the document loader, let's select the default document loader. So the type of data changes to binary because we want to grab
[44:27] the file that we loaded from the previous node. And let's go back to the canvas. And finally, let's add a text splitter. And let's add the recursive character text splitter. We can leave this on the default values. And all we have to do is click on test workflow. Let's select our file. Let's click on submit. We can see that this loaded six items into the vector store. So if we go back to pinecone, let's go to database. And it in tutorial, we can see that we now have six records. And if we have a look at these records,
[44:58] we can see that it's the name along with the email address for each of these. Great. So now we have a workflow that we can use to load data into our database. But now how do we use this database as a tool in our agent? Let's go back to our agent. Let's add a tool. And let's search for pinecone. Select your credentials. Let's call this contacts. And for the description, let's enter, use this tool to retrieve email addresses of contacts.
[45:28] Then for the pinecone index, we'll simply select our index. We'll only return the four most relevant documents. And under options, let's select namespace. And we called our namespace contacts as well. Let's go back to the canvas. Let's move this tool back to our other tools. Let's select the embedding model. So I will select embedding's open AI. Believe it on text embedding3small. And believe it or not, but that should be it. This test is out. So let's go to test workflow.
[45:59] And let's send an email to Alice with an email address of alice.jonsson at example.com. So let's try this. Send an email to Jane, inviting her to my party tomorrow at 7pm. All right. Apparently the invite was sent. Let's have a look. You can see that our vector store was indeed called. And then the email note was called. And looking at my sent emails, we can see that Jane was emailed. So it's jane.smith at example.com inviting her to our party.
[46:29] If you made it this far, then I want to congratulate you. And thank you for spending this time with me. If you enjoyed this video, then please hit the like button and subscribe. And check out these other NNN videos on my channel so that you can become a master of building AI agents in 2025.