00:00Hey, did you know you could create an AI agent completely for free and you don't even need to know how to code? I'm David and at David's Donut Den, sometimes we have customers who order donuts for events, but they don't pay us on time
00:13So, I got to chase some people down
00:15Instead of me keeping track of that, let's build an AI agent to take care of that for us
00:20We're going to use the app n8n
00:25I'll show you how to set it up for free in just a minute, but first, let's get on the same page about what an AI agent actually is
00:31So, AI agent can mean different things depending on who you're talking to
00:36So, for this video, I really mean a digital process that starts to feel like a real teammate doing work for us
00:44That boils down to about three characteristics
00:46First is they have reasoning skills
00:48Unlike an AI chatbot, which you would detail explicit steps to, agents can take in a goal and figure out the best way to achieve that goal
00:59In this example, the agent could first make sure that the article is relevant, the tone and format works for LinkedIn, it checks its work, etc
01:06It figures out what you meant versus just doing what you said
01:11The second is they have tool access
01:13Unlike chatbots, they can actually do things like move money around, email someone, order something for you, or make a post on social media
01:23Third is they have memory
01:23They maintain context throughout a task and even multiple tasks
01:29So, they learn from past mistakes just like we do
01:34Now, if that starts to feel like these agents will replace you, I honestly can't say whether they will or won't
01:40But, the more you know about them, the more they can enhance and support you
01:46Now, we're going to build an AI agent in n8n
01:48n8n is a workflow automation tool like Zapier or make.com
01:52After you sign up, you get a 14-day free trial and up to 1,000 workflow executions for free
02:00But, if you're willing to do just a little more work, I'll show you how to run it for free
02:05First, go to the Docker Desktop website
02:07You can find the link in the description below
02:09Then, go to the download Docker Desktop version and choose the version which is right for you
02:13Once it's downloaded, go ahead and install it
02:18After the install, you'll probably have to restart your machine
02:20And if you're on Windows, make sure you enable WSL or Windows Subsystem for Linux if you're asked
02:28After the install on Windows, double-click the Docker Desktop icon to launch it
02:33Accept the service agreement when you're ready and we'll skip making an account
02:36Now, go down to your taskbar and click on the start menu
02:39Type in cmd and then click on command prompt
02:43Then, type this exactly, all lowercase, docker space volume space create space n8n_data
02:54Then, press the enter key
02:54If it was successful, you should just see n8n data
02:58Here's the next command
02:58By the way, both of these you can copy from the description
03:02Press enter again and after a few moments, your Docker should be started
03:08What does that mean exactly? Well, it means you can copy and paste this link into a new browser window to access n8n
03:15Then, create your account and I'll see you on the dashboard
03:18Now, here's the main dashboard
03:20I like this one compared to other tools because it's pretty simple
03:25In the top right, you'll see you can create a new workflow
03:27We'll come back to that in just a second
03:31Below that, you have some analytics about your workflows
03:32And then in this section, you'll see all the workflows that you've built
03:36Don't miss down in the bottom left-hand corner, you also have access to thousands of templates
03:42Let's check a few of them out
03:42You can search or filter by the type of template
03:46So, let's check out AI templates
03:48You can find all sorts of ways that n8n can help you in your personal life as well as at work
03:52Back on the home page, click on test a simple AI agent example to get started
03:57This is the n8n editor
04:00You can move around the canvas by using your touchpad or by middle clicking with your mouse and dragging
04:06And when you want to get back to the full view of your workflow, click on the zoom to fit button in the bottom left
04:12You can also press the number one key
04:15Now, our workflow has two steps in it and those steps are called nodes
04:17The first node is special, it's called a trigger
04:21That tells n8n how the workflow starts
04:24Because this node says when chat message received, it seems like we can already chat with our agent
04:29Let's try it by clicking the open chat button
04:31And I'll ask in the chat window, are there any signs of life out there? And we hit an error
04:37This is totally expected, we have to set up our agent first
04:40There are three things we need to set
04:42First is the chat model, then the memory, and then a set of tools
04:47The model is the reasoning power behind the agent
04:50It's the LLM you want to use
04:52Let's delete the OpenAI model by clicking on the trash can
04:56Then, I'll click on the plus icon to see what models I could choose from
05:01There's a lot of others like Anthropic, Gemini, DeepSeek, Ollama, and so on
05:06In this video, we'll select Gemini because I want to show you how to do this for free
05:10Here, we need to get n8n talking with Gemini
05:12That's done through a credential
05:15So, I'll click on the select credential drop-down and click create new credential
05:19To do this, we need an API key
05:21That's no problem
05:25Head over to aistudio.google.com, you can grab that link from the description
05:29And once you're here, click on the get API key button in the top right
05:34From here, click create API key, then click create API key in new project
05:38If you don't see this button, you can probably create an API key in an existing project
05:42Once you have your key, copy it, then head back over to n8n and paste that key
05:48Click save in the top right
05:50You should see that the connection tested successfully and then click the X in the top right
05:54Then, under model, open the drop-down and scroll down until you see Gemini 2.5 flashlight preview 617
06:01The reason we're choosing this is because on the free plan, it gives you 15 free requests per minute and 1,000 free requests per day
06:13If these limits have changed, you can check the link in the description to find a better model for you
06:16Now we set up the model, you can click anywhere outside these boxes to head back to the canvas
06:22To see if this worked, let's try the chat one more time
06:25Well, it ran successfully, but it didn't give us a useful answer
06:29We'll have to set up the agent's memory first
06:31Click the plus icon next to memory to add a memory node
06:36So, memory gives the agent power to remember its previous steps
06:39In this tutorial, we'll keep it simple and choose simple memory
06:43We'll also change the session ID from connected chat trigger node to define below
06:48It doesn't matter what you type here, it just means there'll be one place to store memory and it'll store the last five messages with the model
06:57Let's head back to the canvas and add our last piece, which are tools
07:01These give the agent power to do what it needs to do
07:04Let's check out what's available by clicking on the plus button
07:08You can integrate with over 250 different products here
07:11The agent needs access to past invoices and we can enable it through the QuickBooks online tool
07:17n8n already has an integration here, so I'll click on that
07:20Just like with Gemini, you'll need to set up your credentials
07:24Now, because you might not have QuickBooks, take this as an example of any third-party app you might want to integrate with
07:31The options that show up after tool description will depend on the app
07:35In this case, under resource, we want to get invoices and under operation, we want to get many invoices
07:44We only want the invoices that are overdue, so let's add a filter
07:45We could type this in by hand, but the whole point of an agent is it should be able to figure this out for us with some minimal instructions
07:54So, click the AI button to say let the model define this parameter
07:59Next, the agent needs to send payment reminders
08:01That means email
08:04Back on the tool connector, click plus again and then search for email
08:06Now, if you're using the cloud version of n8n, it's actually easier to use the Gmail tool directly
08:14That's because you can just sign in to Gmail
08:16But, when you're self-hosting, you have to do a little bit more work
08:20Let's click the send email tool
08:22Just like with other tools, let's create our credential
08:25We'll use our Gmail settings
08:27That means the user is our email address and the host is smtp.gmail.com
08:35Now, the password is not your Gmail password, it's something called an app password
08:40You can create one by going to security.google.com, making sure that you're signed in, and then searching for app passwords at the top of the screen
08:49Click on the app passwords icon to make one
08:51Once you have your password, fill in the form and then click the save button in the top right
08:57Your connection should be successful, so let's exit out of this one, too
09:00Now that my credentials are set, I need to tell the agent who and what we're emailing
09:05First is the from email
09:08That's easy, it's the email we signed in with
09:10Next is the to email
09:13Now, the agent's going to get that from the invoice, so we need to tell n8n let the model define this parameter
09:19We also want the model to decide the subject line
09:23Then, to simplify the email, let's make it plain text instead of HTML
09:26And we'll also rely on the model to generate the message
09:31Now, we had to set all of those parameters, but there are some optional ones which we can explore by clicking the add option button
09:38You can add attachments or add a CC line or BCC line
09:44However, let me turn your attention to append n8n attribution
09:49This adds a message to the bottom of every email saying it was sent by n8n
09:55We want to look more professional than that, So, let's turn that off
09:57Now, let's head back to the canvas and put all of this together
10:01Let's save our progress first, and then let me tell you something about tools
10:05See, it's our responsibility to teach the agent about these tools
10:10And to describe a tool, it helps to name it first
10:12So, to name the QuickBooks online tool, I'll double-click it to open its node settings again
10:18Then, I'll click on its name and give it a new name
10:20Get invoices is a simple, self-evident name
10:25Let's exit out of here and then give a name to our email tool
10:27I'll make this one a little bit more descriptive and call it send payment reminder
10:32Now, it's time to make our agent sing
10:34Let's double-click on the agent to see what we can configure about it
10:39First, we can click on the agent drop-down to see that N8N supports multiple different types of agents
10:47The tools agent is the default
10:50This supports calling all the tools we've just set up
10:52Next, we have the prompt
10:54I'm going to click this icon in the bottom right corner of the window to expand it
10:58In the center of the screen, we just have the current prompt
11:01This is the default that N8N sets up ahead of time
11:05These green and red blocks indicate that the prompt is created dynamically
11:10As you can see, anything inside those curly braces is JavaScript
11:15And then on the right side, you'll see the JavaScript evaluated for the current context
11:19This, by the way, is why our chats didn't work earlier
11:22It's because the agent was instructed to tell us to connect to memory first
11:26Now, instead of starting this prompt from scratch, let me show you a process that can help you get to that right prompt
11:33I'll head over to the free version of ChatGPT, and then I'll click that speech bubble in the top right to turn on a temporary chat
11:40I'm doing this so ChatGPT doesn't use any of its past memory or prompts for what I'm about to show you
11:47So, we're going to ask ChatGPT to create this agent prompt for us
11:53Here is a template that you can follow
11:56First, help me write a prompt for an AI agent using these key components: role, task, tools, and outputs
12:03These are common elements of reliable prompts
12:06Then, I'll tell ChatGPT I'll write a brief below that starts with a task, and this pound sign is just a symbol to indicate a heading
12:15So, the task is to send payment reminders to customers who have at least one overdue invoice in QuickBooks online
12:21The next step is context
12:21This is more info for the agent on how to act to do its job
12:27Basically, here I'm telling it to start polite when the customers are under 7 days overdue, but get more and more firm
12:33Then, make sure you only send one email per customer, even if they have multiple overdue invoices
12:39Next comes the tools, and this is where we use the tool names to offer descriptions to the agent
12:44I tell it how to get overdue invoices and that it can send payment reminders
12:49Finally, I describe what I want at the end of the process
12:54Here, I'm asking for data in a JSON format, which we'll show why later on
12:59When I submit this, ChatGPT will put the full agent prompt together for me
13:04Now, a trick which I didn't do here is ask ChatGPT to ask me questions first in case there is any ambiguity
13:11You can see an example of that in the description
13:16Now, you do need to proofread that this is actually what you want, especially within the task section
13:20I'm happy with this, so now let's get it into a format we can copy with this prompt
13:24You can copy this prompt from the description
13:28It just converts that prompt into markdown
13:30Back in N8N, let's replace the prompt in the center column with the prompt that I just copied
13:35Now, we're not quite ready yet
13:37We've got one more thing we need to change
13:40It's this today field I just highlighted
13:42The AI model won't know what today's date is, so we've got to tell it
13:47Here's how we'll do that
13:48I'll simply tell the model the current date
13:51That uses JavaScript, which requires me to use two open braces
13:55Then, to get today's date, I can use the special variable now
13:58On the right side, we can see what that actually evaluates to
14:02It's not quite what we want, but if we use the format function, we can retrieve the date by using this date format
14:10That gives us the right date over here, too
14:12And if you're not a coder, just remember you can use this text to get the current date
14:17Now, you've been so patient through all this configuration
14:19Let's get this agent working
14:21I'll add a simple step to run this, and then let's see what happens
14:24No guarantees that this works the first try
14:26Okay, I had to try this a few times to get it to work
14:31Every time an issue came up, I just tweaked the prompt a little bit to fix it
14:35To see what actually happened, I've expanded this bottom pane to see the logs
14:39You can click on any step the agent went through to see more detail
14:43And you'll normally see inputs and outputs broken up side by side
14:45So, it understood it needs to fetch the invoices and then called the get invoices tool
14:51Then, it reinvoked the model with this new data and found multiple overdue invoices
14:55Then, it sent two payment reminders, and one of them was for the Kevin Cookie Company
15:00I always got to chase that Kevin guy down
15:05And finally, here's the actual email, which I can access from my sent box
15:09That brings us to the sponsor of today's video, Intuit, the creator of QuickBooks online
15:14Now, it's annoying when you don't get paid on time, but did you know that QuickBooks online already has AI-driven payment reminders built in? They're configured ahead of time based on the customer's history
15:25And if you have several late customers, QuickBooks online will guide you through automatic late fee collection
15:31It's about more than getting paid, though
15:33QuickBooks tracks all the money you earn and spend and categorizes it automatically with AI
15:39That way, you actually save money on your taxes since you'll find extra deductions
15:44And sales tax is tracked for you, too
15:46So, it's a breeze to know how much you owe to each agency
15:48And now it's powered by its own suite of AI agents, it is a great time to try QuickBooks
15:54Click the link down in the description to give it a shot
15:56Okay, so even though we were successful, what we have so far isn't realistic
16:01I have a hard time believing anyone would send out emails without reviewing them first
16:08When we put a reviewer in the process, it's called human in the loop
16:12Fortunately, N8N realizes this is a core part of an agent workflow
16:14So, it's got a number of tools you can use to get human approval
16:19Let's build this out by creating an approval process in Discord
16:24Just like all other nodes, we'll start with the credential
16:26I've already set up a token, so I can paste that in here
16:30Now, let's configure the bot
16:30I want the bot to message me, so message is correct
16:35I also want it to wait for a response, so this is correct
16:37So, next I'll choose my server, and I want all of these approvals to go to the approvals channel
16:44That's all good, but now we're stuck because we don't have access to the email subject and message here
16:48I can tell that because I can see all the possible data I have access to in this input pane
16:55And the only thing the agent tells us is that it sent two emails
16:58Not helpful
17:01So, let's modify our agent node to make this work
17:03So, we skipped this option last time, but we're going to need it now
17:07It's called require specific output format
17:08This adds another option to the agent called an output parser
17:13Let's add one and make sure all the data we require comes back
17:19We'll use the structured output parser
17:21That gives us the best chance of getting the subject and message in the Discord node
17:25Here, we can set up an example of the format that we want
17:28This has everything a human might need to make an approval
17:31Now, if this looks like Greek to you, don't worry
17:33You can provide ChatGPT with a list of these fields and ask it to generate sample data in JSON for you
17:41Okay, if we've done everything right, the output should now match this format
17:45Before we try it, let's clean up three other things
17:48First, we need to remove the send payment reminder tool
17:52The agent can only email if it's been approved in Discord
17:54So, I'll remove this tool by clicking the trash icon
17:59Second, let's update the prompt to accommodate this change
18:00There are two changes here
18:02First, the agent should just write each customer an email, not send it
18:07And second, we'll remove the send payment reminder tool from the prompt
18:11The last thing to clean up, which I've ignored until now, is that we kick this off with a chat message
18:15What we need instead is a schedule
18:17This is a weekly operation
18:20So, I click the plus button here, and then I can click add another trigger, and then select on a schedule
18:27To make this a weekly operation, I'll change the trigger interval from days to weeks, and then leave weeks between triggers at one
18:35We'll get out of here, and then now let's remove the chat node with the trash can
18:38Let's see if our agent likes the changes
18:40I'll double-click on the agent node, and then I'll click execute step
18:44This only executes the workflow up to this node
18:47Okay, looks like we hit an error, and we can see from the red outline around the tool that it's in the get invoices step
18:53Sometimes this happens where the LLM sends the wrong data to your tool
18:57In this case, it made up sending select star from invoice
19:00So, let's just make a quick edit to the tool description so it doesn't do that
19:05Now, let's try this again
19:08Awesome
19:08That did the trick
19:10Now, to check the output will work for that Discord node, I can click on this output button
19:14Now, it looks like we have everything we need: customer name, customer email, subject, and the body
19:20Now, give yourself a pat on the back because this was the hard step
19:24Now, let's get this approval process set up in record time
19:25The agent gives us output, but we need that output as a list of email details
19:30That's so we can run an approval process on each one
19:36To make that happen, I'm going to add a new node called split out
19:38This does what we want: turn a list inside items into separate items
19:43So, see how the agent gave us this output node? We actually need the details list instead
19:50Now, that's as easy as dragging and dropping details into fields to split out
19:54You can preview this again through execute step and see that it results in two items
19:59Now that we have the list, we've got to add a new node to loop over each item
20:04You'll find that under the flow nodes and then select loop over items
20:08And we'll keep the batch size as one since the approvals run one at a time
20:13Now this loop looks different from the other nodes
20:15It has a loop case and a done case
20:18The approvals run in a loop, so I'll get rid of this replace me node and this loop path
20:22I'll also get rid of the done path and then drag and drop the plus of the loop path to our Discord node
20:29Now let's configure the approvals
20:31I'll double click on this Discord node so we can edit it
20:32This time we now have access to all the data to create a message
20:37Here's my very simple template to start plugging in data
20:41And next I'll drag in fields from the input starting with email body
20:43I'll add the customer name as well as the email subject
20:48And you can see a preview of the data down below
20:51Now what's cool with n8n is that the approval processes are built in
20:55So all we need to do is add approval options and it'll take care of the rest
21:00I'm going to choose a simple approve or disapprove workflow
21:05But you can allow your human to make corrections via the response type option
21:09So let's test this out by clicking execute step
21:11Here in Discord in this approvals channel, I can either decline or reject the message or approve it
21:18Let's click approve
21:18Now we've tested it, we get the output saying that approved is true
21:22That means we can send the email
21:25So let's get that set up
21:25To create a branch, we're going to go back to flow nodes and this time choose if
21:33So we only move forward if approved is true
21:36I'll start by dragging and dropping approved into values
21:38Then I need to change the comparison
21:41Since approved is a boolean, I'll go to that drop down list
21:45Then I'll select is true
21:48Now it's time for the email node
21:50We'll go over to this true branch because we're testing if approved is true
21:54Search for our email tool like last time and then let's set up send email
22:00I don't want to wait for a response, so I'll just click send an email
22:04Let's make sure we get our previous data first
22:05That takes a second or two and now we need to fill in the email info
22:09This is where I don't like n8n
22:12See, we can't access the current data in the loop
22:14Instead, we've got to get it from code
22:17You can copy and paste this code from the description
22:19And the email text is the last of it
22:21We'll head back to the workflow, then make sure that every branch goes back to the loop
22:27That includes your approvals and rejections
22:29Now let's run our workflow end to end and see if it works
22:31Okay, it got our emails and now it's waiting for us to respond in Discord
22:36Let's reject this first one for Hope Mills
22:38And now the second one comes in for the Kevin Cookie Company
22:42We got to approve that one
22:44Back in the workflow, we see one email was sent and one was not
22:46And we can see that email in our sent box
22:49And look at that
22:51In just a few clicks, you can have an AI agent that can reason about the best way to achieve a goal, invoke a number of different tools to get there, and even work with humans to produce the best outcome
23:02Thanks so much for watching
23:04Leave me a comment on what you want to see me cover next and I'll see you in the next video.