[0:00] Everybody's talking about AI agents. [0:03] These are programs that can reason, make [0:06] decisions, and take actions all by [0:08] themselves given an input from us. And [0:12] most of us are talking about agents in [0:14] respect to Kiro or Kiro CLI or Claude [0:17] code, those agents that can help us to [0:19] write applications and write code. But [0:22] in this video, you're going to get [0:24] hands-on and make your very own agent. [0:27] But before we do that, what components [0:30] make up an agent? [0:36] We start off with the brain or the [0:38] model, the large language model that [0:40] gives us the natural language [0:42] intelligence to be able to process the [0:45] inputs that the agent gets. But how does [0:47] the agent do anything? Well, this is [0:49] with the hands or the tools. These tools [0:52] give our agent agency to be able to [0:55] affect change in the outside world. Then [0:58] we have the system prompt. The system [1:01] prompt is essentially the personality of [1:03] our agent. This describes what we want [1:06] the agent to do and how we want it to go [1:08] about it. Now, all of those components [1:10] are brought together in the agentic [1:13] loop. This is an iterative loop that the [1:16] agent is in control of. When we put an [1:18] input into the top of the agent, it then [1:21] processes through the loop, running [1:23] tools, thinking, running another tool [1:25] until it decides it has the output, and [1:28] then it provides the answer back to us. [1:30] Now, to build our first agent, we're [1:33] going to use a framework, and that [1:35] framework is Strands Agent SDK. This is [1:39] a completely free and open-source [1:40] agentic framework. It works with any [1:43] model provider. It works with any [1:45] hosting provider. And for us today, [1:48] we're going to get an agent running on [1:49] our laptop using a model from the cloud. [1:53] Let's jump into some code. And here is [1:55] my coding environment. This is Kiro, and [1:58] Kiro gives me all of the AI goodness I [2:00] need to assist me in writing code. But [2:03] in this case, we're going to write it [2:05] ourselves from first principles. So, let [2:08] me go and grab myself up a terminal, and [2:11] I'm going to kick off a Python project. [2:14] So, Strands Agent SDK is available in [2:16] both Python and in TypeScript. Python's [2:19] more my thing, so that's what I'm going [2:21] to do. And so, I'm going to start off [2:22] this project by saying UV init because [2:26] I'm using UV as a package manager for my [2:28] project. If you haven't used that [2:30] before, I'll put a link in the [2:31] description below of how you can install [2:33] UV inside of your environment. So, with [2:36] UV init, you can see on the side here my [2:38] Python project has started. I now need [2:40] to include the Strands Agent SDK. So, [2:43] I'm just going to say UV add, and then [2:45] I'm going to say Strands {hyphen} [2:47] Agents. Hit enter, and all of those [2:50] packages are now being downloaded. And [2:52] that's all I need to be able to then go [2:54] ahead and build my first agent. So, if I [2:57] look on the side here, I've got main.py. [3:00] This is just the boilerplate main [3:02] function from the uh initialization of [3:05] the UV project. So, I can go ahead and [3:07] select all of that and remove it. Now, [3:09] let's start writing our Strands Agent. [3:11] So, all I need to do is import the [3:13] Strands Agent SDK. So, I'm going to say [3:15] from Strands [3:18] import, and then I'm going to import um [3:21] agent. [3:23] Pretty much all I need to do. Now, I'm [3:25] going to go and get myself an agent [3:27] object. So, I'm going to say agent [3:29] equals [3:31] and then I'm going to say [3:32] agent [3:34] and that's all I need to do there. [3:37] And now I can prompt my agent. So, I can [3:40] just say agent uh tell me a joke. [3:45] And this is one of the very standard [3:47] things that we ask an LLM to do because [3:49] of course the LLM is the intelligence [3:51] behind our agent. So, essentially all [3:53] we're doing here is invoking the LLM [3:56] once. We don't have any tools or [3:57] anything like that at this stage. We [3:59] will though in just a moment. So, let me [4:01] save that, and let me just clear my [4:04] screen here, and let's go and run that. [4:06] So, UV run main, and it's almost [4:09] certainly going to ask me to or tell me [4:10] the joke about the scientist. You [4:12] probably heard it before um because [4:14] that's what LLMs do. So, let's have a [4:16] look after we've run that. Yes, of [4:18] course. Why don't scientists trust [4:20] atoms? [4:21] Because they make up everything. [4:25] Okay. So, a really, really simple agent [4:27] working there, but all it's done is [4:29] we've taken the input, it's gone into [4:31] its agentic loop, it's thrown this query [4:33] essentially over to the large language [4:35] model, and then it's spat the answer [4:37] back out. It's no different to just [4:39] prompting a large language model. In [4:41] order to make this properly into an [4:43] agent, well, we've got to start adding [4:45] these other components. So, let's go [4:47] ahead and give this a tool. So, I can [4:49] extend out the things that I'm importing [4:51] from Strands Agents to also import tool, [4:54] and tool for us here is actually a tool [4:57] decorator that we can now decorate a [4:59] Python function. It becomes a tool that [5:02] we can then pass to our agent. So, let's [5:04] just say um def, I'm going to define my [5:07] own thing. I'm going to say weather. Uh [5:09] Kiro's trying to be helpful for me under [5:11] the hood there, which is pretty cool. Um [5:13] and then I'm going to say city, um which [5:15] is a string, and the whole thing's going [5:17] to respond with a string. [5:20] Um and then I can put in a docstring [5:21] here. Now, this docstring is more than [5:23] just helpful to me to remember what this [5:25] function's for. This docstring is [5:27] actually something that will get passed [5:28] to the agent and therefore the large [5:30] language model so it knows what this [5:32] tool is for. So, let's just say this is [5:35] um get the weather for a given city. [5:41] Um and we're not actually going to [5:42] implement this code right now, but we [5:44] are going to just return [5:46] um [5:48] it's nice and hot. So, whatever city it [5:53] asks for, it's always going to say it's [5:55] nice and hot. This is just a piece of [5:56] sample code. Now, we can pass that to [5:59] our agent like this. So, we can say [6:01] inside of the agent constructor, we can [6:04] say tools, and we can give it a list of [6:06] the tools that it's got available to it. [6:08] In this case, we're going to pass it [6:10] weather because that's the only tool [6:11] we've got. And I can hit save. So, let's [6:13] just review that code just for one [6:15] moment. So, we're importing Strands [6:17] Agent SDK, and we're also importing the [6:20] tool decorator. We're defining a [6:22] function here as weather that returns a [6:24] string, so something that's natural [6:26] language that the agent will be able to [6:28] make sense out of. And we're decorating [6:30] that with tool. That means now that this [6:32] is ready to be loaded as a tool into our [6:34] agent. We pass that into the agent here [6:37] with tools equals and the list of tools [6:39] we have. And now, well, let's ask it [6:41] something different. What is the [6:44] weather like in London? [6:48] Okay, and now let's clear this out so we [6:51] can run this again [6:52] and run this agent again. This time, [6:54] we're actually using the agentic loop [6:57] because what happens is it goes in and [6:58] decides, "Okay, I'm going to check the [7:01] weather in London." It then calls a [7:03] tool, it calls the weather tool, which [7:05] is the only tool we have, and then it's [7:07] come back with, "The weather in London [7:08] is currently nice and hot." Which of [7:10] course it's not, or it might be, I don't [7:12] know. We just made up the answer here, [7:14] but now you see an agent using a tool. [7:17] So, there's only one more piece left, [7:20] and that is the system prompt. And we [7:22] can do that here um by adding in again [7:25] to this. We can say system prompt [7:28] because at the moment it's basically [7:30] been super generic. Um and we can say [7:33] you are a [7:36] helpful assistant [7:39] who always responds in the voice of a [7:44] pirate, which is always super useful. [7:47] So, let's do that and add a comma at the [7:49] end of that, and it should all be happy. [7:51] And then let's go ahead and clear this, [7:54] and then we're going to run this again. [7:56] So, we've set the personality of our [7:59] agent, and now of course it's even [8:01] thinking in pirate speak. Ah, yes. The [8:04] seas be calm, and the weather be fine in [8:06] London. I'm not going to say any more of [8:09] that. Okay, so now we've got the basics [8:11] of an agent up and running. Let's start [8:13] to build up a small project. I like [8:16] tabletop RPG games, so let's build [8:19] ourselves a games master that's going to [8:21] be the beginning of a project you could [8:23] take a long way. [8:25] Now, you might have noticed that in the [8:27] first demonstration that we ran, it [8:29] worked, but we didn't actually specify [8:31] the brain. We didn't specify the model [8:33] that we were going to use. And that's [8:35] because Strands Agents will actually [8:37] pick up a model by default for us if we [8:39] don't. But it's going to be super useful [8:41] for us to be able to define the model [8:43] that we actually want to use, and so [8:44] that's what I'm doing in this code here. [8:46] So, I'm now saying from Strands Models [8:49] import Bedrock Model, and then that [8:51] gives us the opportunity to actually [8:53] specify the Bedrock model that we want [8:55] to use. Now, again, Strands Agent SDK [8:58] doesn't have to use Bedrock models from [9:00] AWS. It can use models from any [9:02] provider. Indeed, in a blog post that [9:04] I've got linked in the description [9:06] beneath this video, I go through pretty [9:08] much everything that I'm going through [9:09] in this video, plus I'll show you how to [9:12] connect it and with Ollama, a locally [9:14] running model. But we're using Amazon [9:17] Bedrock models here. So, let me just go [9:20] over to the Amazon Bedrock console page [9:22] in the AWS console because if we go to [9:25] model catalog over here on the left-hand [9:27] side, I can see a a list of all of the [9:30] models which are available for us in the [9:32] particular region that we're working in [9:34] from all of the different model [9:35] providers. And you'll see that there's [9:37] all of these models from Anthropic here. [9:39] We can go and see them from places like [9:41] Meta and Cohere and Deep Seek, um and [9:44] also models from Amazon ourselves as [9:46] well. And so, if I go into here, I can [9:48] find the Nova 2 light model. This is a [9:51] small, cost-effective model for getting [9:53] started. It's a great place to start. [9:56] And in the code that we have here, I've [9:58] got a model that's actually specified [10:00] here as Amazon Nova 2 light. So if I go [10:03] back to the model catalog for a moment, [10:05] you can see that Nova 2 light there is a [10:08] model ID right there. Now if I come back [10:10] to the code, you'll notice I've got us. [10:13] dot and that's because this is a [10:15] regional endpoint for this model. So [10:17] it's going to do the best it can [10:19] throughout the whole of the US because [10:20] I'm using US East 1 for this particular [10:24] example. [10:25] Um so then I've got the rest of my model [10:27] defined as we did before, but this time [10:29] I'm creating a tabletop RPG games [10:31] master. So I've said you're you're a [10:33] dramatic and entertaining tabletop RPG [10:36] games master. Keep the story short and [10:38] to the point. Um one or two paragraphs [10:41] at most. We can adjust this. You can [10:43] adjust this to create a games master [10:45] which follows your particular style. And [10:48] so then I can pass in my first prompt [10:51] essentially, I kick open the tavern door [10:53] and stride up to the bar. Barkeeper, [10:56] your finest ale. Okay, let's run this [10:58] and see what happens. [11:00] Um so again, I've just pasted this into [11:03] main inside of my project code here. And [11:06] yeah, look, it does exactly what we [11:07] thought and it starts off a story. And [11:10] as you kick open the creaky tavern door, [11:12] the raucous din of laughter and clinking [11:14] mugs momentarily hushes. And you can [11:17] read the rest of that to see what's [11:18] going to go on. I'm not going to turn [11:20] this into a let's play session. [11:23] Let's build and let's continue to build [11:25] this agent cuz you notice that we don't [11:26] actually have any tools here. So let's [11:30] go and add the tool back in. So I'm [11:32] going to go and add in the tools import [11:35] one more time. Um and then we're going [11:38] to find ourselves [11:40] a tool to add. [11:41] And so let me paste that in. And here we [11:44] go. This is actually one of my favorite [11:45] tools. I love playing around with this. [11:48] So this is a dice rolling tool or roll [11:50] dice tool. And it takes as an input the [11:53] number of sides on the dice. So pretty [11:55] much anything from a D4 all the way up [11:57] to a D20 [11:58] and the number of dice you want to roll [12:00] and then it gives some general [12:02] instructions here. [12:03] And it gives instructions to the large [12:05] language model or in other words, the [12:06] agent as to what these arguments mean. [12:09] So the number of sides on each die and [12:11] then how many dice to roll. And then [12:13] look, all it's doing is just calculating [12:16] some random numbers. But it's kind of [12:17] fun. The one thing I'm going to need to [12:19] do is import [12:21] random. [12:24] So let's just do that up top so that [12:26] we've got everything ready for the code. [12:28] And then the next thing I need to do is [12:30] I need to add this in as a tool. So I'm [12:32] going to say tools equals and then I'm [12:34] going to add in my dice [12:37] roll dice tool like that and save there. [12:41] Okay, so at this point I can run this [12:44] again and likely nothing's going to [12:46] happen because I haven't necessarily [12:49] done something that requires the dice. [12:52] But let's just have a quick look. [12:54] It might decide that it's going to do [12:56] it. This is part of the [12:57] non-deterministic nature of agents of [12:59] course. Yeah, look, it's decided to roll [13:01] the dice because it's got one. [13:02] And so what does it say this time? [13:04] I don't know what I rolled. We can find [13:06] that out in a second. The barkeep [13:08] grumbles, eyes narrowing as he slams the [13:11] tankard down in front of you with a [13:12] clank. Doesn't sound very happy. I [13:14] wonder whether I rolled something low. [13:17] Actually, it's difficult to tell because [13:18] I can't get back into this agentic [13:21] conversation. It's finished at this [13:22] point. Okay, let's fix that. So I'm [13:26] going to clear that up and I'm going to [13:28] expand down here. And what I've got here [13:31] is just a quick chat loop that I can [13:33] paste in. [13:34] So if I just grab my [13:36] code from here. So instead of having [13:38] this, I can insert above here this. I'm [13:42] going to borrow this [13:45] because maybe we can use this in the [13:47] next call anyway. So let's copy that and [13:50] delete that. Okay. So now what I've done [13:52] is I've added in this quick while true [13:54] loop here. And what it's basically going [13:56] to do is it's going to allow me to enter [13:58] some text. When I've entered the text, [14:00] it will then send that to the agent and [14:03] then keep going around unless I type in [14:05] quit or exit. So let's press save on [14:07] that and now let's run this code again. [14:11] Now I've got a prompt. And so I could [14:13] actually just have a general [14:14] conversation with the agent. So I could [14:16] just say hello [14:17] and see what it returns back with. [14:19] Greetings, intrepid adventurers, etc. [14:21] etc. Now let's just say that what I want [14:23] to do is I want to kick open the tavern [14:25] door, stride up to the bar and say [14:26] barkeeper, your finest ale. So let's [14:28] just press enter on that and see. Now [14:31] let me just expand that up. [14:33] This time it decided not to roll the [14:36] dice, but it's given us a bunch of [14:38] things that we could do. Um so pay for [14:40] the ale. I haven't read the entire [14:42] story. I just don't really feel like I [14:44] have time to do that. What if I say roll [14:46] a D20? Just throwing the games master a [14:50] curveball here I suppose. [14:52] Oh, it's decided it's going to do a [14:53] charisma check. So it's rolled the dice, [14:55] done a charisma check and got 17. I'm [14:58] doing well with my charisma today. So [15:00] you can see here how we are getting [15:03] started. And if I had the time and if I [15:05] wanted to, I could actually clear this [15:07] out, start again and actually start a [15:10] agentic run campaign all by myself with [15:13] my agent. Now you can actually do this [15:16] and you could actually start to play [15:17] this for quite some time. At some point, [15:20] the context window's going to fill up [15:22] and the whole thing's going to come [15:23] crashing down. And we can take a look at [15:25] that in a subsequent follow-up video. [15:26] But for now, it's going to keep that [15:28] conversation history, in other words, [15:30] the game history going and you can [15:32] follow on with responses about things [15:34] that have happened about the game that [15:36] you're playing. Now before we wrap this [15:38] up, let's go quite a few steps forward. [15:41] I've got a more established games master [15:43] code that I can paste into here and then [15:45] we can step through what we've got. [15:47] Okay, here it is. And in this case, I'm [15:50] hopefully going to make it a little bit [15:51] nicer to look at and a little bit better [15:53] to play. Let's step through the code [15:55] that I've got here and of course, all of [15:58] the code which I've had for the entire [16:00] video up until this point is going to be [16:02] linked in the description below. So [16:04] first of all, I define some colors [16:06] because I want to make something look a [16:07] little bit nicer in the command line [16:09] when we're playing this. Going to try [16:10] and separate out some of the tool calls [16:12] from what I'm typing and things like [16:15] that. We've got a tool call hook here. [16:18] We'll get back to what this is in just a [16:20] second, but we've got more tools to look [16:22] at. So we've got a tool which is the [16:24] look up rule tool. And this is going to [16:27] look up rules from the rule book. And I [16:29] have actually copied in a rule book [16:31] here. It's just a simple piece of text. [16:33] So this is a simple set of text [16:35] instructions that we can ask the agent [16:37] to dip into so it can come and have a [16:39] look at what are the combat rules? What [16:41] are the skills checks rules? Now look, [16:43] this is super simple and honestly, I [16:45] could put all of the things that are in [16:47] this rule book actually in the context [16:50] or in the system prompt for the agent. [16:53] But I'm just demonstrating here how we [16:54] can use a tool to go and query and get [16:57] data from another source. In this case, [16:59] it's a text file. But this is the basics [17:02] of retrieval augmented generation. We [17:04] can get much more complex with this and [17:06] we could search an entire enterprise or [17:08] corporate document repository. But for [17:10] now, we're just searching this [17:12] text-based rule book. That's the tool [17:15] there that we've got. We've got roll [17:16] dice here again, but we've also got some [17:18] other things. We've got player state. So [17:20] this is able to keep hold of what our [17:23] current player state is. Like what are [17:25] our current hit points? What's our [17:26] current strength? The agent can actually [17:29] update this as we go along because it's [17:30] got a couple of tools. It's got get [17:32] player state which will just return that [17:34] player state and update player state. So [17:37] the agent can keep track of our health [17:40] as we play this game. And we could be [17:41] able to query that as well. And here's [17:43] our agent. We're still using Nova 2. Um [17:46] here's our system prompt. It's a little [17:48] bit more comprehensive now. Just talks a [17:51] little bit more about what's going on. [17:52] It explains that there's a rule book [17:54] there and the different sections of the [17:55] rule book that it can get. Um and then [17:57] we've got all of those [17:59] tools all in that tool list there. [18:02] Including then, we've also got hooks. So [18:05] hooks is a powerful thing inside of [18:07] Strands Agents SDK. So at various points [18:10] in the life cycle of that agentic loop [18:13] that we looked at, different hooks will [18:15] fire and you can go and hook into that [18:18] with your code to go and do a certain [18:20] thing. And so we have tool indicator as [18:23] a hook that we're going to register [18:25] here. So if I just scroll back up to the [18:27] top where that hook was defined, um we [18:31] can see here that it actually extends [18:32] hook provider which is something that we [18:35] have called in from the Strands Agents [18:37] SDK. We're actually calling in all the [18:40] necessary things that we need to [18:41] register this hook. And so this hook [18:44] here is going to get called before and [18:47] it's basically just going to print out [18:49] the name of the tool which is being used [18:51] just to break up something in the user [18:53] interface. This is very simple example [18:56] of how to use hooks. They're super [18:57] powerful. If you want to dig into the [19:00] documentation, of course, a link is in [19:02] the description below. [19:03] So let's scroll down again back to our [19:06] main agent. And then we have a game loop [19:08] here. Just a little bit more flare if [19:11] you like inside of the chat agent [19:13] itself. Otherwise, everything is the [19:15] same. So let's jump in here. Let's [19:18] expand this out just a bit more so I've [19:20] got some more room to play. And let's [19:22] play for the last time our quest. So [19:25] I've got [19:26] an interesting start out here. It says [19:28] the sun dips low casting long shadows [19:31] across the cobbled road as you approach [19:33] approach the humble village of Everbrook [19:37] Hollow. [19:38] And on it goes with the weaving of the [19:40] story. Let's have a look. [19:42] You push open the creaky door of the [19:45] rusty tankard, the warm amber light [19:48] spilling out into the cooling evening [19:50] air. And then it's got all these other [19:52] stuff learned down there. Let's have a [19:54] look. And it says, "What would you like [19:56] to do? Speak with Innkeeper, approach [19:58] the lone figure." Do you know what? I [20:00] think it's always a good idea for roll [20:02] to roll for investigation. So, let's [20:04] roll for investigation. [20:07] Also, I want to have a go with the tool. [20:09] So, it's looking up some rules. It's [20:12] decided. And then it's rolling the dice. [20:15] Um and then well, it doesn't actually [20:16] say what number we got back for Oh, no, [20:18] it does. It We rolled a three. Oh, [20:20] that's not good. So, we probably didn't [20:22] manage to discover very much. But you [20:24] can see how this works. It's looking up [20:26] rules. It's uh rolling the dice. And [20:29] it's also remembering um the status of [20:32] us as a player. This is a much more [20:34] sophisticated agent. But it's just [20:37] scratching the surface of what we could [20:39] do. You can see how we can build in [20:41] pretty much any tool, anything you can [20:43] do programmatically, you could build in [20:45] a tool for your agent. And then beyond, [20:48] if you want to add memory, if you want [20:51] to add connections to other types of [20:53] document stores, if you want to add [20:55] connections to MCP servers, or if you [20:57] want to publish this out to the internet [21:00] and have a cloud-hosted [21:02] agent, you can do all of those things [21:04] with Amazon Bedrock Agent Core. That's [21:06] the next step beyond building an agent [21:09] with Strand's Agent SDK. And for Amazon [21:11] Bedrock Agent Core, there'll be a link [21:13] in the description below. Thank you so [21:15] much for taking the time to go through [21:18] on this quest and this journey with me [21:20] for building agents. I hope you have a [21:23] lot of fun building agents, maybe as [21:25] much [music] fun as I'm having telling [21:27] you about them. Thank you so much for [21:28] watching, and I will see you in another [21:30] video really soon.