- [Instructor] Now that our agent is polished and robust,
it can have one major limitation:
and that is, it's forgetful.
It's one shot.
It takes a look at the weather and the location,
figures out some stuff,
gives me a recommendation and that's it.
I can't ask any follow-up questions
because it'll treat every interaction as a brand new one.
So, the next thing to do that makes an agent very powerful
is to add memory,
transforming it into a true conversational assistant.
So let me give an example of this running
with the agent that we've been using all along.
So, this is an enhanced version of the agent
with memory in it, it's looking at the forecast,
it's asking if there are nearby parks and trails,
and it's going to give me the opinionated recommendation.
Okay, it's given me a bunch of recommendations here
and now, like any follow up questions that I want to ask,
so I could for example, say, "Which of these is closest?"
or "Tell me more about the second one"
or my personal favorite is,
"Help me understand how accessible these are."
So as we can see, because I used the word accessible,
there's like obviously many different ways
that that word can be used.
but I'm really talking about it, what if ADA approved?
What if I have somebody who needs a wheelchair
or a stroller or something like that?
Now it's going into it in a lot more detail, right?
It's showing this Muir Woods Main Trail
is ADA approved with a level trailhead.
There are wheelchair and stroller friendly sections
up to the halfway point.
So again, I can manage my expectations.
If I want the Hidden Valley trail
at Joshua Tree National Park,
well, there's no ADA standard pathway there
and an uneven surface, so it's not wheelchair friendly.
So I can start querying
and asking about the suggestions that it gave me.
The agent didn't know at the beginning
that I was interested in accessibility.
So it followed up after I asked about this
with these ones and said, "Well, guess what?
"Two of the three were not accessible,
"so let's come up with some that are."
And again, it was Muir Woods Trail
as the safest bet for me of those ones.
And it can give me some quick tips
for accessibility in national parks, etc, etc.
I could maybe say,
"Can you find some parks that are more accessible?"
and see what it comes up with.
So, I can see it came up with a long list of parks here.
I'm not going to go through them all,
but like the agent said,
parks that really welcome everybody, pave boardwalks,
smooth ramps, etc.
Muir Woods, again, is there.
So, Golden Gate Recreation Area is there.
And so, it's a case of we can go through these
as well as getting all of this advice from the agent
about how to deal with it.
So we can see we've given memory to our agent
because I was asking about things like these
and referring back to previous answers.
So, it had memory of the previous interaction.
So, it was able to reason across not just
what I'm asking now,
but also the data from previous interactions,
so that it could give me smarter responses.
So let's take a quick look at the code to make that work.
The main part of it is really back in this query model.
One of the things that we had done previously
is that we had the system role and we had the user role
and we created that blob
and we sent it to the model as a one shot thing.
The system defined how the model would behave.
The user defines the prompt that I'm giving
along with the payload of data and to get the response.
In this case, what I want to do
is that whenever I pass in a new user prompt,
I'm going to continue to append that to the conversation.
GPT works in that way where conversation will look like
the system prompts is something,
the user will say something,
the bot will reply with something,
the user will say something,
the bot will reply with something.
So now whenever I call query model,
I'm adding what the user is saying.
So, instead of having that single shot
that gets passed to it,
I'm continuing to update the conversation.
So I can continue to add stuff to that,
so the entire payload gets sent to the model
along with the latest thing that the user has said,
so it has that context of the entire conversation.
So that's pretty much all it is.
It was a very small change to do this
where I'm just going to add-
I already have the system role.
If it wasn't previously set, I will insert the system role.
If it was previously set, I'll ignore it
and just continue to update the user.
And then within the main function itself,
we just continue the conversation with this,
with follow-up prompts.
Do you have any follow-up questions?
If there are, let's call query model.
Let's pass in the message history
and let's pass in the new thing that the user has asked for,
so that we continue to update that conversation.
And that's pretty much all you need to do
to update the simple one shot agent
to be one that has multiple conversation
and has what's called, in agentic terms, it's called memory.
So with these changes,
the agent has now gone from that simple command line tool
to do a single thing to this conversational assistant,
as we demoed.
It can remember what was said previously
and as a result, provide much more helpful
and natural responses.
And next and final lesson,
I just want to go
into a little bit more detail on reflection.