# I built an agent that automatically replies to my emails.

## Метаданные

- **Канал:** Underfitted
- **YouTube:** https://www.youtube.com/watch?v=XM5D5JZf0mQ
- **Дата:** 17.12.2025
- **Длительность:** 44:43
- **Просмотры:** 1,416
- **Источник:** https://ekstraktznaniy.ru/video/48783

## Описание

Here is the source code: https://github.com/svpino/gmail-draft-loop

To create an MCP server using Zapier: https://bit.ly/4alplzh

I teach a live, interactive program that'll help you build production-ready Machine Learning systems from the ground up. Check it out here:

https://www.ml.school

To keep up with my content:
• Twitter/X: https://www.twitter.com/svpino
• LinkedIn: https://www.linkedin.com/in/svpino

🔔 Subscribe for more stories: https://www.youtube.com/@underfitted?sub_confirmation=1

## Транскрипт

### Segment 1 (00:00 - 05:00) []

Here is what we're going to be doing in this video. I want to build right here on camera a complete multi- aent system that will help me automatically reply to emails that I get from other people. So this system will connect to Gmail and we'll find specific emails, will craft an answer for those emails and will generate a draft reply for those emails so I can later go and just review and just click send. I use this system in a for a bunch of multiple uh situations in my daytoday life. One of them is for example I get a lot of requests for sponsorships and I don't want to engage with clients with first-time clients unless clients understand what my processes uh what requirements I impose and what the pricing is. So I basically detect any emails that come from new clients and then I'm going to reply automatically reply to their email answering their questions. I get the answers from the questions from the database. If there are questions that I don't know how to answer, I'm going to leave sort of like a placeholder. So anyway, all of that happens automatically. It saves a ton of time. I want you to be able to build an uh a system like that. It's going to be pretty simple. Uh I'm assuming that this video is going to take about an hour. I don't know. We'll see at the end, but it should be pretty simple to build from scratch. And this is what we're building. Basically, they're going to be six different agents. The first agent is the orchestrator. This agent here is when you start the system, this agent is going to go to the email finder agent and it's going to ask to connect to Gmail. that agent connect to Gmail and find an email with this specific subject. That's the way I'm designing this. Uh so this finder agent is going to find that email and it's going to attempt to write a first pass of what the good answer would be. that sort of like a first draft will go to a refinement loop agent. This is going to be in a loop and it's going to first critique that first draft, provide feedback, then it's going to go to the drafting agent which is going to use the feedback to improve the writing and then it's going to be back and forth between the critiquing agent and the drafting agent until it's fine, until the email is good enough. And then when I have that draft, that's good enough. We're going to go to the replying agent which is going to connect to Gmail again and it's going to generate that draft reply on Gmail. Okay, so this is beautiful. It's super powerful and super simple to build. Now there is something here that's very important. In order for us to build this system, we first need to connect to Gmail. So in an agentic world in the AI, we have something that's called MCP protocol. Okay, is the model context protocol. The beauty of MCP is that uh different companies, different services, different providers, they create their MCP servers and we can just go and use them in order to get access to their services. So we are going to be using here to connect to Gmail. I'm going to be using Zapier. And the reason I'm using Zapier is number one, it's extremely simple to use. And number two, it it's gonna give me access to up to 8,000 different uh services out there, different applications that I can connect to build whatever I have in mind. I only need for this example uh to connect to Gmail, but it's exactly the same process, okay? To connect to Google Calendar, to Slack, to Jira, to whatever I want to connect to. So before I even get into the code, let's get the Zapier MCP ready with the tools that we need in order to implement our multi-agent system. This should take a couple minutes here. So I want you to go to sapier. com/mcp. Obviously, if you're not signed in, if you don't have an account on sapier, you're going to have to create one. And I'm going to click on start building here. start by creating a new MCP server. Okay. So first I need to specify the client. So what client is going to be connecting this MCP server? The reason uh sappier is asking you about the client is because Sappier needs to give you or wants to give you instructions on how to uh set up that client to connect to the server. I don't care. I'm going to select Visual Studio Code here. I'm actually the client is actually going to be my Python code. Uh but I'm going to select Visual Studio Code for now. and I'm going to call this the Gmail uh drafting loop agent. Okay. So, I'm going to just give it a name. I'm going to create this MCP server. And once I have that, um you

### Segment 2 (05:00 - 10:00) [5:00]

can add the tools that you want to have access to. Okay. So, in this particular case, I'm going to go to Gmail because I want to connect to Gmail. And then I want two tools because I do not want to give access to my agent to stuff my agent shouldn't be able to access. Okay. So I'm going to add find email. Okay. So this is going to return an email given some criteria and I'm also going to uh give it access to create a draft reply that is I'm not giving this uh agent or the agent that I'm going to create I'm not going to give it access to send emails. I don't want the agent only create a draft reply. Okay. So I'm going to select those two tools. That's awesome. I'm going to click connect. And now we have this. Okay, we have an MCP that has access to these two particular tools. That means that any agent that uses this MCP will be able to find emails and create draft replies. Another way of implementing this if you want to [clears throat] be a little bit more specific and I'm doing this just for the sake of time but you will craft an MCP server with access to finding emails and you can have a separate MCP server with access to creating the draft replies. So two separate MCP servers so each email only has access to the tools it needs. You don't have to do it that way but that is a way that you could actually do it. Okay. So now we're going to go to connect here. And in this connect tab is where you're going to get the instructions to configure Visual Studio Code because that's the client that I selected. I don't care about that. The only thing that I care about is this particular URL. This URL right here is the one that's going to give me access to that MCP server. Okay. So, we're going to come back to this as soon as I get access to that MCP server. Now, obviously, one thing that has not happened here yet is that for you to have access to Gmail, you need to specify what Gmail account you have to create a connection. You have to authenticate yourself. Now, I did that off camera. I have a separate uh MCP server that does that. You're going to have to do that yourself where you enter your Gmail username and password and Sapier gets a hold of that authentication. So when a request comes into this MCP server, Sapier can reddex the request and get the data from your server. We're going to come back to Zapier in just a second. Right now let's go and create our ADK project, our Google ADK project that's going to have our multi-agent system. Now, to do that, I'm going to start by creating a folder. I'm going to call it Gmail uh draft loop. I'm just making the name up. Gmail draft loop should be fine. I'm going to do that here. I'm going to go inside and then I'm going to use UV to initialize that repo and get access to a virtual environment. If you don't know what UV does, uh, just stop this video, go and watch a UV video. You really want to be using UV for virtual environment stuff. When after having this, I'm going to add I'm going to just go to the history because I do not remember the command, but I basically want to add uh just going to type this. I'm going to add access to Google ADK and the Google Genai packages. Uh, I don't think I need the geni package. I'm going to add it anyway. So, that line, it's like a pip install. It's the same thing. Gives me access to those two libraries. And now I'm just going to run the ADK command. The ADK, that's the Aentic development kit, the agent development kit uh framework from Google. And I'm going to use the create command to create an application. So that will be uv run adk. And now I want create command and I'm going to create an agent. I'm going to call it the Gmail agent. Okay. So this is going to now take me uh through a ser a series of steps. Uh it's going to say which model do you want? Uh you know I'm going to say I'm going to fill out this later. I'm going to say two. And as you can see this created here uh this created some code. So if I list this stuff you can see I have a Gmail folder and that Gmail folder contains an

### Segment 3 (10:00 - 15:00) [10:00]

environment variable contains an init py and contains the code for my agent. Okay. So I'm going to go to Visual Studio Code now and I'm going to open that project right there. There we go. So, here is the project that I just created. I'm not going to need uh the chat window. update this right now. Uh as you can see, here [snorts] is what the create command gave me. Right? So, it's a very simple agent. Um there is no model here. Uh so, we're going to have to fill that out. Um there is some description and some instructions. Okay. So, just to test this out so you can see this working, I'm going to fill in the model here. I'm going to say Gemini 2. 5 lash. This is very small, very fast model. That's all that we need here. And for this to work, I'm going to need an API key. Uh, you can do that by going to Google AI Studio. If you go to Google and say, "Hey, Google AI Studio API key," you are going to be able to just create an API key here. I'm going to name it the Gmail uh draft loop API key. And obviously, I'm going to delete this after I recorded the video. But let's create a new key. Uh where is it? Oh, there we go. Here is the key. Uh can I just copy the key? Yes. And now we're going to go to the environment here and say Gemini API key. And now we want this to be the API key. You need something else which is the Google genai use vertex AI equals zero. This there are two modes when you're creating an agent in for Google ADK. You can create it on Google AI Studio or Vertex AI. I'm going to say this is zero. So, it does not use Vertex AI. Uh, this should be enough. This should work. The only thing that's left for me right now is to run this project. Uh, let me go back to the uh terminal and I'm going to say UV run ADK run and the name of the agent is Gmail, right? I think it is email. So, as you can see, it's, you know, it's asking me for my input. I'm going to say, how much is 2 + 2? And the agent is answering 2 + 2 equals 4. Okay, so this is actually working. By the way, there is another way to run this agent, which is instead of calling it run, you say web. Okay, and that will open a web page uh with an input. And it's pretty much the same thing, but you get a lot of information. So you get to debug the agent. You get to see what the events are, the session state, etc. I'm going to be just for simplicity. running it here in the terminal. But I just wanted to show you we have one agent. That agent is working. So let's now get down to business. Remember, this is what we want to build. So there are a few agents that we want to build here. First thing I'm going to create is just because I want to keep the prompts in one file. I'm going to create a prompts py file. Here is where I'm going to be copying the prompts of every one of those agents. Okay. So now let's go to the autoresponder agent. Okay. I have the code here. So I'm going to copy and then we're going to go line by line making sure we understand what's happening. So this is the code of that autoresponder agent. Let me go back here. I'm going to replace this root agent with this root agent. And obviously this here uh this is actually going to be a sequential agent. Okay. So this is an agent. I'm going to call it email autoresponder. Now notice that I have sub agents here. Okay. And I'm going to explain what those sub agents are in a second. And the description of this agent, I'm going to move this up. The description is this binds relevant emails and uh iteratively drafts replies. Okay. That's what this agent is going to do. Again, this is going to be the orchestrator here. Okay. Now this uh root agent here is a sequential agent because this is what in ADK is called a workflow agent. So basically a workflow agent will rely on a bunch of sub aents that will be executed in sequence. So

### Segment 4 (15:00 - 20:00) [15:00]

that means that when the entry point gets here, this sequential agent will first execute the email finder agent which is this one here. Then it will execute the refinement loop which is this one here. And finally it will execute the replying agent which is this one here. So whenever you want to enforce a sequence of agents, one agent after the other running after another agent, you will use a sequential agent. There's no LLM here because I don't need an LLM here. I just need that sequence to always execute that way. Okay. Now, obviously for this code to work, we need this email finder agent. Okay. So let's define I'm going to find it here. I'm going to paste it. Uh, this is going to be an LLM agent. I'm going to add here the LLM agent part. Notice that we are going to need some instructions. I'm going to just copy those instructions, the email finder instructions, and we're going to analyze those instructions obviously in just a second. So now I can say from prompts import email funing instructions and we have an ML uh tool set which I'm going to explain in just a second what it does. Uh we need streamable HTTP connection. Yep. And we need that. Okay. So let's go and see what this is. Okay. So, first of all, this is our email finder agent. Actually, I'm going to just comment these two out. So, I don't care about those two. This is the email finder agent. It's going to be using the Gemini 2. 5 flash because it's very easy the task that it has to do. So, a fast uh relatively not smart model works. The description is this is the assistant that will automatically find an email. And here are the instructions which we are going to read. And notice that I'm giving it access to a tool. Now you see this big URL right here. This is if I go back to Zapier, this is the URL that's behind this. Okay. So if you copy this URL, you pasted it here. Now you're giving to your email finder agent. You're giving it access to Gmail through that MCP protocol. That's beautiful. It's very simple to do. Okay. So, now let's see the email finder instructions. Okay. Let's go here, which is the prompt that I created and it's uh you're an email a triage agent your job. Find the latest email with the subject line that matches the entry from I should spell this right from the user and draft the first response to it. So in other words, hey just I'm going to give you a subject find the email with that subject and draft a response respond for it. Okay, reply for it. Now remember this is just for me to simplify this system. Ideally you don't have to do the find the subject. you can just return every unread email or something like that. Okay. To draft a response, uh I'm giving it instructions here how to draft a proper response and at the end I'm saying please output only the draft text. So don't reply with subject lines. Do not add any instructions, explanations. Just reply with the draft text. Okay, that is the instructions for my LLM agent. Now, notice this is an LLM agent, not a sequential agent. We don't need the sequential agent. Now, we just need an agent with access to an LLM. That LLM is going to be Gemini 2. 5 L. Okay, it has access to the tools. So, this LLM is going to be smart enough to say, okay, I need to find an email with a subject line. How do I do that? It's going to look at the tools and it's going to realize that there is one tool that we added through sapier and that tool uh gives it access if we go to configure that tool is called find email and it's going to use that tool. It's going to check the parameters. It's going to configure those parameters and it's going to do that for us. We don't have to specify anything. The LLM is going to know how to do it. And notice one final thing which is the output key. Okay, remember the goal of this email finder agent is to draft the first attempt to response. That response we're going to get back in this

### Segment 5 (20:00 - 25:00) [20:00]

[clears throat] output key. So the framework, the Google ADK is going to save that response on this key so we can later reference the key and use that response. Now, I think we should be able to run this as is. Uh, let's see if that is true. Uh, let me go here to my This is my inbox. I'm going to send an email to this inbox here. And that email we can reference then. So, let me just type the email. I'm typing it off camera. I just don't want anybody to see my email. And I'm going to call it test one, two, three. And I'm gonna say, "How is your day today? Thanks, me. " Uh, actually, John. Okay. So, I'm sending an email. You're going to see that email right here. By the way, it's going to look like it's been read because I'm forwarding automatically all of the emails from this inbox to a different place. But at some point, if I send this correctly, did I send this email? Did I even send it? Yes. Okay. So, we should be able to see that email coming through here. There we go. So, that's the email. How is your day today? Thanks, Jean. And the subject is test one, two, three. So, let me run the ADK here. UV run ADK. Run. And the name of the agent is Gmail. Uh, this is going to ask me, okay, just tell me what the subject is. I'm going to say the subject is test one two three agent is going to go it's going to do its thing if you configure everything correctly and again it's pretty simple to get it correctly this agent should be able to find that email as you can see here it says hi John so it knows that the email ended up with John as an AI I don't experience this in the same way as a person does, but I'm ready to assist you. Please let me know how I can help you today. Thank you. Blah. So, this right here is the first draft of the email that was generated by my AI agent. Now, obviously, and this should be obvious just by reading this, this AI is even saying I'm an AI. So, this is not great. This is actually a very crappy response to an email. I don't want to just say as an AI, I cannot answer your question. That's why you can make this way better by having this refinement loop right here. this refinement look. You can craft it the critiquing agent and the drafting a uh the drafting agent. You can craft those prompts in a way that you can generate very strong, very focused and correct responses. You don't have to rely on stuffing one agent with the entire job. Just find the email, craft a good response. You don't want to do that. Instead, you can offload that task to this refinement loop agent that's going to go critique, draft, incorporate the feedback, get back to critique, send back the feedback until you're done. Okay, that's what we're going to do right now to extend the system that we have. Okay, so let's go back here and notice that the second sub aent of my sequential agent here is the refinement loop. Okay, so let's bring that agent over here refinement loop. This is what that agent will look like. Okay, so this is going to be a loop agent. I'm going to import loop agent here. So a loop agent is basically a workflow agent that you're going to specify the order of the operations and how many times you're going to loop through them. So in this particular case, I'm calling this agent refinement loop. The sub agents are called critiquing agent and drafting agent. And I want to go through this loop a maximum of three iterations. So that means that if even if you go back and forth back and forth, you're only going to do that up to three times. So they don't run forever. Okay. So now for this to work, obviously we need the critiquing agent and the drafting agent. So I'm going to bring them here. Let's start with the critiquing agent. I'm going to paste here the critiqueing agent. This again is an LLM agent name critiquing agent. The model is going to be Gemini 2. 5 flash. Again, this I'm going to say do not include content. So, this is going to rely only on the

### Segment 6 (25:00 - 30:00) [25:00]

variables that come through. I don't want to keep memory. anything like that. These are the instructions that we going to have to import. I'm going to add this for now. uh the description of the agent, something simple that explain what the agent does. Not a big deal. And notice that the output key out of this agent, just like we did here, we're going to the output the the result of running this agent, we're going to save it in this criticism output key. Okay. Now, let's bring the instructions and we're going to put them in the prompt. So, I have my instructions right here. And these instructions are uh basically where you're going to spend a ton of time trying to make these instructions strong for your use case. So, you want to uh provide feedback based on your specific criteria of what a good email looks like. In this particular case, I don't care about the specific instructions. Don't worry too much about that. What I do care about is I want you to notice how I'm saying this is the draft to review and I'm specifying inside squiggly you know squiggly brackets it's not square brackets forgot the name of this type of bracket I'm specifying current email so that's a variable that current email is precisely the output key from the first agent it. Okay, so that output key goes here. The framework will automatically replace this variable with the email that was generated by the first agent and everything else. The task here is basically bunch of instructions on how to critique that text and at the end I want the output of this agent to be or to become this particular e. So, it's going to be saved with this particular key. Why? Because I need the criticism in the drafting agent that now I'm going to bring here. Let me just go find drafting agent. I'm going to add it right here. And drafting agent is going to be very similar to critiquing agent. Uh you get same model. I'm just I don't want memory. I don't want anything. Uh here [snorts] is the instructions that I'm going to bring. Now the prompt. Uh there is something new here and is this tools which is called exit loop. We're gonna look at it in just a second. And there is another output key which is current email. So notice how this works. High level. First agent produces a draft and we save it in current email. Then it goes into the critiquing agent which produces criticism or feedback. This drafting agent is going to use that feedback. You'll see that in the instructions in just a second. And it's going to produce a new copy of the email, which we're also going to save in the current email. So, every time we go through a loop, we critique and we draft. When we're done, when we're out of that loop, what we have is the latest version of that email is going to be right here in current email. Okay. So, we're missing instructions. I'm going to grab those instructions. Here they are. I'm going to paste them right here. Okay. So, the instructions, what do I say? I say, okay, so this is the current draft and I reference the variable. Okay, curly braces. I forgot that before. within a double curly braces. I reference the current draft and I reference the suggestions, the feedback, the criticism using also the output key from the uh critiquing agent. And now the task is analyze the feedback and apply the feedback to the current name. Pretty self-explanatory. Let's import this here. And now we have all of our agents, I think. Okay, there is one more thing. Uh, we're still obviously missing this replying agent, but there is one more thing and is access to a tool. I'm calling that tool the exit loop tool. So, what's going on here? Well, remember that when we created this loop agent, we want to go through it a maximum of three times, but we don't have to go three times through it. If we get after one revision, if we get a very good draft, we want to stop at that point. Okay? So notice that if I

### Segment 7 (30:00 - 35:00) [30:00]

go to the prompt in the drafting instructions, we are going to look at something that says if the critique is exactly no issues found, you must call the exit loop function. Right? So basically I'm saying I'm telling the drafting agent if you receive as feedback capital no issues found, I want you to stop. call a function that will stop this loop. So I don't have to go three times through it. Okay? So notice here as part of the critiquing instructions that we say if the draft is coherent, addresses the topic uh and has no glaring issues, errors, respond exactly with the phrase no issues found. So that is the mechanism that we're building sort of like the the special message that one agent will send to the next agent so the next agent does not do any more work that it has to do and basically calls the tool to stop the process. So let's take a look at that tool is a very simple tool. It's just very simple function and this is what it's going to look like. I'm going to just add it right here. So this is an exit loop. That's the tool. This is what you have to import if you wanted to just you know basically create a tool that an agent will be able to call and then we are going to do this and return empty JSON file. So usually tools return JSON. So that's what I'm returning an empty JSON file. And what I want to do here is hey just escalate this here and we can talk about it uh later. This here will basically stop the loop agent from working. Okay. So the loop agent let's say is in the second loop. If we pass this escalate true basically the loop agent is going to stop. Okay. So that's what we want to do whenever we find no issues found. If we don't never get to no issues found, this loop is going to continue working until we reach three iterations. Okay. All right. So this is pretty cool. Uh we can try it out before we just add our final agent. So let's rerun this. Let's make sure everything works. I'm going to stop this and I'm going to rerun it. say the subject is test one two three. So we're going to use the same email that I sent myself. And let's see the loop working. Let's wait for it to read the email. By the way, it's beautiful when you run this ADK. If you run it on the web, uh you can see all of the events that actually we can do that so I can show you exactly what it looks like. But it's uh yeah, it's actually I'm going to do that. I'm going to just stop it and I'm going to do ADK web. And as you can see, this will open [clears throat] a URL here. And we can go and we can open that URL right here. And here it's you can see that it's already auto selected the Gmail agent. And here I can say subject equals test one two three. And again this is going to work. Oops. No module name prompts. Oh, there we go. There is a little problem here with the way I'm importing the libraries. And in order for me to fix this, I think I have to do human prompts. This should work. So if I rerun this Yeah, because I'm referencing uh a file within a folder is didn't like it. It's fine. Uh subject equals test one two three. Okay, there we go. Let's see what happens now. So notice that this is calling a tool Gmail find email and by the way you can review here everything that's happening you can go to events you can see the state uh session artifacts you can see everything that's happening this uh agent here the process first it started by calling a tool and the tool is Gmail find email so you can see here this is the tool if you click on a tool you can get everything that it

### Segment 8 (35:00 - 40:00) [35:00]

returns signature Sure you can get all of that good stuff. You can navigate through the events over here. So the next one here uh this is the result. So this is basically that email coming back. This is the answer that somebody crafted. Let me go to the event. Uh yeah, hi John. My day is going well. Thank you for asking. Please let me know if there is anything I can help you with. Thanks. Going to the next event. Uh this event is the critique agent. Notice how it's is selected here. The critique agent read my the first draft and saying no issues found which is great. So let's go to the next event which is this. The next event is the drafting agent. That's calling the exit loop because there is nothing to draft. It received the secret handshake message. No issues found. So this is just finishing and that's pretty much it. So, this is what the web looks like. It's pretty cool to see it like this. I really like it. Uh, so yeah, let's go back and let's finalize our system is almost done. Now, we have the ability to draft a message, to review that message, to update that message. We just need the ability now to create automatically create that draft reply. So, in order to do that, we need this replying agent. Uh, we're gonna bring it back if I can find it. It's right here. So, I'm gonna bring back this replying agent. This replying agent again is our final piece of the puzzle. This replying agent will also have access to, you guessed it, the Sapier MCP. Why? Same MCP, same URL in this case because we added access to two tools. one to search to find an email. The second tool that we added access to this uh agent is to uh create that draft reply. We need some instructions here which I'm going to copy. Let's see if I can find them. There you go. I'm going to paste them here. And the replying instructions should be pretty simple. You're an agent with access to create draft replies to emails. your job. Find the latest email with the subject line. Remember, now we need to find the same subject line that matches the entry from the user and create a draft reply using the following text. And you know, curly braces, we're referencing the output key, current email, which remember that's where we've been storing our current email. Actually, if I go back here and I go I close this and I go to the state. Well, the state here only has criticism. But if we go within one of these uh let's see, let's see if they display it here. So, you can see the actual state. Okay. here actions and you see this state delta. That's basically this current email changed and it's displaying here what that current email looks like. So that event is changing the state. So you can basically track the state and what the values are and what not just by using the web. Okay. So going back here, let's take a look at this agent. We apply an agent. We need to pass the instructions here. Okay. Uh I'm using the same model. description does not matter. Instructions are those and access to the tools. Obviously, if I remove access to the tools, now this replying agent will not know how to create the draft reply. It needs access to Gmail in order to do that. One thing that I wanted to mention before I test this out, do the final test here, is that I've been using here for every single agent, I've been using Gemini 2. 5 Flash because it's a very fast, easy model to run. You don't have to. You can have different agents use different models. Like for example, maybe to drafting the email, you want a very strong model, right? a model that knows how to write good emails. Maybe you want to use Gemini 3. 0 or Chad GPT or I mean GPT5 or whatever model you want to use, you can use it. And for other tasks, for simple tasks, you can have faster models, smaller models that are cheaper to run. So you can mix and match however you want that uh to use that. Okay, so I think we have our entire system ready to go. This is the system. Let's run our system and let's see what happens. Okay.

### Segment 9 (40:00 - 44:00) [40:00]

So, I'm going to just stop this. I'm going to rerun it. Remember, it's ADK web if you want to run it on the web. ADK run locally in your console in your terminal window. I'm going to go back here. I'm going to just refresh. So, I start from nothing. Did I refresh? Yes, I did. And now I'm going to actually let me check here. Oh, I already run it. My day is going well. Thank you for asking. Let's just remove this. I'm gonna resend an email. I'm going to do some like uh let's see. Let's send another email. And I know you cannot see me typing now, but that email is going to say something like a new email. One, two, three. I'm just adding the one, two, three in the subject line so it's easy for me to find that email later. Can you tell me how much is 27 - 7, please? And thank you. And I'm going to say Lydia or Mary, I don't know. Let's just send that email. Okay. So, that email will show up here. Uh let's wait for that email to show up and then we can run our system and see what happens. Just takes it's a little bit of delay because there is a delay sending the email. It actually waits. So, here it is. A new email one two three. Can you tell me how much is 27 minus 7 please and thank you Mary? Okay. So now we can actually uh run this. I'm going to open I'm going to clear the session. So I'm going to open this from scratch and I'm going to say uh okay process email with subject and new email one two three. Okay. So let's see if I can it can find that email and it can craft a response. All right. So, it's doing the Gmail find email and now it's creating the draft reply. Let's go back here. Let's wait. There you go. Hi, Mary. Thank you for your email. 27 minus 7 is 20. Please let me know if you have any other questions. Thanks. and my name. Obviously, this is a problem with my prompts for the critique and the drafting. That's where you go and you paste here or you make these prompts as strong as possible. Okay. So final thing that I want to answer before giving you access to all of this code, I'm going to add it to GitHub so you can just go at it and do whatever you want with it is I want you to remember that uh there is a simple version of this system. You can do everything that you see here with a single cult or a single agent that calls an LM. You can do it. Okay. The reason you shouldn't do that, and I recommend just breaking it down into smaller steps, it's because you're gonna have more control into the quality of the output of that agent. If you try one single agent in a single prompt to find the email, craft a good reply, and just generate the reply on Gmail, you're basically going to be limited by what that prompt can do in a single shot. Instead, by having this refining loop, you add yourself the ability to iterate and find better answers, maybe bring a separate model, a different model to the mix. So maybe you use uh GPT5 to critique and you use Gemini to write and incorporate that feedback. That will allow you to have better quality outputs in a very single system. As you can see, we built this. I don't know how long it took. Uh, probably an hour. How long it took? 45 minutes. So, 45 minutes to build the entire system from end to end. So, I hope you found this helpful and I'll see you in the next one. Bye-bye.
