1 00:00:00,05 --> 00:00:02,08 - [Instructor] Now that our agent is polished and robust, 2 00:00:02,08 --> 00:00:04,04 it can have one major limitation: 3 00:00:04,04 --> 00:00:06,00 and that is, it's forgetful. 4 00:00:06,00 --> 00:00:07,07 It's one shot. 5 00:00:07,07 --> 00:00:09,07 It takes a look at the weather and the location, 6 00:00:09,07 --> 00:00:10,08 figures out some stuff, 7 00:00:10,08 --> 00:00:12,08 gives me a recommendation and that's it. 8 00:00:12,08 --> 00:00:15,01 I can't ask any follow-up questions 9 00:00:15,01 --> 00:00:18,02 because it'll treat every interaction as a brand new one. 10 00:00:18,02 --> 00:00:20,09 So, the next thing to do that makes an agent very powerful 11 00:00:20,09 --> 00:00:22,02 is to add memory, 12 00:00:22,02 --> 00:00:25,02 transforming it into a true conversational assistant. 13 00:00:25,02 --> 00:00:27,00 So let me give an example of this running 14 00:00:27,00 --> 00:00:30,02 with the agent that we've been using all along. 15 00:00:30,02 --> 00:00:33,00 So, this is an enhanced version of the agent 16 00:00:33,00 --> 00:00:35,05 with memory in it, it's looking at the forecast, 17 00:00:35,05 --> 00:00:38,07 it's asking if there are nearby parks and trails, 18 00:00:38,07 --> 00:00:44,07 and it's going to give me the opinionated recommendation. 19 00:00:44,07 --> 00:00:47,04 Okay, it's given me a bunch of recommendations here 20 00:00:47,04 --> 00:00:50,05 and now, like any follow up questions that I want to ask, 21 00:00:50,05 --> 00:00:53,02 so I could for example, say, "Which of these is closest?" 22 00:00:53,02 --> 00:00:55,02 or "Tell me more about the second one" 23 00:00:55,02 --> 00:00:57,01 or my personal favorite is, 24 00:00:57,01 --> 00:01:00,05 "Help me understand how accessible these are." 25 00:01:00,05 --> 00:01:08,04 "Help me understand how accessible these are." 26 00:01:08,04 --> 00:01:12,01 So as we can see, because I used the word accessible, 27 00:01:12,01 --> 00:01:14,04 there's like obviously many different ways 28 00:01:14,04 --> 00:01:15,07 that that word can be used. 29 00:01:15,07 --> 00:01:18,06 but I'm really talking about it, what if ADA approved? 30 00:01:18,06 --> 00:01:20,06 What if I have somebody who needs a wheelchair 31 00:01:20,06 --> 00:01:22,07 or a stroller or something like that? 32 00:01:22,07 --> 00:01:25,02 Now it's going into it in a lot more detail, right? 33 00:01:25,02 --> 00:01:27,09 It's showing this Muir Woods Main Trail 34 00:01:27,09 --> 00:01:30,06 is ADA approved with a level trailhead. 35 00:01:30,06 --> 00:01:32,09 There are wheelchair and stroller friendly sections 36 00:01:32,09 --> 00:01:34,04 up to the halfway point. 37 00:01:34,04 --> 00:01:37,02 So again, I can manage my expectations. 38 00:01:37,02 --> 00:01:38,06 If I want the Hidden Valley trail 39 00:01:38,06 --> 00:01:40,02 at Joshua Tree National Park, 40 00:01:40,02 --> 00:01:43,00 well, there's no ADA standard pathway there 41 00:01:43,00 --> 00:01:46,08 and an uneven surface, so it's not wheelchair friendly. 42 00:01:46,08 --> 00:01:48,03 So I can start querying 43 00:01:48,03 --> 00:01:51,05 and asking about the suggestions that it gave me. 44 00:01:51,05 --> 00:01:52,09 The agent didn't know at the beginning 45 00:01:52,09 --> 00:01:55,04 that I was interested in accessibility. 46 00:01:55,04 --> 00:01:57,07 So it followed up after I asked about this 47 00:01:57,07 --> 00:02:00,03 with these ones and said, "Well, guess what? 48 00:02:00,03 --> 00:02:02,05 "Two of the three were not accessible, 49 00:02:02,05 --> 00:02:05,04 "so let's come up with some that are." 50 00:02:05,04 --> 00:02:07,01 And again, it was Muir Woods Trail 51 00:02:07,01 --> 00:02:10,00 as the safest bet for me of those ones. 52 00:02:10,00 --> 00:02:11,08 And it can give me some quick tips 53 00:02:11,08 --> 00:02:15,09 for accessibility in national parks, etc, etc. 54 00:02:15,09 --> 00:02:16,08 I could maybe say, 55 00:02:16,08 --> 00:02:22,01 "Can you find some parks that are more accessible?" 56 00:02:22,01 --> 00:02:26,02 and see what it comes up with. 57 00:02:26,02 --> 00:02:28,09 So, I can see it came up with a long list of parks here. 58 00:02:28,09 --> 00:02:30,04 I'm not going to go through them all, 59 00:02:30,04 --> 00:02:31,04 but like the agent said, 60 00:02:31,04 --> 00:02:34,00 parks that really welcome everybody, pave boardwalks, 61 00:02:34,00 --> 00:02:35,01 smooth ramps, etc. 62 00:02:35,01 --> 00:02:37,00 Muir Woods, again, is there. 63 00:02:37,00 --> 00:02:40,02 So, Golden Gate Recreation Area is there. 64 00:02:40,02 --> 00:02:42,02 And so, it's a case of we can go through these 65 00:02:42,02 --> 00:02:44,03 as well as getting all of this advice from the agent 66 00:02:44,03 --> 00:02:45,06 about how to deal with it. 67 00:02:45,06 --> 00:02:48,01 So we can see we've given memory to our agent 68 00:02:48,01 --> 00:02:51,06 because I was asking about things like these 69 00:02:51,06 --> 00:02:54,05 and referring back to previous answers. 70 00:02:54,05 --> 00:02:57,04 So, it had memory of the previous interaction. 71 00:02:57,04 --> 00:03:00,01 So, it was able to reason across not just 72 00:03:00,01 --> 00:03:02,02 what I'm asking now, 73 00:03:02,02 --> 00:03:04,04 but also the data from previous interactions, 74 00:03:04,04 --> 00:03:06,06 so that it could give me smarter responses. 75 00:03:06,06 --> 00:03:09,07 So let's take a quick look at the code to make that work. 76 00:03:09,07 --> 00:03:13,02 The main part of it is really back in this query model. 77 00:03:13,02 --> 00:03:15,02 One of the things that we had done previously 78 00:03:15,02 --> 00:03:18,05 is that we had the system role and we had the user role 79 00:03:18,05 --> 00:03:19,09 and we created that blob 80 00:03:19,09 --> 00:03:22,03 and we sent it to the model as a one shot thing. 81 00:03:22,03 --> 00:03:25,06 The system defined how the model would behave. 82 00:03:25,06 --> 00:03:28,00 The user defines the prompt that I'm giving 83 00:03:28,00 --> 00:03:31,04 along with the payload of data and to get the response. 84 00:03:31,04 --> 00:03:32,06 In this case, what I want to do 85 00:03:32,06 --> 00:03:36,03 is that whenever I pass in a new user prompt, 86 00:03:36,03 --> 00:03:39,09 I'm going to continue to append that to the conversation. 87 00:03:39,09 --> 00:03:44,01 GPT works in that way where conversation will look like 88 00:03:44,01 --> 00:03:46,01 the system prompts is something, 89 00:03:46,01 --> 00:03:47,02 the user will say something, 90 00:03:47,02 --> 00:03:48,08 the bot will reply with something, 91 00:03:48,08 --> 00:03:50,04 the user will say something, 92 00:03:50,04 --> 00:03:52,04 the bot will reply with something. 93 00:03:52,04 --> 00:03:54,02 So now whenever I call query model, 94 00:03:54,02 --> 00:03:56,05 I'm adding what the user is saying. 95 00:03:56,05 --> 00:03:58,04 So, instead of having that single shot 96 00:03:58,04 --> 00:03:59,05 that gets passed to it, 97 00:03:59,05 --> 00:04:02,03 I'm continuing to update the conversation. 98 00:04:02,03 --> 00:04:04,00 So I can continue to add stuff to that, 99 00:04:04,00 --> 00:04:07,06 so the entire payload gets sent to the model 100 00:04:07,06 --> 00:04:09,09 along with the latest thing that the user has said, 101 00:04:09,09 --> 00:04:13,09 so it has that context of the entire conversation. 102 00:04:13,09 --> 00:04:15,03 So that's pretty much all it is. 103 00:04:15,03 --> 00:04:16,08 It was a very small change to do this 104 00:04:16,08 --> 00:04:18,09 where I'm just going to add- 105 00:04:18,09 --> 00:04:20,04 I already have the system role. 106 00:04:20,04 --> 00:04:23,05 If it wasn't previously set, I will insert the system role. 107 00:04:23,05 --> 00:04:25,01 If it was previously set, I'll ignore it 108 00:04:25,01 --> 00:04:27,03 and just continue to update the user. 109 00:04:27,03 --> 00:04:29,04 And then within the main function itself, 110 00:04:29,04 --> 00:04:31,04 we just continue the conversation with this, 111 00:04:31,04 --> 00:04:32,04 with follow-up prompts. 112 00:04:32,04 --> 00:04:34,01 Do you have any follow-up questions? 113 00:04:34,01 --> 00:04:36,07 If there are, let's call query model. 114 00:04:36,07 --> 00:04:38,05 Let's pass in the message history 115 00:04:38,05 --> 00:04:41,06 and let's pass in the new thing that the user has asked for, 116 00:04:41,06 --> 00:04:44,04 so that we continue to update that conversation. 117 00:04:44,04 --> 00:04:46,00 And that's pretty much all you need to do 118 00:04:46,00 --> 00:04:49,01 to update the simple one shot agent 119 00:04:49,01 --> 00:04:52,02 to be one that has multiple conversation 120 00:04:52,02 --> 00:04:56,02 and has what's called, in agentic terms, it's called memory. 121 00:04:56,02 --> 00:04:57,05 So with these changes, 122 00:04:57,05 --> 00:05:00,02 the agent has now gone from that simple command line tool 123 00:05:00,02 --> 00:05:02,05 to do a single thing to this conversational assistant, 124 00:05:02,05 --> 00:05:03,09 as we demoed. 125 00:05:03,09 --> 00:05:06,03 It can remember what was said previously 126 00:05:06,03 --> 00:05:08,04 and as a result, provide much more helpful 127 00:05:08,04 --> 00:05:10,01 and natural responses. 128 00:05:10,01 --> 00:05:11,05 And next and final lesson, 129 00:05:11,05 --> 00:05:12,04 I just want to go 130 00:05:12,04 --> 00:05:16,00 into a little bit more detail on reflection.