The Secret to Making AI Agents 100% Reliable - Human in the Loop (n8n)

Dr. Violet Howard shows how to build reliable AI agents in n8n by pausing workflows for human approval. A Telegram request triggers an agent that drafts a tweet using GPT-4.1 and web search, then waits for user feedback. If rejected, a revision agent rewrites it based on the feedback, looping until approved.
Chapters
Okay, our workflow is actively listening for us in Telegram and I'm gonna ask it to make an X post about coffee at night. So as you can see, this first agent is going to search the internet using Tavily and create that initial X post for us. Now we just got a message back in our Telegram that says, hey, is this post good to go? Drinking coffee at night can disrupt your sleep since caffeine stays in your system for hours, often leading to poor sleep quality. So what I'm gonna do is click on respond and this gives us the ability to give our agent feedback on the post that it initially created. So here's that response window and I'm gonna provide some feedback. So I'm telling the agent to add at the end of the tweet, unless it's decaf. And as soon as I hit submit, we're gonna see this go down the path. It's gonna get classified as a denial message. And now the revision agent just made those changes and we have another message in our Telegram with a new X post. So now as you can see, we have a new post. I'm gonna click on respond and open up that window. And what we can see here is now we have the changes made that we requested. At the end it says, unless it's decaf. So now all we have to do is respond good to go. And as soon as we submit this, it's gonna go up down the approval route and it's going to get submitted and posted to X. So here we go. Let's see that in action. I'll hit submit. And then we're gonna watch it get posted onto X. And let's go check and make sure it's there. So here's my beautiful X profile. And as you can see, I was playing around with some tweets earlier, but right here we can see drinking coffee at night can disrupt your sleep. We have the most recent version because it says unless it's decaf, and then we can also click into the actual blog that Tably found to pull this information from. So now that we've seen this workflow in action, let's break it down. So the secret that we're gonna be talking about today is the aspect of human in the loop, which basically just means somewhere along the process of the workflow, in this case it's happening right here, the workflow's gonna pause and wait for some sort of feedback from us. That way we know before anything is sent out to a client or posted on social media, we've basically said that we 100% agree that this is good to go. And if the initial message is not good to go, we have the ability to have this unlimited revision loop where it's going to revise the output over and over until we finally agree that it's good to go. So we have everything color-coded and we're gonna break it down as simple as possible. But before we do that here, I just wanted to do a real quick walkthrough of a more simple human-in-the-loop because what's going on up here is it's just gonna say, do you like this? Yes or no? Compared to down here where we actually give text-based feedback. So we'll break them both down, but let's start up here real quick. And by the way, if you wanna download the template for free and play around with either of these flows, you can get that in my free school community. The link for that will be down in the description. And when it comes to human-in-the-loop in N8N, if you click on the plus, you can see down here human-in-the-loop. Wait for approval or human input before continuing. You click on it, you can see there's a few options and they all just use the operation called send and wait for response. So obviously there's all these different integrations and I'm sure more will even start to roll out, but in this example, we're just using Telegram. Okay, so taking a look at this more simple workflow, we're gonna send off the message, make an X post about AI voice agents. What's happening is the exact same thing as the demo where this agent is gonna search the web and then it's gonna create that initial content for us. and now we've hit that human-in-the-loop step. As you can see, it's spinning here purple because it's waiting for our approval. So in our Telegram, we see the post, it asks us if this is good to go, and let's just say that we don't like this one and we're gonna hit decline. So when I hit decline, it goes down this decision point where it basically says, you know, did the human approve? Yes or no? If yes, we'll post it to X. If no, it's gonna send us a denial message, which basically just says post was denied, please submit another request. And so that's really cool because it gives us the ability to say, okay, do we like this? Yes. And it'll get posted otherwise. Just do nothing with it. But what if we actually want to give it feedback so that it can take this post, we can give it a little bit of criticism, and then it will make another one for us, and it just stays in that loop rather than having to start from square one. So that's exactly what I did down here with the Human-in-Loop 2.0, where we're able to give text-based feedback instead of just saying yes or no. So now we're going to break down what's going on within every single step here. So what I'm going to do is I'm going to click on Executions. I'm going to go to the one that we did in the live demo and bring that into the workflow so we can look at it. So what we're gonna do is just do another live run and walk through step by step the actual process of this workflow. So I'm gonna hit test workflow. I'm gonna pull up Telegram and then I'm gonna ask it to make us an X post. Okay, so I'm about to fire off, make me an X post about crocodiles. So I've sent that off. This X post agent is using its GPT-4-1 model as well as Tavli Search to do research, create that post. and now we have the human in the loop waiting for us. So before we go look at that, let's break down what's going on up front. So the first phase is the initial content. This means that we have a Telegram trigger, and that's how we're communicating with this workflow. And then it gets fed into the first agent here, which is the X-Post agent. Let's click into the X-Post agent and just kind of break down what's going on here. So the first thing to notice is that we're looking for some sort of prompt. The agent needs some sort of user message that it's gonna look at. In this case, we're not doing the connected chat trigger node. We're looking within our Telegram node because that's where the text is actually coming through. So on this left-hand side, we can see all I basically did was right here is the text that we typed in, make me an X post about crocodiles. And all I did was I dragged this right into here as the user message, and that is what the agent is actually looking at in order to take action. And then the other thing we did was gave the agent a system message, which basically defines its behavior. And so here's what we have. The overview is you are an AI agent responsible for creating X posts based on a user's request. Your instructions are to always use the Tavli search tool to find accurate information, write an informative, engaging tweet, include a brief reference to the source directly in the tweet, and only output the tweet. We listed its tool, which it only has one, called Tavli Search, and we told it to use this for real-time web search. And then just gave it an example basically saying, okay, here's an input you may get, here's the action you will take, and then here's the output that we want you to output. And then we just gave some final notes. And I know I may have read through this pretty quick, but keep in mind you can download the template for free and the prompt will be in there. And then what you could do is you can click on the logs for an agent and you can basically look at its behavior. So we can see that it used its chat model, GPT-4.1, read through the system prompt, decided, okay, I need to go use Tavily Search. So here's how it searched for crocodile information. And then it used its model again to actually create that short tweet right here. And then we'll just take a quick look at what's going on within the actual Tavily Search tool here. So if you download this template, all you'll have to do is plug in your own credential Everything else should be set up for you, but let me just break it down real quick. So if you go to tably.com and create an account, you can get 1,000 free searches per month. So that's the kind of plan I'm on. But anyways, here's the documentation. You can see right here we have the Tably search endpoint, which is right here. All we have to do is authorize ourselves. So we'll have an authorization as a header parameter, and then we'll do bearer space our API token. So that's how you'll set up your own credential. And then all I did was I copied this data field into the HTTP request. And this is where you can do some configuration. You can look through the docs to see how you but all I wanted to do here was just change the search query. So back in N8N, you can see in my body request, I changed the query by using a placeholder. Right here it says, use a placeholder for any data to be filled in by the model. So I changed the query to a placeholder called search term. And then down here, I defined the search term placeholder as what the user is searching for. So what this means is the agent is going to interpret our query that we sent in Telegram. It's then going to use this Tavily tool and basically use its brain to figure out what should I search for. And in this case, on the left-hand side, you can see that it filled out the search term with latest news or facts about crocodiles. And then we get back our response with information and a URL, and then it uses all of this in order to actually create that post. Okay, so here's where it may seem like it's gonna get a little tricky, but it's not too bad. Just bear with me. And I wanted to do some color coding here so we could all sort of stay on the same page. So what we're doing now is we're setting the post, and this is super important. Because we need to be able to reference the post later in the workflow, whether that's when we're actually sending it over to X or when we're making a revision and we need the revision agent to look at the original post as well as the feedback from the human. So in the set node, all we're doing is we're basically setting a field called post and we're dragging in a variable called json.output. And this just means that it's going to be grabbing the output from this agent or the revision agent, no matter what. As you can see, it's looped back into this set because if we're defining a variable using $json, It means that we're gonna be looking for whatever node immediately finished right before this one. And so that's why we have to keep this one kind of flexible because we want to make sure that at the end of the day, if we've made 5 or 6 or 7 revisions, that only the most recent version will actually be posted on X. So then we move into the human-in-the-loop phase of this workflow. And as you can see, it's still spinning. It's been spinning this whole time while we've been talking, but it's waiting for our response. So anyways, it's a send and wait for a response operation. As you can see right here, the chat ID is. Coming from our Telegram trigger. So if I scroll down in the Telegram trigger on the left-hand side, you can see that I have a chat ID right here. And all I did was I dragged this in right here, basically just meaning, okay, whoever communicates with this workflow, we need to send and get feedback from that person. So that's how we can make this dynamic. And then I just made my message basically say, hey, is this good to go? And then I'm dragging in the post that we set earlier. So this is another reason why it's important is because we want to request feedback on the most recent version as well. Not the first one we made. And then like I mentioned, within all of these human-in-the-loop nodes, you have a few options. So you can do free text, which is what we're doing here. Earlier, what we did was approval, which is basically you can say, hey, is there an approve button? Is there an approve and a denial button? How do you want to set that up? But this is why we're doing free text, because it allows for us to actually give feedback, not just say yes or no. Cool. So what we're going to do now is actually give our feedback. So I'm going to come into here. We have our post about crocodiles. So I'm going to hit respond and it's going to open up this new page. And so yes, it's a little annoying that this form has to pop up in the browser. Browser rather than natively in Telegram or whatever, you know, Slack, Gmail, wherever you're doing the human-in-the-loop. But I'm sure that'll be a fix that'll come soon. But it's just right now I think it's coming through a webhook, so they just kind of have to do it like this. Anyways, let's say that we want to provide some feedback and say make this shorter. So I'm going to say make this shorter, and as I submit it, you're going to see it go to this decision point, and then it's going to move either up or down. And this is pretty clearly a denial message, so we'll watch it get denied and go down to the revision agent. As you And just like that, that quickly, we already have another one to look at. So before we look at it and give feedback, let's just look at what's actually going on within this decision point. So in any automation, you get to a point where you have to make a decision. And what's really cool about AI automation is now we can use AI to make a decision that typically a computer couldn't, because a typical decision would be like, is this number greater than 10 or less than 10? But now it can read this text that we submitted, make this shorter, and it can say, okay, is this approved? Or declined. And basically I just gave it some short definitions of like what an approval message might look like and what a denial message might look like. And you can look through that if you download the template. But as you can see here, it pushed this message down the declined branch because we asked it to make a revision. And so it goes down the denial branch, which leads into the revision agent. And this one's really, really simple. All we did here was we gave it two things as the user message. We said, here's the post to revise. So as you can see, it's, this is the initial post that the first agent made for us. And then here's the human feedback. So it's gonna look at this, it's gonna look at this, and then it's going to make those changes because all we said in the system prompt was, you're an expert Twitter writer. Your job is to take an incoming post and revise it based on the feedback that the human submitted. And as you can see, here is the output. It made the tweet a lot shorter. And that's the beauty of using the set node is because now we loop that back in. The most recent version has been submitted to us for feedback. So let's open that up real quick in our Telegram. And now you can see that the shorter tweet has been submitted to us and it's asking for a response. So at this point, let's say we're good to go with this tweet. I'm gonna click Respond, open up this tab. Recent crocodile attacks in Indonesia highlight the need for caution in their habitats. Stay safe. We've got a few emojis and I'm just gonna say, let's just say send it off because it can interpret multiple ways of saying like, yes, it's good to go. So as soon as I hit Submit, we're going to watch it go through the decision point and then post on our X. So you see that right here, text classifier, and now it has been posted to X. And I just gave our X account a refresh. You can see that we have that short tweet about recent crocodile attacks. Okay, so now that we've seen another example of a live run-through, a little more detailed, let me talk about why I made the color coding like this. So the set note here, its job is basically just, I'm gonna be grabbing the most recent version of the post because then I can feed it into the human in the loop. I can then feed that into the revision if we need to make another revision because you wanna be able to make revisions on top of revisions. You don't wanna be only making revisions on the first one, otherwise you're gonna be like, what's the point? And then also, of course, you wanna post the most recent version not the original one, because again, what's the point? So in here you can see there's two runs. The first one was the first initial content creation, and then the second one was the revised one. Similarly, if we click into the next node, which was request feedback, the first time we said make this shorter, and then the second time we said send it off. And then if we go into the next node, which was the text classifier, we can see the first time it got denied because we said make this shorter, and the second time it said Sent it off and it got approved. And that's basically the flow of, you know, initial creation. We're setting the most recent version. We're getting feedback. We're making a decision using AI. And as you can tell for the text classifier, I'm using 2.0 Flash rather than GPT-4.1. And then of course, if it's approved, it gets posted. If it's not, it makes revisions. And like I said, this is unlimited revisions and it's revisions on top of revisions. So when it comes to human in the loop, you can do it in more than just Telegram too. So if you click on the plus, you can see right here, human in the loop, wait for approval or human input before continuing. We've got Discord, Gmail, chat, Outlook, Telegram, Slack. We have a lot of stuff you can do. However, so far with my experience, it's been limited to one workflow. And what do I mean by that? It's kind of tough to do this when you're actually giving an agent a tool that's supposed to be waiting for human approval. So let me show you what I mean by that. Okay, so here's an agent where I tried to do a human in the loop tool because we have the send and wait message operation. As a tool for an agent. So let me show you what goes on here. We'll hit test workflow. Okay, so I'm gonna send off get approval for this message. Hey John, just wanted to see if you had the meeting minutes, and you're gonna watch that it's gonna call the get approval tool. But here's the issue. So it's waiting for a response, right? And we have the ability to respond, but the waiting is happening at the agent level. It really should be waiting down here for the tool because as you saw in the previous example, the response from this should be the actual feedback from the human. And we haven't submitted that yet. And right now the response from this tool is literally just the message. So what you'll see here is if I go back into Telegram and I click on respond and we open up this tab, it basically just says no action required. And if I go back into the workflow, you can see it's still spinning here and there's no way for this to give another output. So it just doesn't really work. And so what I was thinking was, okay, why don't I just make another workflow where I just use the actual node like we saw on the previous one That should work fine because then it should just spin down here on the tool level until it's ready. And so let me show you what happens if we do that. Okay, so like I said, I built a custom tool down here, which is called Get Approval. It would be sending the data to this workflow. It would send off an approval message using the send and wait, and it doesn't really work. I even tried adding a wait here, but what happens typically is when you use a workflow to call another one, it's going to be waiting and looking in the last node of that workflow for the response, but it doesn't yet work yet. With these operations, and I'll show you guys why. And I'm sure NNN will fix this soon, but it's just not there yet. So I'm just going to send off the exact same query, get approval for this message. We'll see it call the tool, and basically, as you can see, it finished up instantly. And now it's waiting here, and we already did get a message back in Telegram which basically said, ready to go. Hey John, just wanted to see if you had the meeting minutes. And it gives us the option to approve or deny. And if we click into the sub-workflow, this one that it actually sent data to, we'll we can see that the execution is waiting. So this workflow is properly working because it's waiting here for human approval. But if we go back into the main flow, it's waiting here at the agent level rather than waiting here. So there's no way for the agent to actually get our live feedback and use that to take action how it needs to. So I just wanted to show you guys that I had been experimenting with this as a tool. It's not there yet, but I'm sure it will be here soon. And when it is, you can bet that I'll have a video out about it. So anyways, that's gonna be it for this one. If you guys enjoyed this style of video and you want to take your learning a bit deeper with N8N, and definitely check out my paid community. The link for that is down in the description. We've got a great community of members all kind of building end-to-end solutions from different backgrounds. It's a great place to connect and get your questions answered. We also have 5 live calls per week to make sure you actually can get some tech support, get your questions answered, and meet some other people in this space. So I hope to see you guys in these live calls. I hope you enjoyed the video. If you did, please give it a like. Definitely helps me out a ton and appreciate you guys as always making it to the end of the video. See you in the next one. Thanks everyone.










