- [Speaker] Now that we understand the basics of AI agents,
it's time to dive into the code for our hiking agents.
In this video, I'd like to take a look
at the high level tour of the project files
so that you can understand how everything fits together.
So the first agent that we're going to be looking
at is in this hiking agent folder,
and there's five Python files that will make up our agents.
They're main.py, location.py,
parks.py, weather.py, and config.py.
I've also included requirements.txt here.
And these are the dependencies that you need
to be able to install for the code to be able to run.
I'm using requests, ollama, and geocoder libraries.
Okay, so looking at the source code,
let's start with config.py.
Now this is a very simple configuration file
where we store the API key that we're going to use
for the National Park Service. In order to use this agent,
you're going to need to get a free API key
from the NPS website and paste it in here.
So you can go to this URL to get it.
You just fill out a basic form,
you say what it is that you're going to be using it for.
I said I'm using it for tutorials,
and they'll email you an API key that you can paste in here.
Okay, next up is location.py.
And this file is going to use the geocoder library
that you can see here to determine the person's location
based on their IP address. And this is the first step,
of course in our agent's process.
And we can see here that it's using the geocoder
to get your location by just saying g equals geocoder.ipme.
And what will happen often is it will actually give you back
a state that might say California or Michigan or Washington.
And I've written this simple little helper function here
to turn it into abbreviations.
And this is because other things
such as the National Parks tool won't take the full text
like California and it requires CA instead.
So this just turns it into an abbreviation.
The next file is weather.py. And once we have our location,
of course we need to check the weather at that location.
And here's where weather py comes in.
It uses a free weather API from these folks
at open-meteo.com, and this will get the forecast
for our latitude and our longitude.
It also has a helper function
that will give us a nice little summary of today's weather.
And it has a number of things
like codes and that kind of thing in it.
And by the way, the latitude and longitude,
we're able to get also from location.
I was talking about state earlier on, but we're also getting
the latitude and longitude from that one.
So this little helper function is really useful,
giving us the state for the national Parks API
and giving us the latitude and longitude
for the weather API. Okay, next up will be park stop py.
And this is the fun part.
So parks.py will use the National Park Service API.
You saw how to get the API key for earlier on,
and this will find parks and trails in a given state.
Now there's two functions in here.
One is to get a list of the parks. It's called get parks,
and the other is to get the list
of trails within a specific park.
So we can see we're using both of those here.
And you can imagine how we're calling them
is that first of all, getting parks
with the state code will list a bunch of parks
that are close to us in the same state that we're in.
And then once we've gotten a number of them,
we can then use the iterate through each of them
with their code to get some details of that park.
And then our tool will be smart enough to be able
to use an AI to parse those details
to come up with a recommendation.
So this is the less the tools that are available to us.
So we have location to be able to determine our location.
We have parks that gets details of parks,
and we've weathered that gets the weather
at our latitude and longitude.
We've also seen config.py where we can put our API keys.
And right now we only need one
for the National Park Service.
So then finally I want to look at main.py,
and this is the heart of our agent
and it's where we orchestrate all of these pieces.
And it has been built in the same pattern
that we spoke about earlier on for agents
where we're understanding intent, we're making a plan,
we're using tools to achieve that plan,
and then we're reflecting on that.
So you'll see here this main.py is just
going to do all of that. I would say the best thing for you
to do is really look at this code in detail.
You're going to be editing this code later on
to extend the functionality,
but you'll see the steps here within the main function.
Step one is to look at your location
and analyze the weather.
We're actually going to do a quick reflection there
to see if the weather is good enough for a hike.
If it is, then we're going to gather the park and trail data.
We're going to use models, the open AI model, the GPT 20 BOSS
that we installed earlier to be able
to parse this information for us.
Step three then would be again,
using the model for hiking recommendations,
getting those opinionated recommendations.
And then finally we'll handle some follow up questions.
And this was the code that I executed earlier on
where you saw it was able to find some national parks
that I could hike in. I'm currently in California
to find some that are near to me.
And that's a quick overview of the project structure.
In the next video, I really want to go deeper
into this main.py so you can understand
in detail the agentic loop.