- [Narrator] In the last video, we set up our environment,
but now let's talk about what an AI agent actually is.
And you can think of an agent as a program
that understands your goals, makes a plan to achieve them,
and then takes action.
At the heart of the agent is this core loop.
It consists of these four key steps,
understanding your intent, making a plan, using tools,
and then reflecting on what it did.
So let's talk through these steps.
First of all is understanding intent,
and this all starts with you, the user.
You're going to give the agent a task like finding a place
for hike near where I am.
The first thing that the agent has to do is understand
what it is that you're asking for.
It needs to figure out what your intent is.
And in this case, the intent is to go for a hike
at a nearby national park.
Now you can use a large language model to do that,
so there's many different ways that I could say this,
I want to hike, I want to go for a hike,
please help me with a hike.
And the nice thing there about the large language model
is that instead of doing the traditional natural language
processing to try and figure out what you said,
the LLM can actually artificially understand
that on your behalf and turn that into an intent.
So now once the agent has derived the intent
from what you said you want to do,
now it needs to make a plan.
Now this plan means it breaks down the task
into smaller manageable steps.
So for our hiking agent,
that plan might look something like this.
Well, first we need to know where the user is,
what's their location.
Secondly, we need to get the weather at that location.
Maybe today is not a good day for a hike
because it's raining or snowing, that kind of thing.
So if it is suitable, let's continue.
And to continue would be we'll find nearby national parks,
and we'll get more details about them and then we'll parse
the details about those parks to get hiking suggestions,
and then give the user some opinionated suggestions
based on the weather, based on the parks
and those types of things.
Now all of that involves using tools.
So in order for the agent to be able to make a plan,
it needs to know what tools are available to it.
And once it knows the tools are available to it,
then it can as part of the planning process,
use those tools.
Now typically those tools are going to be APIs,
of course, right?
So the agent needs to know how to call an API for weather,
how to call the API for location,
and then even like the national parks,
how to call the API for that and to parse the results.
And this is where agents get really, really powerful.
Those tools are what the agent uses to intersect,
and interact with the outside world.
Now, a tool, like I said, could be anything
from a simple function like convert Celsius to Fahrenheit,
or it could be a full blown API like searching
for national parks.
And our hiking agent is going to use those tools
that I've mentioned, understand where the user is,
fetch the weather where they are,
and then search for national parks if appropriate,
to be able to hike based on the current weather.
Once it's done all of this kind of thing,
it then needs to reflect,
it will take look at the results of its actions and ask,
well, did I accomplish this goal?
LLMs are well known for hallucination, for example,
and this is one of those steps where you can take a look
at what has happened, look at the user's intent,
look at the details from the tools, look at the suggestions,
and say, hey, I really did think I accomplished the goal.
Or if not, then go back and try again,
or maybe ask the user for more details.
Are you okay to hike in the snow?
Those type of things.
So that's where the reflection part of it
will often give you the results
because the results are good, but if they're not good,
a really good agent will go back,
take a look at its results and go back and maybe replan
and maybe indeed as part of replanning also go back
to maybe get extra intent from the user.
So to recap, this is how you should be thinking
when you're building agents to break it down
into these four steps.
To understand the user's intent, to plan,
to act on that plan, and then to reflect.
And this is the basic loop that all agents will follow.
So next up, we're finally going to get our hands dirty
and we'll write our very first agent.