How to build an Ai Email Agent┃(no code, simple tutorial)

Rory Ridgers builds a no-code AI email agent using Relevance AI and ChatGPT that can compose and send emails or retrieve and summarize past messages. He creates two tools, writes a system prompt to control when each runs, connects a CSV of contacts, and links it all via OpenAI schema. Live demos show it sending emails and pulling summaries of specific topics from Gmail.
Chapters
In this video, I'm going to be teaching you how to make an AI assistant that can send emails for you and also retrieve data on the previous emails that you've either sent or received. So how it's going to work is you can just say to it, hey, send an email to Dan saying I'm going to be late for that meeting, and it's going to find Dan's email address and send an email to him saying, hey Dan, hope you're well, just letting you know that I'm going to be late to that meeting later on. And then you can also say to it, did Steve update me on that project yet? Then what it's going to do, it's going to look through your inbox, 'Look for any emails from Steve about the project,' and it's going to come back to you saying, for instance, 'Steve said that the project's going to be ready on Friday.' If you haven't seen me before, my name is Rory Ridgers and I'm an AI enthusiast, and I'm passionate about helping business owners integrate AI into their business. So if that's something you might be interested in, then do consider subscribing and stick around for the video. So let's not waste any more time, let's get into it. So in this video, we're going to be using Relevance AI to create the tools for the agent, and we're also going to be using ChatGPT to be able to actually communicate with this agent. Now you can communicate with this agent through other channels, for instance Facebook Messenger, WhatsApp, or Slack. But in this video, just to keep it nice and simple, I'm just going to create a custom GPT and communicate with it through there. So to be able to do this, we've got two tools. We've got the email retriever tool that's going to be able to retrieve and summarize these emails, and the email generator tool that's going to be able to send these emails. So I'm just going to show you inside both of them. I've already made both of them, and these are custom tools that you have to make yourself. You can't find them on Relevance AI, but they're really, really simple. I'll show you inside them. So first of all, we're going to be using the email generator tool. So I'm just going to hit edit and show you inside this one. So first of all, we got the inputs. We have the user email request and the email recipient. And now the email recipient is obviously going to be the person that we're going to be sending the email to. And then the user email request is just going to be what the user inputs, what they want to send to this recipient. So just after the inputs, we've got an LLM step, another LLM step, and then the send email block on Relevance AI. If we just go into these LLM steps, what this one does is this is going to create the email body based on the prompt from the user. So you can see this is what I've said to it. I've just said, you're an email body writing expert, use the input here. So this input, the email request, to create an email body. Keep the email concise and have a friendly tone. Don't make up any details. If you aren't sure on certain details, then don't specify them or keep them vague. I've I did this because when I was testing it out, I found that it was just making up random details. Like if I said arrange a meeting with Gary, it would make up times and dates for these emails, which I didn't want. And I've said in this case, sign them all off with Rory Ridgers, but you'd obviously put in your name there or whatever you want to sign it off with. I said don't include the subject line, just create the email body and use the name specified in the email request to use at the beginning of the email. For example, if the email request is send Dave an email asking him if he's available for a meeting, and start the email with, hey Dave. So really, really simple. And then the next LLM step, all this does is just creates the subject line. You can see you are an expert at creating subject lines. Use the output from this block here to generate a short email subject line that summarizes the email body. Don't put subject at the start, just output purely the subject line content, because I found that it was outputting subject line and then a colon and then the subject line, which is not what we want. And then just this simple Send Gmail block. You can see I've connected it to my account. If you don't know how to do that, it's really, really simple. Relevance AI walks you through it, so don't worry about that. And to email, this is going to be the email recipient that we have up here in the user inputs. And then nothing in CC, nothing in BCC. Then the email subject is going to be the output from this. The email body is obviously going to be the output from the step before that. Then yeah, that's really all there is to the tool. And now you might be thinking that you have to input the email recipient every time, which obviously we don't want to do because that's just annoying to do. So I'm going to show you later on how it works with that. For now, we're just going to test it with some examples. So in the email recipient, I'm just going to put my email. Okay, so I've put Rory@autonomouslyai.com. And then the user email request, we can just say— I've just said for the email request, see if Rory is still available for our meeting tomorrow morning. We're going to hit run tool and then just see what this comes out with. So the LLM step working, the second one's worked, and then you can see it sent the email. So if we go back up to these tools and look at the outputs, this is the email body tool. It said, hey Rory, hope this message finds you well. I wanted to check in and see if you're available for our meeting tomorrow morning. Look forward to hearing from you. Best. Obviously it signed it off as my own name because I'm just sending these emails to myself. So that might look a little weird. And then the email subject line is just meeting confirmation for tomorrow morning. You can see I'm in my inbox here and the email has worked. It sent to me, so that's all working fine. And now if you want to change sort of the tone of voice or anything in the email body, you can literally just prompt the LLM to do that and it will do that for you. I've left it pretty vague, so it's just kind of doing whatever it thinks. But yeah, you can get a little bit more specific with that on how you want it to speak. So if we hit save, come out of that. Now with the email retriever tool, so I'm just going to show you inside that. We'll hit edit, and then you can see this time we only have one input and it's the email summary request. So this is just going to be what the user is requesting to find from their inbox. So, you know, has this person emailed me recently? Did this person email me about that project? Those type of things. And for this, we literally just have two steps, and the first one is get emails from Gmail. This is just a pre-made tool by Relevance AI, and you can just see we connected our Gmail account again. Emails per page, we just put 100, and this is how many emails it's going to scrape. You can change this to however much you want. It means the LLM after is going to have to do more work scraping through them, but you know, if you're a really busy person and let's say you get 100 emails a day, you might want to change this to 500 or something. Completely up to you, whatever works for you. So the next step after that is LLM step. I've just said you're an expert at retrieving data and summarizing emails, and I've told it to take the output for the most recent emails, the output here, and based off the user prompt, summarize the emails that are relevant to them. So then for this one, I've put some examples just to help it out. Said if the user said, did Katie email me about the recent project that they've been working on, then I want the LLM to search through the emails to see if Katie's emailed And then output, yes, she said she should be finished by Friday. Obviously, if that's what they found in the 100 emails. And then I've just put a couple more examples. This time, if the LLM can't find what the user is looking for, so has Tim scheduled that meeting yet? It's gonna search through the emails to see if Tim's mentioned anything about a meeting. And then let's say that it didn't find anything. It's just gonna say, no, it looks like Tim hasn't scheduled that meeting yet. And then I've just stated again down here, output only the summaries that are relevant to the user's query. I spelled it wrong. Output only the summaries that are relevant to the user's query because I found that it was just kind of outputting all of them, which isn't what we wanted. But what we're going to do is we're just going to test it out. So you can see I've got this email from StackBlitz from my last video where I was using the Bolt tool. And what we're going to say to the email retriever tool is, have StackBlitz emailed me recently? And then just see if it can find that email. So we're going to say— so I've said, has StackBlitz emailed me recently? Let's run the tool. And now what I have found with this is that the get email step will run for a little bit, but usually the LLM step will have already outputted something while that step is still running. That just seems to be how it works for some reason. Then yeah, as you can see, the LLM step is finished, but this step is still working for some reason. But you can see, look, the output. Yes, StackBlitz emailed you recently. Here are the details. It's given me the subject line, the date, the body. StackBlitz requests you to confirm your email address by clicking the link provided. So it hasn't actually just copied and pasted the body, it's actually summarized the body of what was in that email, which is really, really cool. So yeah, this is what will be sent back to you when you're actually communicating with it through ChatGPT. So what we need to do now is quickly set up our custom GPT. So we're going to come over to ChatGPT, hit Explore GPTs, Create, and you can see we've got all of these boxes here— the name, description, instructions. And the name and the description, they don't really matter, it's kind of just for us. So I'm quickly going to put these in and I'll come back. Okay, so as you can see, I've just called it Email Assistant Agent. Description: Send and retrieve emails for a user. I've got to generate a little profile picture because why not? And now we move on to the actual important stuff, the instructions. And I've already made a prompt, so I'm just going to paste it in here and then sort of walk you through what I've said in it. Okay, so this is a prompt I've got. You can see we've got the role here. You're an expert at sending and summarizing emails from a user prompt. And then we've got tasks, specifics, and examples. You can see the main bit of this is the task. So I'm going to give you a brief rundown of what I've put in there. Basically, what I've said is use the tools provided to send and summarize emails. Use the email generator tool to take user inputs and send emails. Use this tool when a user says they want to send an email, and then when they say the name of the person they want to send the emails to, check the knowledge base to find the email that matches that name, and then use that as the email recipient input in the tool. I'll come back to the knowledge base in a minute because we've got to do that as well. And I've said use the rest of the initial user input as the email request input in the tool. So what basically I'm saying there is when a user says send Dave an email saying da da da, what it's going to do is search the knowledge base for Dave and find the email that matches that, because the knowledge base is going to be a long list of names with the emails that match them. And then it's going to use that email for the email recipient input here. And then the rest of that initial input is going to be used in the email request input. So if they say send Dave an email saying, are you still up for that meeting? It's going to find Dave's email, put that as the email recipient input, and then use the 'are you still up for that meeting' as the email request input. So I hope that all makes sense. And then for the second half of this, I've told it how to use the email retriever tool. So I've said, to retrieve and summarize emails, use the email retriever tool. Use this tool when a user asks a question about their recent email. For instance, if a user says, has Sally emailed me about the project? Then use the email retriever tool to use that entire input for the email summary input in the tool. So basically this time it's just gonna use that entire input and put that as the only input in the email retriever tool. Same for the specifics, really simple. I've just said always use this tool when you think a user is requesting you to, and if you don't think the input is sufficient enough for you to be able to fill in the inputs in the tool and ask the user to provide additional information. That you need. So for instance, if they just say, send an email saying, are you still up for that meeting? But they don't specify a name, they won't be able to put anything in the email recipient input in the Relevance AI tool. So what I want the assistant to do is just say, who am I sending this to? Pretty much. And then examples, I've just put 2 examples in here. You can always put more, but I've just put 2 of the 2 different sort of scenarios. Can you tell Sally I'm going to be late for this meeting? And I want the assistant to search knowledge base for the email address of Sally, use that as the email recipient input in the email generator tool. And then use the tell Sally I'm late for the meeting as the email request input, then output the, then output if the email was successful or not. And then for the second one, I've just said the user says, has Dan emailed me about that project yet? And then I want the assistant to use the, has Dan emailed me about the project yet as the email summary input in the email retriever tool, and then output the results of the tool. And now we also need to put a section on here on just a list of the tools and how the assistant can use them. We're going to do that after we've actually added the tools. For now, what we need to do is add the knowledge base for it to reference to be able to get these emails. So I'm going to show you how to do that really quick. So you can see here I've just got this really, really simple list of names. All of these apart from my one at the top are just fake emails. So for this video we're only going to be using my one. But yeah, you can see we've got all of these fake names, fake emails. What we're going to do is we're going to download that, which I've already done. Come over to here, the knowledge base section. Hit upload files and then just select the file that you want to upload and then it should go straight in. And now what we need to do is add these Relevance AI tools into this custom GPT. And Relevance AI make it really, really easy to do this. They have a built-in feature that allows you to do this, so I'm going to show you how to do that. So if we come over to the tools section here, you can see there's this custom actions bit. So we click on that, sort of talks you through how to do it, but I'm just going to show you. We click on the tools we want, so email generator and email retriever. And then here we can generate our API key, but we're not going to do that just yet. What we're going to do first is get this OpenAI schema. So we generate OpenAI schema, copy that, come back over to our CustomGPT, and then we go down to Actions, Create New Action, and then we simply just paste the schema in here. Now as you can see, our tools have come up here— the email generator and email retriever tool. And then what we need to do is we go to Authentication API key, and then this is where we paste in our API key from Relevance AI. So if we come back over, we're going to change this from basic authentication to custom authentication, and then I'm just going to generate this API key and paste it in. So I've pasted that in. We go to custom, and then the custom header name is going to be authorization. So authorization, we hit save. And now what we need to do for this as well is we need to create a privacy policy That's a really, really simple process. I've already done this just because it's kind of boring to watch me do it, but I will leave some instructions in the description of this video on how to do it. It's really, really simple. There's a custom GPT that'll pretty much do it all for you. So then that's all good. So what we can do is we can come out and one more thing to do actually before we come out of it, let's go back into it and you can see the names of our tools here. What we want to do is we want to copy these and paste these into our prompt whenever we reference the tool. Just so we make sure that it's the exact same name of the tool so the assistant knows what we're doing. So we copy that, come out, and then— so I've copied the email generator tool, and now every time I reference the email generator, I'm just going to paste this in. Okay, so I've just gone ahead and done that, and I've also added a section at the bottom of the prompt here called tools. And what it is is just I've pasted the name of the tools and then give the agent a little description on what the tool is and how to use it. So I've done the email generator and the email retriever. It's kind of similar to what I've put in the task, but I've just made it a little bit clearer for the agent. And now we can actually try and test this assistant. But what we're gonna do is we're just gonna try and send a simple email. We can say, so I've just said to it, message Rory Ridgers asking if he can work this Saturday. We can hit enter and then you can see it search knowledge base to try and find the email. Hopefully it's done that. And then it's asking us to confirm or deny the use of the tool, which is good cuz now it knows that it needs to use the tool. It says there was an error generator in the response, but you can see the action is still going. So I'm not sure what's happening there. We're just going to hit regenerate, see if we can get it to try again. So starting action, confirm or deny, we hit confirm. Search my knowledge, starting the action. Looks like we've got to hit confirm again. And then the email to Rory Ridgers asking if you can work this Saturday has been successfully sent to Rory at Autonomously AI. Let me know if you need anything else. Okay, so it looks like I haven't had an email sent to me, which is weird. Okay, so it seemed like it was just in the preview mode. It wasn't working. What I've done is I've created it and actually published the agent. You can see I've just given it the exact same prompt, and if you look, pretty much instantly it sent me this email. Hey there, I hope you're doing well. I want to check in and see if you're available to work this Saturday. Let me know if that works for you. So that's absolutely perfect. You can see here it's used the asking if you can work this Saturday as the email request variable, and the email recipient variable is Rory@autonomouslyai.com. So that's perfect, that's working absolutely fine. And what I'm going to do is I'm going to do it one more time just to show you live what it's actually doing. So I'm going to say Email Rory. I'm just gonna say Rory this time instead of Rory Ridgers and see if it's still able to retrieve my email. I've just said email Rory saying can he send me the report this Friday? And you can see starting action. We hit confirm and then it's talking to Relevance AI and it should say talk. Yep, talk to Relevance AI. And yeah, the email's successfully been sent. So what was happening in the preview, what is it was just saying starting action. And then it was just the agent was saying to me that it's been successfully sent, but the action hadn't actually finished. So now when we've published it, you can see talking, talk to it. And then if we look at the variables, asking if you can send the report this Friday. I'm the email recipient, so it's actually found my email just from my first name as well, which is cool. And then yeah, as you can see, it's emailed me this. Hey, I hope you're doing well. I'm checking to see if you could send this report on Friday. It'd agree, a great help, thanks so much. You can see though it's put name rather than Rory, which is weird. So obviously that's a problem with the Relevance AI tool. So what we can do is we can go back into the tool, this email generator tool, hit edit. Okay, so what I've done is I've just reinforced this prompt a little bit. I've said, um, always do this when I've said to use the first name here. I've said always do this, never just put name, and if you aren't sure on the name, just put hey. So we're going to save that, and now that all should be working fine. So if for whatever reason it isn't sure on the name, just put 'hey,' never put the name in brackets. So now what we're going to try and do is we're going to try and scrape some emails and see if it can return back some data to us. Okay, so I got this email from OpenAI the other day just talking about some changes to the GPT-4 model. So what we're going to do is we're going to ask ChatGPT if it can retry and retrieve this email for us. So we're going to say to it, so we're going to say to it, have I had any emails about GPT-4 recently? And then we're going to see if it uses the right tool. Okay, so it's asking us to confirm and deny use of a tool. Don't know which tool yet. Hopefully it's the email retriever tool. And now we do know this one takes a little bit longer, so we're just going to give it a minute and see what comes out with. Okay, so that literally took maybe 30 seconds. I thought it's going to take longer than that. You can see it said, yes, you have received recent emails about GPT-4. Oh, here are the key details. So an OpenAI reminder on September 30th. If we come over here, yep, that's the date, 30th of September. And then it's just said what's in it, the new model will be 50% cheaper for the input tokens, da da da. Then it's also saying about the other one we got on the same day, saying, uh, they emphasize the benefits of the update, highlighting cost savings and improved features of this new version. So that's awesome, that's worked perfectly. And obviously you can do this on a larger scale. So what you can say to it is things like Um, have I received any emails about this project from anyone? So, you know, has anyone on my team emailed me about this particular project or this particular job? And it will just scrape all of them and find all the emails that are relevant to that. So what we're going to try and do now is we're going to try and sort of simulate that and see if it can give us multiple results. So we're going to say— so we're going to say to it, have I got any emails from software companies recently? I often get emails from things like Make, Relevance AI, uh, Botpress, Voiceflow, things like that. So we're going to see if it's able to return all of these. Okay, so it's really, really cool. You can see all of these emails chronological order. So it's got Gumroad, Replit, OpenAI, Slack, StackBlitz, Make, and Voiceflow. All of these obviously software companies. So that is so cool. It's told us the date and also then a summary of what all of these emails say. That's perfect. So yeah, that worked absolutely perfect, and that's super cool and really, really handy. And as I said at the start of the video, you can integrate this into other channels. So you could have it as a WhatsApp contact, you could have it in your Messenger, you could have it in your Slack channel with your team, so everyone in your team could use it, for instance. So yeah, really, really useful tool, pretty simple to set up as well. Just let you know, everything I've used in this video, the templates will be available for free in the description of this video. And if you're a business owner and you're looking to integrate AI into your business, then I've left a link to my website in the description of this video. You can book in a free consultation, we can talk about some ways that we can integrate systems like this or something else into your business. So thank you to everyone that made it to the end of this video, and if you've got any video suggestions that you'd like to see, please do just put them in the comments.
More from Rory

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










