Back to Index

Building AI agents with Claude in Amazon Bedrock | Code w/ Claude


Transcript

AVAILABLE NOW: Building AI Agents with Cloud in Amazon Bedrock. Today, I am excited to explore how to create intelligent, autonomous AI systems that can transform your applications. My name is Dewan Lightfoot. I am a developer advocate at AWS. I am Banjo Abiyami. I am a systems architect at AWS.

Hi, everyone. My name is Suman Devanath. I am a developer advocate at AWS. Now, this will be a hands-on keyboard event. So we have a live workshop where you can log into an environment and get started with some code. So, we are going to go through a few slides to kind of level set and get everyone on the same page, and then we will hop into the workshop.

Now, this is Code with Cloud. And one of the things that I want to talk about is Anthropic on AWS. To do that, we have Amazon Bedrock, which is a fully managed service that provides you access to powerful foundational models, like those in the cloud family through a unified API.

This gives you everything you need to not only build, but also scale your AI applications globally. And it does this by providing you with everything you need. Model choice, guardrails, as well as it gives you security at enterprise grade at default. Now, we're talking agents. That's what everyone is here to see.

But we kind of need to level set what that really means. And at AWS, we explain it like this. An agent is an autonomous system that can reason, plan, and take multiple steps to perform an objective like humans. So if you have a task and you give it to an agent, the agent is able to take that task and say, "Here is the high-level objective.

Let me create a plan of the steps that I need to take." Then it can take actions on those steps. And once those steps have been taken, the actions have been taken on those steps, then it can evaluate the results and reason on what needs to happen next until it actually achieves that objective.

This is an agentic system that we'll be discussing today. Now, at AWS, we've also done something awesome that my colleague, Souman, is going to talk about at this time. Thank you so much, Duan. So taking one step further, what we have done, in fact, last week, last Friday, we have announced an open source SDK to build an agentic application called strands agent.

So what this agent does is it's a very simple SDK which needs three things: models, tools, and prompt. It cannot go any simpler than that. It doesn't have any scaffolding that you don't have to guardrail your prompts, your backstory, goals, etc. What we believe in is that in today's world, the LLMs are pretty strong and we want to make use of the full strength of the model in the backend.

So we are giving the better flexibility for the model to reason on behalf of us. And that's why, if you look at this architecture, it's very straightforward. You create a prompt or this is your question. You send it to the agent, which is the strands agent. And when you create an agent object, you will define the model and tools that we provide to you.

You will see in the workshop when Banjo will go through a couple of the demos, you will see that the default model that we use is Claude 3.7, as of today. And the moment you have strands installed and configured, you get a bunch of tools inbuilt. So you don't have to write heavy lifting code to create a few of your basic needs.

And the best part is not only for your testing and deployment in the test environment, you can actually deploy on the cloud. So assume that you have your workforce in EC2 or Lambda or ECS, you can just deploy your code with ease with the integrated support for all these services.

So to get started, just take a snap of this. This contains the launch blog, as well as the documentation, which is nothing but strands agent.com and the GitHub. And this is an open source project, so feel free to give a star and just raise a PR. If you have anything interesting that you built or if you have any specific requirement which is not there, feel free to contribute.

It's just three days old and we got many PR and feedback from the community, and we would love to work with all of you. All right. So the moment you're all waiting for, it's time to build. So we have pre-configured AWS accounts for you. VS code is also configured so there's nothing you need to download.

Everything is done in the browser. So when you go to this URL, it's going to take you to our pop-up screen and you're going to sign in. It's going to ask you for a one-time password. That's the best way to log in. And once you do that, you're going to be able to have access to the AWS account as well as the VS code server we spun up.

So we're going to take a few minutes to get set up. I always say this is the hardest part of the workshop. So Tumon and Duan are going to be walking through. Ask any questions, raise your hand, and I'll also walk through it. But take some minutes to get started and let's start building.

So when you log in, you'll get to a screen like this. So I'll give a couple more minutes to get to the screen and I'll walk through setting up bedrock so we can have access to the models and then to our VS code server. While people are waiting, I have a video to highlight what strands can do so I can just show that in the meantime.

So in this example, we actually have a strands agent that's actually going to create a math video for this. So it's actually pretty cool. So let's see what happens here. So it's running an MCP server. It's going to start that. It's going to actually create an animation video for us.

So it's going to create a maxim scene to draw the cubic function, 2x cubed. Yeah, something hard that you might have to do in latex, scientific. Like this is very annoying. But we'll see how the MCP server is actually going to build it and actually make a video to highlight it.

How many of you have heard of 3, blue, one, brown? So that is what you are going to see now. So we have created an MCP server which can create the video that you see in 3, blue, one, brown. So we have created a quadratic equation and we wanted to plot that within the range of minus 3 to 3.

And this is powered by cloud 3.7 and strands. So we'll push that code in the GitHub repo which we have shared earlier. Let's see what we have here. But this is just a testimony of how you can get started quickly with the out-of-the-box tools and just a few lines of code.

Thank you. So the first thing to do is make sure you log into this AWS account. So you should not be using your own AWS account. We have already provisioned one with all the resources needed. It's open AWS console. And it will open up a new account, new like this.

You should see this workstop participant role. So you should not be using your own AWS account if you haven't. From here we're going to type bedrock, Amazon bedrock. So when we get to the Amazon bedrock console screen, we're going to want to enable the models so we can use them in our lab.

So give it a second. I'm going to scroll down to this model access button. And then I click the modify model access. And we've got some new models, but they have not enabled them yet. So we're just going to use Claude V7, 3.5 Haiku, and 3.5 Sonnet. So enable those.

Hey, you got the four already. We got four already, yes. But I don't think it's enabled in this account yet. So we've got to use the older models. So I'm going to press next. Once we request access, submit. But again, this code, all the code is open source. The workshop is open source, and we can share the link so you can run this on yourself.

So Module 1 is the one we're doing today. So we're going to show you how Strand Agent works and how you can actually build agentic workflows with it. So the first thing you do is install it. So just doing pip install strand agents and strand agent tools gets you what you need.

And have some utility things, UV to download MCP servers. So I'm going to copy that command. Paste. All right. Already installed. Great. So. And then the cool thing with Claude Code, you actually can use it with Amazon Bedrock. So if you have an AWS account, you have Bedrock, you can use Claude Code without using the Entropic key signing in.

Everything is just down to Bedrock. That's by using the export Claude Code environment variable. So let me go ahead and do that. All right. So Claude gets started. Research preview. I'm going to press dark mode. Of course. All right. Cool. So use recommended settings. Yes. Proceed. All right. Claude Code's ready to go.

So all I did was just export that command because it's already used in Bedrock. Everything that's ready to go is already in my environment. And you all can see this, right? This is a good screen. Yeah. Cool. All right. So the first exercise of the workshop was actually going to use a weather count.

Every AI thing has to start weather first. So, you know, well, we added two tools to this one. The one that can actually get the weather and actually count how many words are in the response just to show how easy it is to use different tools using strands. And we're actually going to use Claude Code to explain how this code works as well before I dive into it.

So I'm going to open this up. paste. Can you explain the structure of the strand agent weather word count file? All right. So it's going to be able to see what happens. Use the tokens. Let me open the file while it does that. And we'll see what Claude says.

Let me make this bigger. All right. So demonstrate a simple agent, implementation the strand framework, an agent file, import necessary, word count tools, using Claude 3.5, actually the query. So let's walk through the code in more detail. So we actually have a system prompt. And we're saying, you know, find the weather.

And it actually puts the API in the system prompt, hdpweather.gov. So there's no API key needed for this. So I can just query this and get the actual weather of what the place is and provide it in a human readable way. And the cool thing about this, strands has this HTTP request tool already built into the framework.

So it's going to be able to just make that request for you automatically. You just provide URL. It's able to call that and get the actual data from that. And then you can use the cool thing about strands also is you can change the different models you can use.

You can use LLM. You can use Ollama. You can use Bedrock. Bedrock to default. So I just changed the Claude 3.5 just to be faster here. And then the cool thing about strands is that's the system prompt, the big system prompt we put up there, which tools we're going to use, the word count tool.

Now what I really like about the tool decorator is I just define a function and just put the return value. There's no crazy thing, no adding. I just put this tool decorator and it handles the rest. So as a developer building functions, I want to put all this extra stuff in there, make it as simple as possible to have a tool.

So that's a really big plus to the strands framework. And then from there I can just say, what's the weather like in Seattle? Let's change it. San Francisco. All right, so we can see how it's going here. First I've got the coordinates for San Francisco. You can see the HTTP request tool.

Now it's going to use the HTTP request tool to find that weather. It gets the San San Francisco, 65, sunny, west, winds, few days, highlight. Now it uses the word count tool, 110 words. So we've got about 44 lines of code. We're able to make that API request. We have the agent.

It's going to have multiple tools done. So I'll pause here for a second just to have any other questions with strands because everybody's going through it. So strands is an open source SDK for building agents. So there are a lot of agentic frameworks, but strand is its own one.

And you can see that you really just need a system prompt, the tools, and a model, and it can execute that loop. So yeah, it is similar to other agentic frameworks, but I believe it's much easier to get started without the boilerplate and extra stuff that you've seen in other frameworks.

All right. One more question and we'll move on to the next part. Thank you. So I have a code-related question. So how are you passing the latitude, longitude, and zip code inside the string? Right. So the cool thing is that we're letting the model decide how to do that.

It uses this HTTP request thing and it understands what the latitude and longitude is of San Francisco and is able to pass that to this API endpoint or use API zip code. So it understands what the API is based on the system prompt and the model is figuring it out by itself.

So we're handing a lot of the infrastructure you might see in other agent frameworks to say you've got to do this, you've got to do this. We're letting the model decide to do that because the model is the much more capable than they were two years ago when you saw the first type of agentic framework coming out.

So the strands tools, like I see that you're importing two tools, which is like word count and HTTP request. So how many tools are there like? Yeah, yeah. So there's some built-in tools in the strand framework like HTTP request. But then I also just made my own tool, which is literally this one line of code, return this length.

So it's very easy to make your own custom tool. You just put this tool decorator and that's it. So very streamlined. All right. So we're going to move on to the next exercise. So the next exercise is fun one, MCP servers. So you know, MCP is the hottest thing, you know.

So what's really cool about Stranded has built-in MCC support and AWS, we actually have official AWS MCP servers. So I'm going to highlight the documentation lookup because AWS docs will be very long, a lot of different things. So if I just have one endpoint that just grab that information and pass it to the model, it's going to be able to understand how to build.

And then an architecture diagram. So making AWS diagrams. So there are two MCP, there's a whole bunch of them listed here, but I'm going to highlight these to an example. So let's go back. And we can also ask Claude Claude code to explain it as well. So I have to explain how the MCP diag one works.

So let me open that up while it's waiting. Claude code is documenting. It's looking at what to do. So while Claude code is going, I'll explain what's happening. That's just finished. Cool. All right. Import the strand. Still going. All right. So the cool thing about MCP server is we can actually just pull it in with one line.

We just the command UVX. This is the Python material for downloading things. So we're going to point it to the MCP server and it will download it locally. So I'm passing in the documentation MCP server and I'm passing in the diagram MCP server. And then, you know, Claude's even saying the same thing.

Connect to the MCP diagram one. Configure using bedrock. Again, I can choose different models on bedrock to pass in. And then I'm giving a system prompt. You're an expert certified solutions architect. Your role is to help customers understand best practices, query documentation, generate diagrams, tell the customer the full path of the diagram when you create it.

Just so we know where it is. And then again, we just say, pass in multiple MCP servers with the diagram client, the docs client. We get all the tools based in those MCP servers. And then again, you know, we have the tools, we have the model and the system prompt.

All you need to have the stands agent. And then we give it like, get the documentation for AWS Lambda, then create a diagram of a website that uses Lambda for a static website hosted on S3. So that's the task I give it. Let's see how it executes All right.

So download the MCP servers. I already downloaded them already. And I was processing now. It breaks it down into steps. So first I'll search the AWS documentation. Then I'll read the document. Then I'll create a diagram illustrating architecture. So you can actually see its thought process. It makes an HTTP call to get the search.

It finds the Lambda welcome page to get the information. It queried the documentation. Now it's going to draw the diagram. Let's see. It listed the icons. So what icons are available for it. Now it's actually generating the diagram. So excellent. It failed there, but it understood that. And it explained, let me correct the cloud icon.

Now generated it. Explained what's happening. And it made this new diagram saved here. So I should be able to open it up. Generated diagrams. And ta-da! It made a new diagram for me. So. Whoops. Yeah. It's going to be different every time when you, of course, based on how much context you give it.

But yeah. I'm able to make that diagram. And just about, you know, 40 lines of code. I have two MCP servers. I put my system prompt. Picking a different model. And I'm able to create that agentic workflow very quickly and very easily without any too much headache. So I'm going to pause here on any talks about MCP servers connecting me with strange agents.

Is there a pattern through API Gateway to host a MCP server with Lambda? Like the server side events. Is there something that allows? Yeah. Yeah. Now because MCP supports the HTTP streaming server side event, you can have it in a Lambda function and do that. There are some, I believe there are some open source code that demonstrates how to do that.

One of my colleagues have done that. So yeah, it's totally possible to do that use case. Because right now I'm just running the MCP server locally. But if you wanted to have it in the cloud, like a Lambda function, totally possible use case. You'd have to change how this is set up.

All right. So the last exercise was we're actually going to create a new agent using cloud code to understand how it does without just looking at the code we have already and being able to understand which CDK. I'm going to make a CDK agent. So CDK is a cloud development kit.

So it's a way to create AWS infrastructure through code. Normally, if you want to create AWS infrastructure, you might use something like CloudFormation, which is a YAML-based way. But if it's a developer, CDK is more preferred for that because you can integrate it to Python TypeScript code. So I'm going to show an example of how we can use cloud code to actually create a new strand agent for us.

So I'm going to make this new file here. Oops. All right. So I created a brand new file. Nothing in it. And then I'm going to ask cloud code, you know, update the CDK agent to create a strand agent connecting to an MCP server. Look at the other files to understand how to do this.

So I'm not giving you the documentation. I'm just going to say, you know, use the knowledge you have already to understand how to make it. So let me, let me get into the repo and then clod and ask it. So yeah, so now cloud code, they're going to look through, see the plan of attack it does.

So let's, let's see what it's doing. All right. I'll update the CDK agent to strand agent connected to MCP server. You know, it looks at the other one. There's no one line of code there. I read the other word count one. All right. It finds the MCP doc one.

It examines it. Cross it off the list. All right. On to the next one. Create a stand agent. It put all the code for that. It asks me, do I want to make this edit? So say yes, make the edit. It's adding the code to me. All right. Configure straight agent, quick MCP client, configure system prompt.

It's done it. Perfect. So I'm going to close out of it. And what I like about cloud code actually tells us how much it costs when you end it. So the total cost, how long the API took, you know, how many code changes, how, which models it use. It used cloud 3.5 site haiku, use click full site sign it to understand what the best way is.

So using cloud code of bedrock, that's an easy way to get started in building applications like this. And it's now natively inside VS code, which is very exciting. So let's see if the code actually works. So I'm just going to run it. Let's see your expert AWS CDK expert.

How can I get a simple S3 bucket with CDK? Give us something simple. Let's see how it works. All right. So I was making a TypeScript example. I'll provide step-by-step guidance. It wrote the code for me. It's doing that security, Texas, add a CNN nag rule. So it really understands what CDK is.

It's putting all this extra stuff there. And yeah, it even explained that. So cloud code is able to understand how strand agent works, create a new agent based on that, create a template on that. And it was very easy to understand. So by providing enough context, cloud code is able to understand what to do, create this agent.

And it's pretty good job. So I'm very impressed with using cloud code and bedrock powering. That's also amazing. But that was kind of the workshop through and through to kind of show you what strands can do from a simple weather agent to connecting to MCP servers and then also making your own agents.

I'm going to pause here for any questions or if you want to see a demonstration of something cool, happy to try it out and see what cloud can do. Sorry, I just have to ask like, what are some of the use cases for like using MCP? Like, I know I will be building agents that probably connect to the outer world like through APIs and all.

Like, maybe I don't know a lot about MCP, but like what are some of the use cases you can like use MCPs for? Right. So a great question. What are the use cases for MCP? So by default, the agent doesn't have enough information to connect to external API. So you saw in the example, we created an AWS diagram.

If I did that without an MCP server, the model would not know how to make the AWS diagram and won't know how to look up the AWS documentation. So providing extra context to the model to do extra action. So when it comes to using large-angle model, context is really that empowers what's going to go on.

MCP provides a structured way to grab that information so it can take action, read documentation, connect to external applications. So MCP is really kind of the USB-C, they call it, of connecting the LLM. So for me, it's a great way to just connect the external applications, get different context for your model.

And I'll show you some highlights of the AWS MCP servers just so you can get an example of what we have. So there are official lists of AWS MCP servers that do a bunch of different things. So I'll go through some examples. Show the documentation one. Bedrock knowledge base, if you have a bunch of PDFs or documents you want to give to an LLM.

Cost analysis, so you want to do AWS cost analysis, if you want to get another example, the MCP server could be useful for you. Amazon Nova Canvas, if you want to draw images, Nova Canvas MVC server. The diagram one that we use today, you can also draw AWS architecture diagrams, cloud formation.

So there's a bunch of different ones. And Terraform, if you use Terraform, front-end code, you want to specialize in React or using AWS Amplify, etc. So there's a whole source of MCP servers. So one big use case is I want my model to understand these things. You have a bunch of documentation, Postgres database, Amazon Neptune server, like so.

This is really the power of MCP. So there's so many integrations you can have to give that model extra abilities to do. We do have AWS credits for you. So if you want to give us some feedback and surveys, I want you to fill this out. You'll get $25 of AWS credits to use, so you can play around, try some things out.

But thank you for coming and let's go build. Thank you very much. Thank you very much. Thank you very much. Thank you very much. Thank you very much. Thank you. Thank you.