1 00:00:00,06 --> 00:00:03,09 - [Speaker] Now that we understand the basics of AI agents, 2 00:00:03,09 --> 00:00:07,03 it's time to dive into the code for our hiking agents. 3 00:00:07,03 --> 00:00:08,08 In this video, I'd like to take a look 4 00:00:08,08 --> 00:00:11,05 at the high level tour of the project files 5 00:00:11,05 --> 00:00:14,05 so that you can understand how everything fits together. 6 00:00:14,05 --> 00:00:16,00 So the first agent that we're going to be looking 7 00:00:16,00 --> 00:00:18,02 at is in this hiking agent folder, 8 00:00:18,02 --> 00:00:21,07 and there's five Python files that will make up our agents. 9 00:00:21,07 --> 00:00:27,00 They're main.py, location.py, 10 00:00:27,00 --> 00:00:32,02 parks.py, weather.py, and config.py. 11 00:00:32,02 --> 00:00:35,07 I've also included requirements.txt here. 12 00:00:35,07 --> 00:00:38,02 And these are the dependencies that you need 13 00:00:38,02 --> 00:00:40,08 to be able to install for the code to be able to run. 14 00:00:40,08 --> 00:00:44,05 I'm using requests, ollama, and geocoder libraries. 15 00:00:44,05 --> 00:00:46,00 Okay, so looking at the source code, 16 00:00:46,00 --> 00:00:48,08 let's start with config.py. 17 00:00:48,08 --> 00:00:51,03 Now this is a very simple configuration file 18 00:00:51,03 --> 00:00:54,01 where we store the API key that we're going to use 19 00:00:54,01 --> 00:00:57,03 for the National Park Service. In order to use this agent, 20 00:00:57,03 --> 00:00:59,04 you're going to need to get a free API key 21 00:00:59,04 --> 00:01:02,02 from the NPS website and paste it in here. 22 00:01:02,02 --> 00:01:04,04 So you can go to this URL to get it. 23 00:01:04,04 --> 00:01:05,09 You just fill out a basic form, 24 00:01:05,09 --> 00:01:08,03 you say what it is that you're going to be using it for. 25 00:01:08,03 --> 00:01:10,05 I said I'm using it for tutorials, 26 00:01:10,05 --> 00:01:14,01 and they'll email you an API key that you can paste in here. 27 00:01:14,01 --> 00:01:17,04 Okay, next up is location.py. 28 00:01:17,04 --> 00:01:21,01 And this file is going to use the geocoder library 29 00:01:21,01 --> 00:01:25,01 that you can see here to determine the person's location 30 00:01:25,01 --> 00:01:28,05 based on their IP address. And this is the first step, 31 00:01:28,05 --> 00:01:31,01 of course in our agent's process. 32 00:01:31,01 --> 00:01:33,03 And we can see here that it's using the geocoder 33 00:01:33,03 --> 00:01:38,01 to get your location by just saying g equals geocoder.ipme. 34 00:01:38,01 --> 00:01:41,03 And what will happen often is it will actually give you back 35 00:01:41,03 --> 00:01:45,05 a state that might say California or Michigan or Washington. 36 00:01:45,05 --> 00:01:47,05 And I've written this simple little helper function here 37 00:01:47,05 --> 00:01:49,04 to turn it into abbreviations. 38 00:01:49,04 --> 00:01:51,06 And this is because other things 39 00:01:51,06 --> 00:01:55,00 such as the National Parks tool won't take the full text 40 00:01:55,00 --> 00:01:57,08 like California and it requires CA instead. 41 00:01:57,08 --> 00:02:00,09 So this just turns it into an abbreviation. 42 00:02:00,09 --> 00:02:04,06 The next file is weather.py. And once we have our location, 43 00:02:04,06 --> 00:02:07,07 of course we need to check the weather at that location. 44 00:02:07,07 --> 00:02:09,09 And here's where weather py comes in. 45 00:02:09,09 --> 00:02:12,05 It uses a free weather API from these folks 46 00:02:12,05 --> 00:02:16,01 at open-meteo.com, and this will get the forecast 47 00:02:16,01 --> 00:02:18,04 for our latitude and our longitude. 48 00:02:18,04 --> 00:02:19,06 It also has a helper function 49 00:02:19,06 --> 00:02:23,03 that will give us a nice little summary of today's weather. 50 00:02:23,03 --> 00:02:24,04 And it has a number of things 51 00:02:24,04 --> 00:02:26,05 like codes and that kind of thing in it. 52 00:02:26,05 --> 00:02:28,07 And by the way, the latitude and longitude, 53 00:02:28,07 --> 00:02:31,01 we're able to get also from location. 54 00:02:31,01 --> 00:02:34,00 I was talking about state earlier on, but we're also getting 55 00:02:34,00 --> 00:02:36,02 the latitude and longitude from that one. 56 00:02:36,02 --> 00:02:39,00 So this little helper function is really useful, 57 00:02:39,00 --> 00:02:41,09 giving us the state for the national Parks API 58 00:02:41,09 --> 00:02:43,07 and giving us the latitude and longitude 59 00:02:43,07 --> 00:02:50,01 for the weather API. Okay, next up will be park stop py. 60 00:02:50,01 --> 00:02:51,07 And this is the fun part. 61 00:02:51,07 --> 00:02:55,06 So parks.py will use the National Park Service API. 62 00:02:55,06 --> 00:02:58,04 You saw how to get the API key for earlier on, 63 00:02:58,04 --> 00:03:02,04 and this will find parks and trails in a given state. 64 00:03:02,04 --> 00:03:03,09 Now there's two functions in here. 65 00:03:03,09 --> 00:03:07,08 One is to get a list of the parks. It's called get parks, 66 00:03:07,08 --> 00:03:09,03 and the other is to get the list 67 00:03:09,03 --> 00:03:12,07 of trails within a specific park. 68 00:03:12,07 --> 00:03:14,06 So we can see we're using both of those here. 69 00:03:14,06 --> 00:03:16,03 And you can imagine how we're calling them 70 00:03:16,03 --> 00:03:18,09 is that first of all, getting parks 71 00:03:18,09 --> 00:03:22,01 with the state code will list a bunch of parks 72 00:03:22,01 --> 00:03:25,04 that are close to us in the same state that we're in. 73 00:03:25,04 --> 00:03:28,01 And then once we've gotten a number of them, 74 00:03:28,01 --> 00:03:31,06 we can then use the iterate through each of them 75 00:03:31,06 --> 00:03:35,04 with their code to get some details of that park. 76 00:03:35,04 --> 00:03:37,08 And then our tool will be smart enough to be able 77 00:03:37,08 --> 00:03:40,05 to use an AI to parse those details 78 00:03:40,05 --> 00:03:42,07 to come up with a recommendation. 79 00:03:42,07 --> 00:03:46,05 So this is the less the tools that are available to us. 80 00:03:46,05 --> 00:03:49,05 So we have location to be able to determine our location. 81 00:03:49,05 --> 00:03:51,07 We have parks that gets details of parks, 82 00:03:51,07 --> 00:03:53,01 and we've weathered that gets the weather 83 00:03:53,01 --> 00:03:54,09 at our latitude and longitude. 84 00:03:54,09 --> 00:03:58,01 We've also seen config.py where we can put our API keys. 85 00:03:58,01 --> 00:03:59,05 And right now we only need one 86 00:03:59,05 --> 00:04:01,06 for the National Park Service. 87 00:04:01,06 --> 00:04:04,01 So then finally I want to look at main.py, 88 00:04:04,01 --> 00:04:05,08 and this is the heart of our agent 89 00:04:05,08 --> 00:04:08,07 and it's where we orchestrate all of these pieces. 90 00:04:08,07 --> 00:04:11,01 And it has been built in the same pattern 91 00:04:11,01 --> 00:04:13,05 that we spoke about earlier on for agents 92 00:04:13,05 --> 00:04:16,04 where we're understanding intent, we're making a plan, 93 00:04:16,04 --> 00:04:18,03 we're using tools to achieve that plan, 94 00:04:18,03 --> 00:04:20,02 and then we're reflecting on that. 95 00:04:20,02 --> 00:04:23,07 So you'll see here this main.py is just 96 00:04:23,07 --> 00:04:26,04 going to do all of that. I would say the best thing for you 97 00:04:26,04 --> 00:04:29,02 to do is really look at this code in detail. 98 00:04:29,02 --> 00:04:31,03 You're going to be editing this code later on 99 00:04:31,03 --> 00:04:33,03 to extend the functionality, 100 00:04:33,03 --> 00:04:36,00 but you'll see the steps here within the main function. 101 00:04:36,00 --> 00:04:38,00 Step one is to look at your location 102 00:04:38,00 --> 00:04:39,06 and analyze the weather. 103 00:04:39,06 --> 00:04:41,06 We're actually going to do a quick reflection there 104 00:04:41,06 --> 00:04:44,02 to see if the weather is good enough for a hike. 105 00:04:44,02 --> 00:04:47,05 If it is, then we're going to gather the park and trail data. 106 00:04:47,05 --> 00:04:53,04 We're going to use models, the open AI model, the GPT 20 BOSS 107 00:04:53,04 --> 00:04:55,01 that we installed earlier to be able 108 00:04:55,01 --> 00:04:57,04 to parse this information for us. 109 00:04:57,04 --> 00:04:59,06 Step three then would be again, 110 00:04:59,06 --> 00:05:01,07 using the model for hiking recommendations, 111 00:05:01,07 --> 00:05:04,02 getting those opinionated recommendations. 112 00:05:04,02 --> 00:05:06,09 And then finally we'll handle some follow up questions. 113 00:05:06,09 --> 00:05:09,04 And this was the code that I executed earlier on 114 00:05:09,04 --> 00:05:11,09 where you saw it was able to find some national parks 115 00:05:11,09 --> 00:05:14,07 that I could hike in. I'm currently in California 116 00:05:14,07 --> 00:05:16,07 to find some that are near to me. 117 00:05:16,07 --> 00:05:20,02 And that's a quick overview of the project structure. 118 00:05:20,02 --> 00:05:22,03 In the next video, I really want to go deeper 119 00:05:22,03 --> 00:05:24,07 into this main.py so you can understand 120 00:05:24,07 --> 00:05:27,00 in detail the agentic loop.