In this lesson, you'll connect your agent to a repository of customer support documents that discuss many simple issues that the agent could resolve itself. Once connected, your agent will be able to resolve some issues directly and escalate others to the human workflow. Let's take a look. And let's paste in all of the imports that we need. As we've done with every other lesson in this course, and I do hope you're enjoying this course, I've had a lot of fun putting it together, I hope you enjoyed it. Let's, create ourselves a client object here. I'm just pasting this in at this point because we've seen the creation of this before. So here's my bedrock agent. And that's what I'm going to use. Well, first of all, let's get some details about the agent which is deployed inside of this lesson. And so in the same way that we've done before, I'm going to call on, bedrock agent, and I'm going to call, get agent. And of course we're going to need, an identifier. So let's go and add in our agent ID, which we've loaded from an environment variable already in this, notebook. And that will get us some details about the agent. And I want to do that because I'm going to show you an update that I've made to the instruction for this agent. So let's run this control shift Enter. And now I've got all of the details in here. So if we just go ahead and grab all of that and just take a quick look, then it's going to be huge. And there's lots and lots of detail in here. Obviously we can print that out a little nicer if we use, like a json. Let's go here. json, dump string and then we can... We're going to have to do some indents on this. And also there will be some dates and things in here. So we're just going to give it an option to do that. And let's, I think if we print that out, it makes it even nicer. So there we go. Let's run this. So now we can see it's slightly, slightly nicer formatted. And then here we have, various things, including the instruction here. So let's extract that out, specifically and print that out. So I can do that here by just getting the agent instruction specifically out. So let's run that. And here it is. And there's a lot to of this. And you can pass through this and you can decide that you want to change some of this if you want to as well. But the thing in here is I have this, handle issues based on complexity part to the prompt. And you notice here how from lesson one where we had just this really simple one line, instruction, we've now got something much more sophisticated, to help deal with some edge cases and to help the agent understand how it needs to behave. Remember, this isn't the whole prompt. This isn't the whole prompt that the large language model sees. It's it's part of a much larger template, which includes the details of all of those, actions that we have inside of our action groups. In other words, the tools, all of that information is in there, too. This is just the instruction to say how we want that overarching behavior of the agent to be. I've got this section in here where it talks about, elevating or escalating complex issues to for human intervention. And it doesn't necessarily say how to do that. And it can figure that out itself because it's got, that tool that we've got to raise a support case. But it's also got this, simple issues in general product usage questions. If that's the case, then take a look at your knowledge base, which is what we're going to add now. So right now this agent might be a little bit confused because it doesn't have a knowledge base. So let's add a knowledge base in. And as I say we've got a knowledge base already in this account. Ready set up. So let's go and take a look at it. I'm going to use my bedrock agent to the one that you can use to configure. And this time I'm going to get the knowledge base. So I'm going to get some details of this knowledge base just so that we can see that it's there. And I guess take a look at it. And we need a knowledge base ID and that's been set for us by an environment variable inside of this notebook already. So this is really all we need. Now, I'll just load that all into a variable so that we can play around with it a bit more effectively. So let's run that cell. And then I'm just going to dump this out in the same way that I did before. I'm just going to do a json dump string, of this data. Indent it and handle things like dates. So let's run this. And again, there's a lot to this, but just wanted to show you that it was here. And so you can see that it has a lot of configuration. And all of this configuration is something that the AWS console page will do for you. So that's why I'm not necessarily going into this into a huge amount of detail now. But in the next lesson, I'll show you the buttons to click, that will get you set up and running with a knowledge base that you can connect into your Amazon Bedrock agent. And so to connect this in with the agent that we have, I'll just get my agent, client object that I can use. And I'm just going to call one simple function, which is associate agent knowledge base. And so that's kind of all we have to do. In a way, you can think of this as a special case of an action group, much in the same way that code interpreter is a special action group. Well, I guess knowledge base could be seen in that way as well. It's a it's a special set of configuration to connect out to this managed retrieval augmented generation service that we've got. So let's add some details in here so we know where to go. And you can imagine the first couple here are going to be the IDs. So we're going to have the agent ID that we want to connect to and the knowledge base ID. And this is obviously the knowledge base that we're going to connect in to our agent. We then do need the agent version. And because this agent version that we're looking to edit is the draft version. So I'm going to type in draft. So that's the draft version, which is sort of currently in a draft state that we can mess around with. And then we can push it out as an alias. And then finally I do need a description. So this is something that I do need to add. The API requires it. And this is a description essentially for us. So this is I got my knowledge base is all I'm going to do for now, but you could type something in more specific if you wanted to, that you'd be able to read later if that's what you want to do. So let's grab the results from that from when it runs. So I'm going to grab the response out so that we can just take a look at it. But this will do it. This is all we need to do. Apart from then preparing the agent again. So let's run that. And we can take a quick look at the output here. And you can see it's basically just, a tick, a thumbs up. It is, a knowledge base which is in the state of enabled. And essentially, we're good to go. And so we need to prepare our agent and then our alias. And you know what? I'm just going to do this all in one go, because we've done it a number of times now. Preparing the agent. Then we're going to use the helper function to wait for that to finish. And then we're going to update the agent alias, and then we're going to wait for the alias to update and finish. So I can just run this one cell. And all of that will happen for us all automatically. And the helper functions are really coming to the fore here, really being helpful for us. Once that's finished, which it has, we're good to go. And now we get to play around with our fully built customer support agent, and we get to ask it some interesting questions and see what it will do. So I'll paste in here the question that we have used before, just to make sure that it'll still work in the same way as it used to. So we're passing in a session ID here, and then to my message, which includes my email address. I bought a mug ten weeks ago, and now it's broken. I want a refund. So that's good. Let's go and do, invoke agent and print. And it should be, same as it was before. So let me just make sure I run that cell. So I've got my message and session ID defined, and then run this cell and let's see what happens. I've got trace off for the moment, so we'll leave it off, and see what the agent says in response to my particular request. So it's doing all of its orchestration at the moment, and it says, I've processed your request for a refund on your mug, that you purchased ten weeks ago. I've escalated your detail support and obviously, if we turn trace on, we'll be able to see the details of that. But we have faith that the agent, when it reports back like this, that it actually did the right thing. that's good. So now let's go in a different direction. So let's paste this back in. So I've got a new session ID and well at the moment it's the same message. But I'm going to change this to something different. We're going to not have as many details in here, but also the situation is not going to be quite as drastic as I want a refund. So I can say: "my mug, is chipped. What can I do?" Okay. So I haven't said when I bought it. I'm not complaining that I want a refund. Essentially, this is a you could decide that this is a more minor kind of issue. So let's define that and then let's send that to the agent and see what happens. What is the agent going to say? I'm going to turn trace on this time and run that. Let's take a look at what happens. So the agent takes in the message of course, guardrails past this is no problem at all. And it says, let me see what I can find to help you with your chipped mug. And it decides to go to the knowledge base to see if it can find something to help. It finds inside of the knowledge base a number of different articles, including Chip happens dealing with mug injuries, and different documents which are inside of the knowledge base, and then it can use the contents of those documents to try and answer the question. So it's still checking with guardrails. Everything's fine. And it comes back with this response. "According to the search results, here are some options for dealing with a chipped mug: If the chip is small, you can apply a patented MugMend enamel to smooth out the edge, and continue using the mug. For larger chips, it's best to repurpose the mug as a pencil holder." Okay, so you might not agree with the customer support outcome here, but this is actually what it says in the customer support documentation that the agent has. So let's decide that actually we're not happy with that as an outcome. And let's throw a very similar thing back in to the way we did before. I include my email address and, I am not happy. I'll say: "I'm not happy. I want a refund" and let's see what happens there. "I'm not happy. I bought this mug yesterday. I bought this mug yesterday. I want a refund." Okay, so we're escalating here because we're not happy necessarily with being told to, fix the mug ourselves. Or using it as a pencil holder. So let's run this, and this will be part of the same conversation. So let's see what it does. Let's paste back in our invitation. Let's turn trace back on and run this. And I'll scroll up so we can see the answer here. So it's happy with guardrails, which is all fine. Okay. Let's see if we can assist the customer with that chipped mug and request a refund. So it's going through the previous action, so it's going to get my customer ID. It's searching for the purchase. It finds the purchase and then it sends it to support. And in the support request it's saying requesting a refund for a chipped mug purchased yesterday. So it's combined together the different pieces of information from the two different requests that we made, the fact that it was chipped. The fact that I want to refund it, that I bought it yesterday. So it's following the conversation flow and then using agentic reasoning for figuring out what to do and how to handle this response for the customer. So the agent that you've built here has multiple different paths, lots of different things that it can do. It can support a customer with simple problems, or it can escalate to a human workflow when that is required. It figures out where to go based on its agentic workflow, the instructions we gave it, and then the tools which we've provided for it. And why don't you spend some time now Sending different, support requests into this agent and seeing what the responses that you get, can you find other interesting pieces of information from the customer support documentation about maybe what to do if the tea keeps spilling out of your mug? And can you get it to reveal secrets, and get past guardrails? Potentially. And once you've done all of that, then it's time to move to the next lesson, where we'll take a look at the AWS console page for Amazon Bedrock and how some of these things can be set up quickly and easily with just a mouse and a few clicks.