This is the new best method to build Ai Agents (quicker, cheaper, more efficient)

Rory Rogers shows how to build AI agents faster and cheaper by sandwiching them between workflows: a pre-agent stage that cleans data, a lean agent with only essential tools, and a post-agent stage that formats output. He walks through a Gmail-to-Airtable lead pipeline and a RAG system using Pinecone, showing how this hybrid approach cuts prompt size and errors.
Chapters
What's up guys, I want to show you a new method I've been using to build AI agents that's quickly becoming a staple in all of my AI agent builds. This is a method that's allowing me to create cheaper, quicker, and more efficient AI agents, meaning they're saving me more time, carrying out more tasks, and carrying out more complex tasks. Just quickly, if you haven't seen me before, my name is Rory Rogers and I help business owners to integrate AI agent systems into their businesses. So if that's something you might be interested in, I've left a link to my website in the description. You go ahead and book up a call and we can talk about some ways to integrate AI into your business. Let's not waste any more time, let's get into the video and I can show you exactly what I'm talking about. Okay, so we all know when it comes to agents, when it comes to automation, we have two different ways of doing it. We have workflows and we have agents. You're probably familiar with both of these a lot of the time. I know I did. I started out with workflows and then I moved on to agents, and of course I still use workflows when they're needed. So we're gonna have a quick look at both of these different systems, workflows and agents, some of the strengths and weaknesses of both. Obviously the strengths for workflows is that a lot of the time they're quicker, they're cheaper, and there's less room for error just because there's more guardrails there. There's less things that they can mess up, basically. And the weaknesses are going to be that they're less dynamic, they can't think the same way that an agent can, and they can also take longer to build. And when I say take longer to build, this is going to be for the more sort of complex, uh, solutions. A lot of time it makes more sense to build an agent rather than a workflow just because it's going to take way longer and there's going to be so many more moving parts to it, so many more things to think about. So that's what I mean when I say it can take longer. And then if we look at the agents, obviously the strengths are going to be much more flexible, can handle different inputs, and it's going to be easier to set up. When I say easier to set up, this is going to be things like, uh, email agents, calendar scheduling agents, CRM agents. A lot of the time it's way easier to get an agent up and running compared to a workflow. And the weaknesses kind of just going to be the opposite of the workflow. So like the strengths of the workflows, kind of the weaknesses of the agent— there's going to be more room for error, and a lot of time it's going to be slower and it's going to be less efficient because obviously having to think about it, it takes a little bit longer. There's less guardrails, so there's more room for error. But you probably know this already and use agents and use workflows accordingly when they're needed. So this is kind of a look at the traditional way of building an AI agent. You've all seen this before. We've got an input, and we have the AI agent that's going to be powered by an LLM, and we have all the tools that it can use down here, and then we have an output of some kind. So an example of this— this is a simple version of the agent I built in my last video. Have a Gmail trigger here, and then we have an Airtable search record, update record, get document from a Google Docs, and then a Gmail send message, and then a human in the loop. And basically what this agent's doing is, is checking my email inbox. When I get an email from a lead or a client, the email's gonna come through here. The agent is gonna check if it's from a lead or a client. It's gonna update the, uh, Airtable base with the information that was in that email, and then it's gonna search a Google Doc to try and reply to this email. Google Doc's just a knowledge base. And it's either gonna send that email or it's gonna use a human in the loop step and just notify me that it wants to send this email and I can click, uh, approve or decline. So you can see here I've written out, it's got Gmail trigger, search Airtable, update Airtable, search docs, send emails, and then use a human in the loop. And then we have the traditional way to build a workflow. So kind of similar, we have inputs and then tool, tool, tool, tool, tool, tool, and then an output. So kind of just missing out the agent part of it. It's just tools with an input and then an output. So an example of this, this is the exact same system as that agent I just showed you. It does the exact same thing. Of course, obviously this is just the equivalent as a workflow. So it's the exact same thing, but in a workflow. You can see we have the Gmail trigger, we have the Airtable step, and then we have the step to see if they're a lead or a client. And then yada yada, you can see it does the exact same thing. So Gmail trigger, search Airtable, update Airtable, search docs, send emails, and then use a human in the loop. And then this is what I'm calling the better way to build AI agents. This is how I've been building all of my AI agents recently, and I think This is just the most optimal way to build these agents. So you're probably looking at this right now and thinking, Rory, this looks exactly the same. This doesn't look groundbreaking. This doesn't look like really anything new or crazy. But basically what we're looking at here is an input and then a tool and then the agent. And then you can see we've got less tools down here and then a tool and an output. And basically what we're looking at is a representation of combining the workflows and the agents into just one system rather than using just workflows or using just agents or using them separately. Combining it into one system and having the input, have a workflow at the beginning, gets to the agent, which now has less tools because there was a workflow at the beginning that did a lot of the work for it, uses the tools, and then the output. Again, there is a workflow before the output, so the agent doesn't have to output in a certain way. Maybe we're going to jump into some actual examples, but yeah, basically there'll be a workflow at the end as well to sort of manipulate the data in some way so that the agent doesn't have to output in a specific way. So this is a real life example of how this system might look, and this is the exact agent I actually built in my last video. And this is just combining those workflows and those agents I just showed you into one system. So we have the exact same thing again. We have a Gmail trigger, search Airtable, update Airtable, search docs, send emails, and then use a human in the loop. And it's doing the exact same thing, but of course this time there's gonna be a smaller prompt because the agent has less tools to use. It's gonna be less room for error cuz there's more guardrails because of those workflows we've implemented. And then it's also going to be quicker and it's gonna be cheaper because we've got workflows and we've got agents combined. So we're kind of getting the best of both worlds. So this is a side-by-side comparison, just so you can see of all 3 systems. So this is just the agent on its own, and then this is just the workflow on its own. Of course, now that you're looking here, you can kind of see that neither of these are the best option. Just the agent on its own, too many tools, prompt's gonna be too big. And then the, just the workflow, obviously too many guardrails. We get an email through, triggers a Gmail trigger, and it's something that the system doesn't quite understand. It's just gonna break and it's not gonna work. So then obviously we combine this into one agent system with workflows at the beginning, less tools, and then a workflow at the end. So if we have a bit of a deeper look into how— just an example of these agents, you can forget this one for just a second. If we have a look at an example of just how these new system for an agent sort of looks, at the beginning we are passing through the correct data. That's why we have a workflow at the beginning, basically passing through the correct data for the agent. And then we have less tools, especially giving the agent less tools, because this just equals less confusion. This is the whole point of this. You want to give it as little tools as possible, just because smaller prompt, less confusion, quicker, cheaper. The whole idea is you want to give it the least amount of tools necessary. And then at the end, obviously, we just have another workflow, which just means the output is going to be easier for our agent, so it can give more of a relaxed output or an output that doesn't need to be exactly as it's going to be when it's presented to the client, or yada yada. Again, we'll get into an example so you can actually see what I'm talking about with the output part. So a good question to ask is, when do I actually use this? Because sometimes you're not going to need a workflow at the beginning, you might need one at the end, not the beginning. You don't know how long to do these workflows, you don't have to do more workflow, more agent, more agent, less workflow. So the way I like to think about it is, can the data that's being passed through be cut down or simplified, or does it need to be cut down or simplified? If we have a look into the system here, let's have a closer look. You can see this is an example of when the data can or should be cut down or simplified. So beginning, we have a Gmail trigger and it's just going to be watching my entire inbox. Then we have an Airtable step and it's just going to return in all our lead information from Airtable. So we have an Airtable base, just all of our leads in there. And then we have an if step that's basically going to match the client emails with the email addresses from the Gmail step. So the email address that we get from this Gmail step, we're going to return all of the client's email addresses from our database. And then this step here is just going to verify that email we got was in our client database. And then the reason we do this obviously is because by the time it gets to the agent, the agent now doesn't have to check if this is a lead or a client. It just knows all the information that gets through is going to be an email from either a lead or a client. So I don't have to worry about actually checking the database and getting all confused. So the second thing to think about is so you can give your agent as little tools as possible. And I touched on this earlier, it's just going to be because there's less confusion, less prompts, going to be quicker, it's going to be cheaper. So if we have a look at the tools here, we've basically only given it 2 tools. This tool here is just an output parser, so it basically forces the agent to, um, output in a specific way. It kind of looks like a tool, but it's not really a tool. We've only really given it 2 tools down here. This one tool is going to update the Airtable records. So when we get an email through from a client, we already know it's from a client. We just want to update the, uh, Airtable base with the content of their email. It could be something like, hey, by the way, I'm going away for a week, so I'm not going to be able to reply to any emails. We can update the Airtable database with that information. But the whole point of having an agent step is because we've done it so that if the agent sees fit, like if it's actually valuable information, then it will update the Airtable database. And if it's kind of not, if it's just like a an automated email from a client, or a client just saying they're running late for the meeting in 5 minutes, something that doesn't really need to be added to our database, then it just won't use it at all. And then we have the Google Docs tool, and this is just going to be— it's going to search a Google Doc and it's just acting as a knowledge base. So when it was to try and reply to the email, the Google Doc is going to be acting as a knowledge base. Yeah, that's the second thing to think about, to try and give your agent as little tools as possible and automating as much as possible with the workflows here. And then the third thing to think about is when the agent's output is the same every time, but needs to again, or can be manipulated to give a better output. So an example of this here, you see at the beginning we have a send message and wait for a response. So basically the agent is just gonna notify me via email when it's got an email that it wants to send and I just have to approve or decline it. And we just have a simple switch step that's just gonna check my response to see if I approved or declined it or gave it some other type of input. And then at the end it's just going to send that message, obviously, if I clicked approve. So in a nutshell, basically to cover what we've just talked about, building these agents in this way will allow you to have more complex workflows, smaller prompts, quicker and cheaper systems, and then less error in your workflow. So combining the workflows and the agents and knowing when to use them effectively is going to give you more complex workflows, quicker and cheaper systems, and then less errors in your systems as well. So we're just going to jump into an example here. You can see I have what is actually a, uh, RAG system that can do a little bit more than just retrieve and upload files to a RAG database. And right now you're probably looking at this and this looks crazy, this looks too complicated to be an actual better system. But if we look into this about what is actually happening, basically what we have here is an agent that's able to upload things to a Pinecone vector store. It's also able to retrieve things from that same Pinecone vector store. The way I wanted it was that every interaction we have with it gets uploaded to a Pinecone vector store so it can effectively learn. Agents like this, quite common, clients will ask for something like this quite often. Agents that can kind of like learn, as I said. So every interaction it has updates the Pinecone vector base. And I've also just given it tools to be able to send message, get messages, and then create Google Calendar events. So just like a really, really simple executive assistant kind of agent. So the way I kind of would have done this before is just having a chat message received node here and going straight to the AI agent and then giving it the tool to retrieve data from the Pinecone vector store. So using that as a tool, and then obviously having these three tools. And then when I want it to upload the interaction to the Pinecone vector store, I would have just had a Google Docs or two Google Docs tools to create a document and then update the document, and then the Pinecone vector store tool again to actually upload data to that Pinecone vector store. And then By this time, I mean we'd have, what, 1, 2, 3, 4, 5, 6, 7 tools plus all of this stuff as well. So we have about 7 tools for our agent, which is just way too many. It doesn't need to be like that. So the way I've sort of built this system as a more optimal way of doing it is having the chat message received and then it goes straight to the Pinecone Vector Store and it will just instantly retrieve the data from the Pinecone Vector Store based on what was in the chat message. So based what was in the chat message input, that'll be passed over to Pinecone Vector Store. It will retrieve the relevant data, and then it will pass both of those data points over to our AI agent, and they can do whatever it was it needs to do. So maybe send an email. And then after it— because it's happening every time— we just create a document, update the document with whatever the output from the agent was. So it's just going to be a status on what it did, basically. And then we just add that to our Pinecone Vector Store. So you can see, this is such a simple solution because basically all we have here It's just an agent that does this stuff. I'm not going to be highlighting that one, but it's basically just doing this stuff. It's basically just sending an email, just getting emails, and just creating a calendar event. That's all the agent needs to worry about. And all the VectorStore stuff is just happening outside of the agent. So we're not confusing the agent with VectorStores. We're just saying, act as you usually would, as if they aren't there. And then we're doing all of this with just workflows before and after. So we're not overcomplicating it for the agent. We're not confusing it. We're just saying basically do as you would without the vector source being there, and then the vector source are just being handled by workflows before and after, like I said. Okay guys, so that is it for this video. I hope you enjoyed it and I hope you learned something. Going forward, I'm going to be building pretty much all of my agent systems like this. I'm going to be looking every time I build an agent, can I automate something before it with a workflow, and then also can I automate something after it with a workflow at the end before the output, because it's just way smoother. I'm having way less errors with my agent bills. The agent bills are actually probably easier as well because I'm not having to worry about like massive prompts with my agents. I'm just automating the stuff that needs to be automated before, and then again automating the stuff that needs to be automated after, and just leaving the bare minimum up to my AI agent so it can do the little tasks it has to the best of its ability. Again, guys, like I said at the start of the video, if you were looking to work with me so we can implement some AI agent systems into your business, then I have left a link to my website in the description. You can go ahead and book up a call and we can talk about some ways to implement AI agent systems into your business. So yeah, like I said, that is it for the video, guys. other video suggestions you'd like to see, please do just drop in the comments or shoot me over an email, and I'll try my best to get around to doing it.
More from Rory

Dynamic Workflows are crazy. This is how to actually use them (beginner's guide)










