Building AI Agents: Prompt Engineering for Beginners [Part 3]

10.03k views9056 WordsCopy TextShare
n8n
Watch Part 1: https://www.youtube.com/watch?v=yzvLfHb0nqE Follow Max on LinkedIn: https://www.linked...
Video Transcript:
hey welcome to part three of the building AI agents tutorial Series in part one we covered Basics like what AI agents are how to use tools and memory and if you don't know what I'm talking about go watch part 1 and two then come right back here in this video we're going to focus on prompt engineering specifically for single task AI agents so an AI agent is software that can autonomously complete tasks on your behalf now some people say they're all hype and not production ready While others are seeing success by using them because they're
deploying agentic use cases where they have well-defined tasks with well-defined scope there are countless well-defined tasks out there from booking an appointment to working inside of a CRM on the specific task plus it's fairly easy to add some sort of intent routing before your agentic steps in your workflows so that's why we're going to focus on single task so you can learn the best practices around getting a task done which you then can apply to having a multitask agent but I highly highly advise especially if you're getting started out focus on having your AI agent
do one thing well and then expand from there with various different strategies that we can get into in follow-up videos so do drop a comment if you'd like me to get into that after watching this the biggest lever you have in driving the success outcomes of an agentic solution that you're working on is impr prompt engineering there's other things like tool calling and even fine-tuning and Distilling of llm models that you can do but prompt engineering is going to have the high highest effort to impact ratio so how I like to think of prompt engineering
is it's essentially an instruction manual that you're giving to an intern and you work at a company that has async work culture you're the manager and your job is to onboard this person have them complete tasks and create business value by only handing them off this manual and you're not allowed to talk to them so you might be able to update that manual over time but the success of your employee that's been assigned to you is wholly predicated on you handing them off a manual that is self-evident clear and has the relevant context to teaches
them how to use tools that they might need to get tasks done teaches them the order of those tasks and perhaps gives them relevant examples of how that task is done so prompt engineering is the handbook you give that intern that's going to be true today and over the next few years even as the AI landscape evolves that intern may become a junior that intern may even become a senior with some of the model Evolution that we're seeing right now either way you're still for the foreseeable future going to need to be able to instruct
them precisely on how to do the things that you want to draw the outcomes that you need for yourself or your business I'll also call out that this is going to be specific guidance for AI agent prompt engineering when I was doing my research I actually saw a lot of guidance that wasn't particularly relevant in AI agents those tutorials we're assuming that you're working with just raw LMS so everything you're going to learn here is specifically for how to build AI agents and throughout this series we're using n8n a work for automation tool with some
pretty Kick-Ass AI agent building features in them if you want to follow along on our Cloud product make sure should use my coupon code Max 50 to get 50% off for 12 months you can also self-host all right without further Ado let's jump in I like to think of prompting occurring on three distinct different layers within an agentic system the first layer is the system layer and this is where you're specifying the role of the AI agent its rules how to complete the task and certain types of context then in Layer Two we'll have a
look at the input layer a gentic system expected input this is the Quest the task and then they output based on that task and then thirdly there's the action layer so there's various tools and functions that AI agents can leverage and those tools need descriptions and definitions so the AI agent can use those successfully so that all happens in layer three the action layer so let's jump into n8n and have a look at layer one the system layer so I'm in the work for canvas in NN and I've got a basic AI agent in here
so I've got a chat trigger connected to my AI agent and I'm using a Google Gemini model here but again you could use a different chat model in this system layer we're going to go over a few different aspects to build out that system layer that system prompt and the first one is role prompting so role prompting is explaining to the AI agent what their role is who they are not necessarily what they're doing although there the elements of that but it's the who they are so I like to think of this as the first
couple sentences in a job description and the reason roles can be helpful is as you see here we're going to add instructions we're going to add rules we're going to give it quite some guidance on how to do its things but by defining a role we give it this you know 50,000 foot view of context when there's ambiguous situations so that's why role prompting is a good first thing to do because it sets the frame of who the AI agent is and what they'll be doing let's open up my AI agent and Define that role
prompt now as I teach all these different skills in this video we're going to do it by building a booking assistant for a beauty salon now I just picked a beauty salon so there's something specific and concrete and you can see how that informs the words that I basically pick that go into my prompts but this can be applied to any use case okay let's open up the AI agent and the role prompt and all everything you're going to see in the system layer is defined in the system message so to add one we click
in options here and we add a system message there is a default system message added here we can see it saying you are a helpful assistant that is role prompting it's really basic really simple rle prompt but that's rle prompting let's clear that however and write our own before I do that have a bit more working room let's just expand our parameter pane here and actually some users don't know about that so yeah you can expand that and move it about which is helpful I'm going to paste it in but then we'll walk through it
you are a scheduling assistant working for a beauty salon Your Role is to help customers schedule an appointment in the beauty salon's calendar okay what am I doing at a very high level my roles typically have a format of UR dot dot dot your role is dot dot dot the UR does not define their type task it doesn't mention it defines who they are you're a scheduling assistant working for a beauty salon I see a lot of folks perhaps at this stage they would say you're a Google Calendar assistant that actually doesn't provide a lot
of context to the a agent on what they're supposed to do how they're supposed to interact perhaps a Google Calendar assistant could be a virtual assistant whose job is to make sure that things are booked really close to each other so they're super efficient versus a customer service that might not be as important to you making the customer happy might be so role provides that very high level context to guide it you're a scheduling assistant this would make sense if it was a person as well and your role is to help customers schedule an appointment
in the beauty salon's calendar so few points to point out I mentioned beauty salon here and I use the exact same words here so AI models are able to understand semantic similarity between things so if I just wrote Salon that would still work but it's a better practice to use the exact same word because it's going to be a stronger match and then in this role I am lightly giving content to what it will be doing in terms of a task but I'm not specifically defining it right I'm not saying Google Calendar here if you
did it probably wouldn't be an issue but that's one thing is trying to separate concerns so we'll Define in the tool that we use the Google Calendar tools we'll Define that it's Google Calendar at this stage it's better to separate that out because what if we switch calendars in future you might have an issue because you're saying Google in your role prompt so you keep it high level here this is a sufficient rle prompt for the scope of our agent and since we're going to be adding other sections we're going to actually use a markdown
format here so this is a H1 title and just write roll here if you're writing short system messages you don't really need this it's firstly helpful for yourself and then when your system messages get larger it can be helpful for the AI agent although I expect that its efficacy will reduce over time as AI models get smarter with the role prompting done let's define the list of instructions the AI agent should follow when completing the task now this is a balancing act because if we're too prescriptive in the steps and end up defining a workflow
we lose the autonomous benefits of an AI agent so this is giving it the highlevel steps kind of like if you were completing a task you might think of it at a very high level before you go do that task which might help you improve how you do that task same thing here let's open up the AI agent and let's add a instruction section now what's going to happen next is we're going to have a list of instructions like number one number two it's going to be a number list since this is an instruction manual
to an AI agent in sort of a first-person voice what we can do to improve this list before we add those numbered steps is preface it follow the following steps to book an appointment for the user and then the list of steps if this was a copyrighting class follow the following steps doesn't sound very good but the AI agent isn't going to be judging you on your copyrighting in that regard what I encourage you to do before you write out AI steps is have a quick think like as a human what you would do so
we're a booking assistant for a salon right so someone calls what happens first thing is the assistant says well which day would you like an appointment and then it takes the user's day and it checks for that day there's going to be availabilities or there's not so either it's going to have to ask the user hey that day is not available is there another day and then it'll find some availabilities for a day and then it'll ask the user hey here's availabilities which would you like the user will say and then it will attempt to
book it before that it needs to make sure it has all the information needs from the user their name their email right to book that and then it books that that is successful or not and then it replies to the user so quite a few cases that could happen quite a few situations I mean the user might say hey what about Sunday they're not open on Sunday right there's all these details here but let's break this down into the key parts and then allow our AI agent to make decisions within those steps so for step
one we want to ask the user for their preferred appointment Day first person voice nice and clear and again here we're saying appointment because here we said appointment and here we're saying appointment using the same ter um throughout these for consistency so next now that we have the users preferred day we need to go check the calendar and see if there's any availability for that day so use the check calendar availability tool to identify free time slots for the user specified day this tool doesn't exist yet but when we do we're going to name it
exactly this and every time we refer to that tool in roll prompting we're always going to use exactly that name that is a best practice now one thing you're going to notice here I'm saying the user the user the user why here you'll notice I said customer this is because in the role it is helping customers and how one might interact with customers could be very different to how you interact with a vendor for example now you might be polite in both cases but again there's a lot of nuance in how you might interact in
that social interpersonal interaction thing is when it comes to instructions here the instructions are interacting with things the user will write and that is the user message that's the entity through which the user on the input layer is delivering this that's what the llm the the AI model understands it as there's user messages and there's system messages under the hood to the llm model so by saying the user that's going to be much stronger connotation with like the other input I'm receiving from an actor from an entity that I know as the user so that's
why you say the user here when it's like Specific Instructions that interacting with the inputs from the user one thing to note when we actually use that tool what we're actually going to have to do is for a day Define midnight of that day till 1159 of that day pull the all the actual events and then find the space in between and that's what the availability is but we're not defining that here that is something we'll Define at the tool level because that's how Gmail is going to work but if we swap it in future
we Define it here and there it's all messy so we're separating those concerns so here the step is to identify free time slot the tool that helps you do that will Define how to do that specifically next we need to show the user these slots and capture their preference so show the US available time slots for the preferred day and get from user the time slot they would like to book an appointment for if there are no available slots for the day start from step one again and ask the user for a new day preference
few things to point out reference steps you have numbered steps you can reference them that's why I use number steps not bullet points next the English here is not so good right like my English teacher would be very upset that I'm ending on a four here but it is specific and it's like verbose to where it would be bad if I was writing this as an article but it's clear it just might not be very elegant that's okay so next we've gotten a preference from the user for time slot that is available and now we
need to ask the user for the information you require to book the calendar appointment in order to book the appointment you need the user's full name and email so interesting pattern I've chosen here is I'm asking it to get information from the user and then afterwards I'm giving it some context on what it needs now here I didn't say it only needs that by saying ask the user for the information you require you give agency to your AI agent what I mean by that is if the tool to book the calendar appointment requires a phone
number or in future has optional things and whatnot that is going to look like a form for the AIG to fill out imagine this was a real person and you're like hey look this is the app that you used to book in Google Calendar they're going to see a form of stuff to fill out that human would infer okay I need to capture this information to book the appointment because I can't click the button until I fill it out that's the same thing the AI agent is going to be thinking when it looks at your
tool so by saying ask the user for the information you requireed to book the calendar appointment you're giving it some agency but then also some God rails because you know it's going to need name an email then in the tool itself you will be defining all the other things it might need as well so it's a bit of a hybrid here removing this could also be acceptable if you want to completely separate concerns and have that only defined in the tool all right Next Step use the create calendar appointment tool again we haven't created that
yet to book the appointment for the user using details captured from step five okay so the agent's going to try and use that tool that's going to work or not work right tools can fail every system can fail so once the appointment is booked notify the user with relevant details for their appointment notify user if it was not possible to create the appointment I'm defining what it should do here I'm not going into too much detail the reason is notify the user with relevant details I could explain a lot on what that is but because
we're going to later show F shot prompting which is providing examples showing it how you would like to show the information for successful booking is going to be a lot easier to show be an example so that's what I'm going to do there we've got instructions booked what's next now that we've added Ro prompting and some instructions the next thing is to Define rules now rules is basically a list of that went wrong while you were building or when you were in prod and you're kind of reverse engineering how to fix that case that's usually
what my rules list looks like I might have one or two preemptive ones that are really important for the use case going in but this is a really quick section so I'll open up my AI agent here in the system message we've got the role we got the instructions let's add another section called rules so in here for my use case I've got two preemptive rules but again from testing if you need to add stuff this is where I would add it always use utc+1 time zone when using tools or their outputs so I wanted
to use UTC plus1 because my beauty salon is in Berlin and it would be kind of weird if it's like you call somewhere or you're texting somewhere local like in your town it's like dealing with time zone stuff so just assume UTC plus1 now that's a rule it could also be a context like later along we might say hey the beauty salon is in Berlin but it's a rule that it should always use UTC plus1 so separate from the context right even though you might want to reiterate in that context that they operate in a
UTC plus next don't make things up ask the user a clarifying question if you need additional information to complete your task so while I've placed this in the rule section this is an example of a few things actually so don't make things up is you're telling it don't hallucinate that's a very simple strategy for having it not hallucinate not making things up there are more complicated ones but so we sew that and we say to ask the user clarifying questions if you need additional information to complete your task it's usually a good one you give
the AI agent an exit hatch or a way to kind of like get more context from the human which is arguably maybe the best tool it has for helping with its task because here we're being very prescriptive on what it should do so we give it this now again only two rules here as we build this we might add one or two here if we were testing it or once it's live for example a rule might be always talk in English because even though they AI agent can talk 12 different languages actually that causes problems
for our Ops because then people think they can talk with the people in Ukrainian or something right so that that could mess it up so this is where we would add those all right so that's rules now let's look at F shot prompting before we get into fuse shot prompting let's talk about what a shot is so this is different from shots fired right this is shots in the context of an llm model and think of it is basically just an example so if someone said that my AI agent has a one shot prompt that
means they give it one example perhaps it's an example of the expected output or an intermediary step and they expect that the AI agent can complete the task based on that one example if they provide multiple examples this can be fuse shot prompting multi-shot prompting or n shot prompting if you got a bit of a math background and you like to sound fancy now as a human if you're given a couple examples of things you're probably going to have an easier time doing a task same thing for an llm shots can be added at different
layers of our prompt engineering system message is a Common Place the user message can be a common one but not for our use case where we have a chat interaction that might be the case more when you're having something programmatic where again you're using that user message and creating that user message based on static and and dynamic data and sending it in and in and AI agents have this concept of structured output so if I check this to true I get the output parser Branch here and I can add a structured output parser this allows
me to define the format that I would like the AI agent to Output its final step now this is not as helpful when you're using a chat trigger use case because here we're expecting a text that comes out that then gets served back to the user the user chats with it sends back and the loop continues but this could be useful for programmatic use casee where we need this to be a rather specific jent object because we're programmatically consuming it down the line so if I provided a jent example in here this would be a
shot now you can provide adjacent example or you can use adjacent schema if you're not familiar with adjacent schemas use chpt to help you provide an example of the Json you want say hey turn this into Json schema cuz in Json schema you can set the type if it's required and what there's quite some flexibility there most of the time I am providing an example but this is only for the structured output of your AI agent step what comes out at the end so for our use case that's not as relevant what I want to
provide an example of or a few shots of is how the AI agent should communicate to the user via chat when the booking is successful and when a nice consistent message that gives the user confidence that their booking has been booked to do that let's open up our AI agent and go into my system message and then underneath rules we're going to add another section and call this examples now since I mentioned that there could be a few different types of example like we might provide an example of what we want the success booking to
look like we might also say hey look here's a three example threads this is how we want your voice and tone to sound like so again here underneath examples we're going to employ these prefaces before we add the examples so for the first one use the the following examples when notifying the user that you've successfully booked their appointment so these are examples just for that message once the booking is successful let me paste in my first example let's have a look I have successfully booked her appointment here are the details we're using markdown formatting so
date and time and email for booking will be bolded because of these asterisks and here we have the time and date the format we're saying the date and time 24-hour clock on Wednesday we mention the day and then the month and year email for booking Jane ato.com and then if you need to cancel your appointment please call a specific number so this is how we'd like them generally to look like and we want to provide an example instead of defining every single rule of everything like it should be in the 24-hour clock and this and
this because it's less effort less tokens faster more efficient and can provide some context maybe a list of rules can't a few things we can do to improve it the first thing is the AI agent might not know where the example starts and stops especially if we got stuff after this so we can wrap it in an example tag now this example tag it's kind of like pseudo XML in here I know that we're then mixing markdown and XML for organizing my things the reason I'm using XML here is because it has a start and
an end you could say the same case for these examples these themselves could also be XML at the end of the day most Frontier models that I'm using today these models were totally fine with this mix and match and this is what works best for me if you wanted to use markdown in here for example something like example one that probably will also work so there is a preference I will say that anthropic models were trained trained more on XML data that could change over time but they are used to XML a bit more open
AI models were trained a bit more in markdown but again this sophisticated models and this is not very complicated XML or syntax so again there is a bit of a preference to it so I have my example this would be technically a onshot example and with only one example it's not really sure what's placeholder and what needs to be swapped out or not right so let's strengthen it by adding another one if I paste it in we'll notice some differences and I thoughtfully chose and created example to be a contrast to the other example so
the way I like to think about examples is there's a canvas of good that I'm trying to explain to the AI agent if they paint here it's bad if they paint here it's good when I pick my examples I try to pick examples that are kind of defining that box so it understands the difference between the examples and what's consistent between the examples because those are both different concepts and both useful to helping the AI agent understand what good looks like so you'll notice with a 24-hour cook I have one example that's after 12 and
one example before 12 that's rather clear it's a 24-hour clock as soon as I've seen something above 12 the next thing is here I'm using a very placeholder email now because again LM are trained on millions and millions and billions of characters out on the world think in the states Jane Doe John Doe is a very common way for placeholder names so there's probably going to be a lot of characters around like Mark and placeholder and stuff if I only use Jane Doe exclusively it might give too much weight to Jane and doe which is
why here I'm using a fake email for our CEO so don't email that email it doesn't exist and so that's providing again different points to paint that picture of of the canvas of good that we want instruct it to follow another thing we're doing is this text is exactly the same and this text is exactly the same so I don't have to write this text should be exactly the same I could separately add that as a rule that you should always include the phone number here and this is what the phone number is if that's
important or if it's failing at that but I'm rather confident but by providing two three examples it will adhere to that two examples is probably enough here again you could add more especially if there's more variability in those examples and you need your AI to understand the minua between those a bit more one thing we could do to make this even stronger is we have my example wrapped in tags let's now take all of my examples and wrap it in an examples tag and also close that okay this is good I don't feel like I
need to provide specific examples for like the voice and tone and how it should interact with the user like a chat thread but if I wanted to I would have a similar preface for here are some examples of the tone of the interactions with users I use those as inspiration or abide by them and then similarly I might have a little chat thread in here wrapped in example and multiple chat threads wrapped in examples all underneath the examples section all right let's continue so far throughout the system layer we've been adding a bunch of contexts
we've been telling it who it is rules how to complete tasks but additional context I like to think of this as the sort of environmental context so your employee if they came in on a Wednesday they'd know it's a Wednesday they'd know what day it is the llm model doesn't know what day it is today that's an example of additional context so let's set that up I'll open up my AI agent and then in the system message we're going to be piping in some Dynamic dot now so that's going to be the time to do
that we're going to need to use Expressions so let's turn this into an expression and let's open this up so we have more room to work with and let's add the additional context section okay so in here we can add this just through bullet points because there's just going to be a few of them if there was a lot of context and that context itself had syntax like if your additional context was for some reason in HTML or something you may want to delineate it with something like this uh XML format but in this case
we'll just have some simple ones so the additional context we want to let it know what date and time it is because that's relevant for this use case the date and time right now is so since we want this to be live that's where we're going to use Expressions so open bracket and this opens up the auto complete here and we can actually select this dollar now method and if I look in the result here that's rendering to a date time object now what we could do is we could format that there's various methods and
stuff that help me do that for example that but since the LM is a computer system and it output puts by default this datetime object that's totally fine for it to understand so what the LM is going to see is the date and time right now is date time 2025 da da d d perfect now let's also add some quick context about the business so the beauty salon is called Max's gorgeous looks best place to get a blowout in bin and well actually best blowouts Berlin and the beauty salon's phone number is so this is
a good example where we've mentioned the phone number multiple times in the examples but we've also said these are examples and we're expecting it to fill some stuff in and out so let's make it extra clear to the llm that this is our phone number because we're mentioning that in two different places now again we could add a bunch of additional stuff like this but you get the idea you can add your bullet points all right that's additional context all right last section for the system layer and we're going to talk about some strategies on
reducing hallucinations so hallucinations is coming up with stuff that doesn't exist and telling the user pcup pi and all lies when I came up with the curriculum for the system layer I did have to cut some stuff so if you're familiar with prompt engineering you're going to say Max what about Chain of Thought and all these other things yes I did have to cut some stuff but the reason hallucinations is making the cut is most people think it's pretty bad when your AI is starting to make stuff up and and obviously that's not good for
for your use case I will preface that I am not an expert on reducing hallucinations and there probably prompt Engineers working on fintech stuff that have a lot of deep thinking on this if reducing hallucinations is something you're running into or generally you want to school up on it the first thing I would recommend you to do is go to Google and search anthropic reducing hallucinations and read anthropics article on reducing hallucinations I'm going to go on some of the things through this and and give a bit of voice over but that's my advice okay
the first thing that you're going to want to let the AI agent do is allow it to say I don't know give it an escape hatch otherwise if you're saying you're helpful you're an assistant it's going to try to keep helping even though it doesn't have the tools or the context in order to do that we've kind of already addressed that so let's take a look if we look in the rules we say don't make things up and ask the user for clarifying questions if you need additional information to complete your task so that's kind
of an escape hatch it's not exactly like anthropics example but that's sort of I think their guidance applied to this we could strengthen it with their guidance so don't make things up ask clarifing questions if you're asked a question to which you don't know the answer say so now the next guidance isn't as relevant for us at this stage but when you're extracting lots of information for example with tools it's going to be helpful to instruct the AI agent to Output quotes from those tools relevant quotes because if the AI agent doesn't output text like
when you're looking through its logs if it's not outputting Ting it it didn't think it so you have it output the things that are going to be relevant is going to use the next step because then it thought about it Etc if you're interested in reducing hallucinations in a sort of MVP low effort way again do read this article but the tldr if you don't want to do that is have some kind of rule or sentence like this don't make things up give it away to to exit and ask the user for a clarifying question
and tell it to that if it's asked a specific question it doesn't know the answer to to not try to be help in that case so drop a comment if you think there's things I'm missing here there's things you've heard about or there's challenges that you're having you and you would like to know how to address those with prompting there was a ton of information packed into the system lay if you're still watching you're doing great we got two more smaller sections because most of the magic happens in the system layer but there's some key
things to keep in mind in the input layer and the action layer so let's continue okay the input layer is where the actual user request is made now the important Point here is the user might not always be a human so in a chat use case the user is typically going to be human but there is some modifications or injections you could be making to their actual request that gets sent in their actual message but then you also have programmatic use cases so this is where the user of your AI agent is another system very
often API endpoint or something like that so let's take a look at these two cases and how we would basically set up the input or the user message to get that request done let's send a message so that we have some populated data okay can I make an appointment tomorrow now the reply isn't going to matter as much because we haven't set up tools and stuff what happens is if I look in my chat trigger here we can see it's outputed a payload of data and it has this variable called chat input and here's that
message that we sent so basically what's happening is this payload of data is being routed we see one item of data into the AI agent and then here we can see in the use a message it's being fed in and this is what the llm the AI agent receives that's the task the thing that's supposed to do the reason this is grayed out is because the source for prompt the source for user message is set to connect a chat trigger node this is the default if you're using the NN chat trigger now if you're using
a different type of app for example telegram or Whatsapp two different things you could do you could either Define below and drag and drop whatever that message is from the user in the incoming node in here for examp example or you can make sure if you're set to the default mode that the text containing that user message is set to chat input by default for programmatic use cases this is where you're going to be using the defined below format because basically you're going to have probably multiple variables of data that you're interspacing with a static
prompt uh and it's going to look kind of like a mail merged email if you've ever done or seen sort of marketing emails where you do personalizations basically personalizing a static prompt with Dynamic data from the task that actually needs to be done let's take a really quick look at that with a basic web hook based example so let's say in this example I have an AI agent that is doing something with user accounts maybe I have accounts in my system and I want it to check in on the health of the account maybe that
requires like using multiple tools getting multiple analyses and then sort of digesting that and giving a verdict on something right so that's something that's rather fuzzy that's something AI agents are good at so let's say we sent it this account username uh I'm using pin data right now but let's say this was being sent in every time I'm running the web hook we will then pipe that into the AI agent open it up and with a source for prompt set to Define below we would make the static portion of the request so for example the
form an analysis on the following username and then we drag the username and pop it in now this is a really simple task right it might be a bit more Vose or if you've defined discretely what analysis means in your system message and whatnot again this could be rather simple that's the basic premise of it obviously what happens in here depends on the task specifically and you can merge multiple bits of data that could be coming from that trigger or could be coming from multiple intermediary steps before fetching from a CRM and your sales CRM
and support getting all this data about the user and then piping that in as context if you have context from the user especially in a programmatic case that doesn't make sense for the actual task itself you can use the same concept of an expression and piping that into the uh instructions as well so if you're making a personal assistant you know here we have additional context about the beauty salon that's static but if you had a personal assistant here you might have things like the person's name is Max to catch they're 30 etc etc right
yep that's the input layer again nothing too fancy but just for completeness all right let's move on to the action layer [Music] the action layer is where we Define the tools that the a agent can use such that it can understand how to use them properly so tools are super useful because they let it interact with the digital and potentially even physical world so we want to make sure that it knows how to leverage those correctly especially cuz tools are more and more are going to start having destructive actions they might be a tool for
deleting an email so you want to make sure it's doing that exactly how you expected to and not for example deleting your whole inbox let's take a look so I've already added a basic check calendar availability tool since this tutorial doesn't focus on building tools themselves I'm just going to focus on the prompting inside the tool itself so let's open it up and the first most important thing with prompting for tools is giving them a consistent name so here in the name of the node I can see I've called it check calendar availability I'm not
using spaces you don't have to use this sort of underscore format you could use camel case or Kebab case the most important advice I could give you here is just don't use spaces because this is far more specific and its incidence in the training data right is is far less likely because it's almost like a very very proper noun because it's very specific so just use whatever format you're you're familiar with there and if you're not again it could be dashes underscores you could be capitalizing each first letter that doesn't matter just remember whatever name
you pick here use that exact name when you're referencing the tool so what I mean by that is again in the system message or anywhere else where you defining prompts make sure that you're referencing that tool precisely like you wrote it in the tool name okay back in the tool the next thing that happens when you're defining a tool is there's usually various parameters that you want it to control that's the case in the check calendar availability tool in fact in this tool we have to define the after and before time so it's a date
time and a date time that defines a window with which we want to fetch events within that window so we're using the from AI method that I went over in the last video and here the name is events after so often my guidance is use the exact same name here but if that doesn't feel descriptive enough add to that so I did it's events after and events before and then I did choose to have a description here and I basically said rever returns events after this time use this format and so by doing the use
this format I did not have to include a type Etc because some of the formats that you have this is in a string format potentially so you can't Define that by a type so you show it as an example in the description now uh a little learning when you're working in Ann is you're going to come up to this case often let's say this is this is this is how this parameter looks by default I might not know when what format I need to specify it if you ever have a situation like that in NN
in the fixed mode pick a value then go to expression and it'll convert that value to the plain text form it expected in then you can just copy that and use that in here uh in your format all right let's reset this and continue so the last step basically in defining your tool is the description of the tool the description can be simple like use this tool to da da da and it can also include some of the instructions and those sorts of things that we were seeing in the system message but scoped for the
tool itself you going to see a lot of people putting that kind of stuff right in the system message right in the system layer and just shipping it that's fine and that's also fine if you're creating a little AI agent just for yourself but when you think of teams or you think of iteration and and doing things well there's a concept of separation of concerns now again if you're have an engineering background you're well aware of this but the the tldr is if the prompting relates to defining the tool keep that in the tool because
then you can copy and paste that tool you could swap that tool maybe tomorrow we're not going to use Google Calendar right maybe management says hey we're switching to Outlook oh no I think that's their email app actually I'm very not familiar with Microsoft's ecosystem and so you want to separate the concerns so this is an app tool it does have a tool description by default in this case since our tool has to go get the actual events that exist for that period and then determine the space in between we're going to need to have
a bit more description so you're probably not going to need to do the step if it's just like a create lead action because n 's going to preset a description for it and for something like create lead if you added an action it's to create a lead that that that's enough information for that so we're going to change this to set manually now here there is a placeholder this placeholder is not what's sent along with sent automatically it would in fact pass along the the resource and the operation that's happening as well but in this
case let's set a description that allows it to actually get availability and describe what that is because it's a multi-step process the first thing we want to do is tell the AI agent when it should use this tool use this check calendar availability tool using the same name as in here to fetch existing appointments for a specified period and determine when there are available time slots that can accommodate a new appointment again most high level and I almost always have this format use this da da da tool to da da da da da right just
like if you were talking to a human about this and since this tool every time you use it there basically it's going to return some data and a few specific steps it has to think through to get the thing that it actually needs this is a great case where you can have instructions just for when it uses this tool so once again we'll add a section okay for the first point it needs to specify the date and range to fetch events are a specified set this this and this and this and this right we might
not need this step but I'm showing that I know I need that to happen every time so I would like to Define that for my AI agent I don't want variability on this because I don't think my use case needs it okay next step retrieve existing appointments the tool will return all booked appointments within the specified date time and range three calculate available slots once you have the existing appointments calculate the gaps between them to find potential availability ensure each Gap is at least as long as the required appointment length do not allow any overlap
with existing appointments it's nice and clear now here's a life hack my original bullet points here or steps were a little bit crappy I used chat GPT to make them better The Prompt that I used was very simple was basically you are an AI prompt writing expert improve these prompt Snippets for Tool snippet not the entire prompt if you're giving it a part of a prompt and it thinks it's a whole wi prompt is going to give you a whole lot and then I extracted the things that were clear to me if I had to
do the task and took those so that's my PSA to you you can use gpts there's various prompt helping tools that lots of people online are talking about so I'm not going to spend too much time on talking about that but learn these Basics learn these skills so you can audit the work of your AIS otherwise you'll have no idea if they're giving you BS or actually useful prompting okay so I've got these steps now one thing we can do here is after you have some instructions like this reaffirm by following these steps you can
accurately find valid appointment Windows based on the ready booked events this is not a really a scientific thing but I've been hearing from some folks that basically after you have a step of instructions some syntax or some words to this effect can improve results basically all right that's well defined let's check calendar availability I'm not going to build the other tool because it's going to be the exact same principle and this is not a tutorial about tool building but let's show this working so okay that is correct and if we look here we call the
model first and then it used the availability tool it correctly set events before and after returned back the events that we have it did some thinking and then it out puted the time slots action layer check if you're watching this you just got through the three layers of AI prompting all skipped through a bunch of it so congrats to the first half and the second half go back and watch it no seriously this was uh probably the most in-depth video I've done today and it's a lot harder to have nice continuity and Clarity across a
40 plus minute tutorial so thank you very much for supporting me as I figure this out and please please to let me know what you think about structuring it into these three layers that's a concept I came up with I basically did a bunch of research took my own experience took some of the experience of some folks that know a lot about this and try to put it into something that digestible right you see these videos telling you the ultimate tutorial everything you need to know about prompt engineering like 45 minutes it's not possible to
fit everything that people know about prompt Engineering in 45 minutes these are like professions and if you're good at it professions that pay you a shitload of cash so clearly you can't teach someone a 350k job in 30 minutes but I hope the concepts I've taught you here Empower you to build more with AI to roll your sleeves up and to build something that you can own and that you can improve over time and so that you feel that magical wow feeling when you see AI automate some drudgery or do something that you've been doing
manually and gives you time for the human things in your life this tutorial series is part of my work at the studio at nadn where we build Ai and automation use cases and also share those with our Global NN community so I'll catch you on the next one and happy flamming [Music] a [Music]
Copyright © 2025. Made with ♥ in London by YTScribe.com