The Best Way to Give AI Agents Tools in n8n

Dr. Violet Howard shows how to use n8n's $fromAI function to let AI agents extract parameters directly from user requests instead of parsing them separately. The new method works with tools like Gmail and Google Calendar, handles optional fields like CC and event end times, and reduces workflow brittleness.
Chapters
So today I wanted to come in here and talk about the most powerful AI agent tools in N8N. N8N is getting smarter every day. The whole AI space is getting smarter every day. Everything's moving and shifting so fast. So I wanted to come in here and show you guys a new method that I've been working on when I build AI agents that is just a lot easier to set up, to be honest. Make sure you guys stick around to the end of this one because I'm going to get into N8N and just do a live build of showing off this new method. So when it comes to building AI agents in N8N, one of the things that's so powerful is that you're able to build a workflow as a tool, and then have the agent call that. So here's the old method. Let's say for example, we're having this AI agent send emails for us as we talk to it. So we talk to it and then the agent figures out what it needs to do, and then it's gonna send off the query to the send email tool, which is actually a workflow that we've built within N8N. So here's that tool that I was just referring to. It's going to get called by the agent and it's gonna have that initial query that's gonna say something like, can you send an email to blank saying blank? All this kind of stuff. And so then after that, it's going to pass it through an OpenAI node or some sort of code node or something just to structure it the way we need to feed it into Gmail. And I'll get all into this in a sec. This is just a high-level overview. And then finally, we have the information we need in Gmail, different parameters like who's the— who is this email going to, what is the subject going to be, what is the body. So that is sort of what's going on here is we were taking the query and then making it, you know, assigned to certain parameters that would feed correctly into the Gmail node so that we could send it off and then tell our agent that we did that. So this is the OpenAI node or whatever you want to use to sort of structure the query correctly. As you can see, it comes through over here, um, with different parameters like who it's going to, subject, that kind of stuff. And then within here, we just needed to make sure that it was feeding in exactly how we wanted it. So we wanted it to take the query and output the parameters separately over here. So we can see exactly send to is going to be natehurk88@gmail.com. We'd have a subject, we'd have an email type message, and then we'd have all this other stuff if we needed it to come through. And it had to come through exactly like this. So now we're in the Gmail node that actually sends the email. As you can see, we have our variables here that's going to feed in with the actual information. And this is how it used to work because we had to have send to had to always be Send To with a capital T. Any changes like that and the automation would break because it wouldn't know who to send the email to. Same thing with, um,.subject. We needed it to always be subject. And then you guys get the point. It just had to be filled in exactly like this, otherwise the automation would break. So this new method, like I said, I think it's a lot more efficient. It's also a lot less of a headache to set up and test. Um, and it's basically just using a function within the specific tool like Gmail or Calendar where you can use this function called, um, fromAI, and then you can fill in different parameters. So this is basically baking in that OpenAI node where earlier, if I go back real quick, we would have OpenAI figure out what the query was saying and then fill in the correct parameters. As you can see, send to subject, all this kind of stuff. But using this function now, it pretty much is one step that combines everything that we just did in that send email workflow because the AI is going to be able to figure out dynamically in those parameters what to put. So like I said, the old method was The agent sends it off to a new workflow, and this workflow goes through the process of parsing the information out and then putting it in the Gmail node and then sending off the email. But now we have this new method where the agent can just send it to one tool. It doesn't leave, it doesn't go to a different workflow, it stays in this workflow, and this node right here is able to figure out who it's going to, the subject, and what the message is going to say. Real quick, just wanted to plug the FreeSchool community. The link for that is down in the description. We're almost at 1,000 members, which is super, super exciting, and really appreciate all the support so far. But yeah, a lot of people ask me for, you know, templates from the videos or different code snippets or whatever. So that's where you're gonna find resources like this, YouTube resources. You'll have information here about how to download the templates and plug it into your n8n so you're good to go. And obviously a great place to be if you're learning n8n and you want some support with figuring out stuff that's going on in your specific workflows. Also wanted to quickly announce this paid community that I just launched. Here's some modules that we're working on. Um, still need to pump out more content, but this will be a great place to start off if you want to succeed in the world of AI. In this paid community, you're always guaranteed to get a response. You're guaranteed to make some meaningful connections and have some good opportunities to collaborate in the future. And also everything that I learn, as soon as I learn it, whether it's N8N or different tools, I'm pretty much gonna talk about that kind of stuff in this community. And you know, we'll also have live calls and stuff like that. So. That's all I really wanted to say. Let's get back to the video. So how that works is with the function $fromAI, and in a sec I'm going to break down the function parameters and it's really, really simple. It may look a little intimidating when you see the different, you know, parameters and the different things you need to fill in, but it's super, super simple. So as you can see, this looks like a normal Gmail send email node. Nothing has changed. The only thing that changed is that instead of using, you know, JSON.message.content.sendTo, anything like that, the hardcoded variables we have in there, it's gonna be dynamic because all we're saying is from AI, it needs to figure out what the email is. AI needs to figure out what the subject is, and AI needs to figure out what the email body is gonna be. And so just zooming in a little bit, I have a couple typos in this query so you can even just see that it works really well. Send an email to Michael Scott asking him how, if he wants to get lunch today. His email address is @michaelscott@dundermifflin.com. So then all we had to do was tell AI, for the to field in the Gmail node, AI needs to figure out what the email is to send to. So we told it email, and it grabbed Michael Scott from the query, and it also left out that in the beginning, which is super cool. And then the subject— based on this query, it had to make a subject, and the subject, as you can see, is lunch plans with a question mark. And then finally, the message— we gave it from AI, needs to figure out the email body, and we can see the email body came back: Hi Michael, I was wondering if you'd like to get Lunch today, let me know what you think, best Nate. So, like I said, normally you'd get the query and you'd have to run it through some sort of OpenAI node or, you know, a custom code node to put these in the different parameters to feed into Gmail. But now Gmail node can just figure it out by itself based on this super cool JavaScript function from AI. And then real quick, just another comparison to show you guys the value in this function. This is the old method. We'd have sendTo, subject, email. And like I said, if you didn't map it correctly or if OpenAI decided to change this to send to without a capital T, it would break and it wouldn't send over that Gmail. But now over here we have the query and then the actual Gmail node over here is gonna be smart enough based on these from AI functions because like I said, it just, it's like you're asking Siri, could you send a text to mom saying, hi, I miss you. That way, Siri knows who mom is. Siri knows what the text is gonna say, all that kind of stuff. It's pretty much like an assistant that will be able to figure out the query and just interpret what to put here. Okay, so now we're gonna get into just setting up this function. This shouldn't take too long. It's really, really simple. If you have used Excel before, it's pretty much the same way you sort of do an Excel formula, a simple Excel formula, not something like a crazy VLOOKUP. But so there's different parameters in the From AI node. You would do $fromai, and that's how it knows. Obviously you need the curly brackets so it knows that it's JavaScript. But then you just need to put a key, and a key is the only thing that's required. These question marks are optional fields, but a key, description, type, and then a default value. So let's break this down really, really simple so you guys can get in there and start playing with these tools. Okay, so the first parameter, like we said, is a key, the most important one because it's the only one that's actually required. So the key is basically just what is the AI looking for? So in this case, let's say you wanted to fill in and get the name of a person automatically every time. You would just put from AI name, and then the AI knows that it's looking for a name. Super simple. Then you have the option to add a description. So if it's not as simple as a name or a time, maybe you could put a description so that the AI doesn't get confused. In this case, we're sticking with the example of a name, and then the description could just be the name of the person we're emailing. So super simple there too. Then we have the type. Once again, it's optional. This is just what kind of data the AI should be looking for to make it easier in case it was looking for a number rather than a string. String is just basically a word. So the type, same example with get the name of a person, we would be expecting a word coming through, a string, not a number or a Boolean or JSON. Then finally, we have default value. This is pretty cool too. If the AI can't figure out what you're looking for, so if the AI couldn't find a name, in this case, it would just reply with unknown. So it's a nice little backup option in case the AI can't figure out exactly what you're looking for, it won't break the automation. The node will still run and you might just get unknown rather than a name or something like that. I'll go through two quick simple examples just to make sure everything's pieced together correctly in our minds. So the first example, let's say we're getting a customer's name and obviously this wants to go into some sort of node. We would use the function, two curly brackets, dollar sign from AI, and then we fill in our parameters. So we're looking for the name, the description is the customer's name, The AI should be expecting a string, and then if it can't find the name, it will just return the value of guest. So what this is going to do is ask for the customer's name. If the assistant doesn't know, it'll say guest. And it's useful because even if the AI doesn't know the name, you still have something to call the person. Let's say it's sending through an email and you want to say hi to them. You would maybe— it would just say hi guest rather than their name. Here's another example. This time we're doing a number. So counting completed tasks, we would tell the AI that we're looking for completed tasks. This means how many tasks are done. If maybe if a task is marked off a certain way within a database, you could say when task equals 1, that would— that's how you know it's completed. And then you're looking for a number, and if the AI can't find out how many tasks are completed, it will return 0 right here. So why this is useful is because you can use it for tracking progress without worrying about missing data. So I know in these slides I mainly just talked about the Gmail tool, which is right here as you can see, but these are all the other ones that you have access to give an AI agent. In N8N. So we have Airtable, we have, you know, Calendar, Docs. You can also do stuff dynamically in Telegram or Outlook, whatever you want to, you know, get in there and play around with. But I believe that they're going to keep continuing to expand on these tools. But just super cool, pretty much all these you can use that function from AI in there, and it's really going to save a lot of time as far as not having to configure more workflows and all that kind of stuff. I definitely still think it's important to not give an AI agent like 30 different tools because, you know, within Gmail you could have different options as far as, you know, getting messages, sending messages, labeling stuff, making drafts, replying, all this kind of stuff. So that's a good use case where you still probably want to have a dedicated email agent that would have these tools. But just super cool, all the options you have, you know, Slack, all this kind of stuff. So yeah, let's get into N8N and just look at a few examples of this. Okay, so we're just going to do a live walkthrough of having an agent call a couple different tools and using the functions within the tools. So let's grab an AI agent. We'll leave it as a tools agent for now. Obviously, we're just going to connect the brain real quick. I'm just going to keep it as 4L mini. That should be good. And so that's all we're going to do as far as the agent setup. We'll give it a quick prompt. Actually, we'll just do that right now. So pretty much all I want to throw in here as far as a prompt is just giving it the current date and time. So here's the current date. And we will just do— of course we need to make this an expression so that we can call the JavaScript and do $now. So now it's got the current date and time, which is good in case we want to make calendar events. So yeah, actually we'll do a calendar tool first because the example pretty much always did, or the examples from the slides we ran through email. So we're going to be creating an event first. Sync up the calendar, and now we have start time, end time. Obviously we need that information for a calendar event, and then we just want to add a summary because that's going to be the title that comes through in, in Google Calendar. So if you guys watch my personal assistant video, Personal Assistant 2.0, you probably noticed that I used some of these tools to help the calendar agent or the email agent. And one of the things that I did is said like, if us— if an end time isn't specified, because sometimes you want to just be like, can you throw down a meeting at noon? And in that case, it— I don't know what exactly would happen, but we specified if there's no end time, then just assume that it's going to be 30 minutes or however long. So let's first start off with an example where we will give it start time and end time. So we're going to fill out these parameters. We don't want to make it fixed, we need to make sure it's an expression. Otherwise, if you go to type in the curly brackets nothing's going to pop up. So make sure you hit expression curly brackets. You can see right here we've got fromai down at the bottom, so we'll just click into there. And so if my slides weren't good enough for you guys, you can always see right here how to set this up. You've got your key, your description, your type, your default value. It's going to show you an example and it's going to show you for each of the parameters sort of what you should be doing and how it works, and some examples at the bottom of course. So for this node, we're going to try this without using any descriptions. We're just going to do keys. So this key is start time. Let me just copy this down to the end time, make sure it's an expression of course. And then we just want to call this one end time rather than start time. So we've got our start time, our end time, and then for summary we are just going to do, um, maybe like event. We'll just say event. Yeah, okay, so we've got start time, end time, and event, and it's already pretty much configured. That's so much easier than if we were to, you know, from the agent gets the query and then we'd have to put something here to make sure that it's going to pass into the parameters of the Gmail— or sorry, the calendar node properly. But now we just have the AI smart enough to figure out what needs to go where. So we'll chat with this guy and make sure it's working. Let's say, can you create an event from 2 PM to 4 PM called, or not called, we'll just say for a meeting and see if the AI can figure out what we're asking for here. Obviously it's going to hit the calendar tool. It's the only tool it's got. It's already done. It said meeting has been successfully created. And let's check right there in the calendar. We've got meeting from 2 to 4 PM, as you can see. Um, so perfect. That was maybe like 2 minutes that we already pretty much set up a calendar agent. We can say, um, let's just see what happens if we don't specify an end time. So, can you schedule dinner for 6 PM tonight? See what happens here. I love watching the stuff happen in real time. I think that's so cool, the visual aspect of it. But we've got dinner from 6 to 7, so that's nice. It said to us, I have scheduled dinner for you tonight at 6 PM. You can view the event here. And it just made it an hour, and we didn't even specify, um, all we gave it was current date and time. We didn't say, you know, if an end, if an end time isn't specified, make it an hour. So that's sort of how that works. Let's go into the execution and see what it filled in here. So as you can see, it got the start time, end time, and the event called it dinner. So yeah, hopefully you guys can see already how quick that was and how easy that was to set up a tool that does something very intelligently, I guess, is a good word to say. So I guess we did an email example, we might as well just do that. And I've already got my stuff configured in here, so I'm just going to sign in real quick again to make sure that we're good to go. Okay, okay, let's turn green. Perfect. All right, so sure, we'll send a message. So we need the to, we need the subject, and we need the message, of course. Let's see, let's do something cool with like, um, let's CC somebody. Okay, so we'll CC somebody. The to is obviously going to be, um, nope, forgot the dollar sign. Okay, so from AI and to, we don't want to just say like name because this has to be an email address. Because it's, you know, what, who the Gmail node is going to send email to. So I will say, I'll just say email address in this case. And we'll try once again without doing descriptions because it really should work most of the time without needing a description unless it's something more complicated. So oops, we'll grab from AI and we will say subject for this one. Make sure you always close it off in the parentheses. And then for the message, we will grab make an expression. We will call this, um, just message. Super simple. Okay. And then CC, I haven't really tested out a CC, so we'll see what happens here. But honestly, let's just see if we just leave it as CC, um, and see if it understands if I just say, can you copy blank? So test out the email tool. Um, let's see, anything we need to do in the prompting for this guy? We shouldn't really have to. Let's just say you send an email to NateHirk88@gmail.com asking him how the project Panda is coming along and reminding him to bring the brief tomorrow. Can you make sure to copy? Um, I'm gonna need like a— okay, bitdigital@gmail.com on the email. Okay, let's see. It's hitting Gmail. Perfect. That was quick. Um, let's go into the execution real quick and then I'll pull up the email. Make sure everything worked here. Okay, so it filled in natehurk@gmail.com. Project Panda update was the subject. The message coming through— can we see how this came through? Hi Nate, I hope this message finds you well. I wanted to check in and see how Project Panda is coming along. Also, please remember to bring the brief with you tomorrow. Looking forward to hearing from you soon. Best, your name. So we didn't prompt in a sender name or anything, so that's why it came through like that. And it CC'd up@digital@gmail.com. So pretty cool, it understood how to do that. And that's, like I said, it's super powerful. Obviously the AI understands what a CC is and you didn't even have to give it a description. So that's pretty cool. I'll come into here again. A security alert. Let's see if we got an email though. There we go, Project Panda update to me with the CC of up@digital@gmail.com. And we didn't turn off the attribution, so we get the message email was sent automatically with N8N. Um, so yeah, that's pretty much how it works. I hope you guys can see the value in this. Obviously, like I said, there's tons of more tools to explore. So, um, will definitely be cool to, you know, play around with maybe doing that as an HTTP request or, you know, stuff like Airtable, seeing how we could do stuff with a SERP API, that sort of thing. Even seeing how it's going to work in like a vector store would be cool. So let me know what else you guys want to see based on these sort of tools. And obviously I utilized this kind of stuff in the Personal Assistant 2.0, and I'll definitely want to keep building on that. Yeah, hopefully this was a little bit— hopefully you learned something from this video. But that is all for now, so thanks guys.










