{"id":4092,"date":"2025-03-07T13:45:30","date_gmt":"2025-03-07T21:45:30","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/semantic-kernel\/?p=4092"},"modified":"2025-03-07T13:45:30","modified_gmt":"2025-03-07T21:45:30","slug":"integration-of-aws-bedrock-agents-in-semantic-kernel","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/agent-framework\/integration-of-aws-bedrock-agents-in-semantic-kernel\/","title":{"rendered":"Integration of AWS Bedrock Agents in Semantic Kernel"},"content":{"rendered":"<h3>Overview of AWS Bedrock Agents<\/h3>\n<p>AWS Bedrock Agents provide a managed service that facilitates the experimentation and rapid deployment of AI agents. Users can leverage proprietary AWS models as well as a diverse selection of models from various providers available on AWS Bedrock.<\/p>\n<h3>Semantic Kernel&#8217;s Integration with AWS Bedrock<\/h3>\n<p>Semantic Kernel now integrates with AWS Bedrock Agents, enabling users to leverage kernel functions alongside features such as code interpretation and Retrieval-Augmented Generation (RAG) powered by the AWS knowledge base. If you manage resources on AWS and are exploring a multi-cloud AI solution, this integration provides a valuable opportunity.<\/p>\n<p><div class=\"alert alert-primary\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Info\"><\/i><strong>Experimental<\/strong><\/p>This is an experimental feature. We are actively collecting feedback and working on moving it to release candidate status.<\/div><\/p>\n<h3>Getting Started<\/h3>\n<h5>Prerequisites<\/h5>\n<ol>\n<li><span style=\"font-size: 16px;\">You need to have an AWS account and access to the <a href=\"https:\/\/docs.aws.amazon.com\/bedrock\/latest\/userguide\/model-access-permissions.html\">foundation models<\/a>.<\/span><\/li>\n<li><a href=\"https:\/\/docs.aws.amazon.com\/cli\/latest\/userguide\/getting-started-install.html\">AWS CLI installed<\/a> and <a href=\"https:\/\/boto3.amazonaws.com\/v1\/documentation\/api\/latest\/guide\/quickstart.html#configuration\">configured<\/a>.<\/li>\n<li>A Bedrock Agent Resource Role Arn.<\/li>\n<\/ol>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>AWS Region<\/strong><\/p>You must also configure the AWS region, or you will have to create custom AWS clients for the Bedrock service. See details in our <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/python\/samples\/concepts\/agents\/bedrock_agent#configuration\">GitHub repository<\/a>.<\/div><\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Resource Role Arn<\/strong><\/p>On your AWS console, go to the IAM service and go to <strong>Roles<\/strong>. Find the role you want to use and click on it. You will find the ARN in the summary section.<\/div><\/p>\n<p><div class=\"alert alert-success\"><p class=\"alert-divider\"><i class=\"fabric-icon fabric-icon--Lightbulb\"><\/i><strong>Foundational Model<\/strong><\/p>You need to make sure you have permission to access the foundation model. You can find the model ID in the <a href=\"https:\/\/docs.aws.amazon.com\/bedrock\/latest\/userguide\/models-supported.html\">AWS documentation<\/a>. To see the models you have access to, find the policy attached to your role you should see a list of models you have access to under the <strong>Resource<\/strong> section.<\/div><\/p>\n<h5>Create an agent<\/h5>\n<p>We provide a convenient method to create a new agent if you would like to perform agent creation in code.<\/p>\n<p>In Python, do the following<\/p>\n<pre class=\"prettyprint language-py\"><code class=\"language-py\">from semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent\r\n\r\nagent_name = \"[YOUR AGENT NAME]\"\r\ninstructions = \"[YOUR AGENT INSTRUCTIONS]\"\r\nagent_resource_role_arn = \"[YOUR AGENT RESOURCE ROLE ARN]\"\r\nfoundation_model = \"[YOUR FOUNDATIONLA MODEL]\"\r\n\r\nbedrock_agent = await BedrockAgent.create_and_prepare_agent(\r\n  agent_name,\r\n  instructions,\r\n  agent_resource_role_arn=agent_resource_role_arn,\r\n  foundation_model=foundation_model,\r\n)\r\n<\/code><\/pre>\n<p>In .Net, do the following<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">using Amazon.BedrockAgent;\r\nusing Microsoft.SemanticKernel.Agents.Bedrock;\r\nusing Microsoft.SemanticKernel.Agents.Bedrock.Extensions;\r\n...\r\nvar client = new AmazonBedrockAgentClient();\r\nvar agentModel = await client.CreateAndPrepareAgentAsync(new()\r\n{\r\n  AgentName = \"[YOUR AGENT NAME]\",\r\n  Description = \"[YOUR AGENT DESCRIPTION]\",\r\n  Instruction = \"[YOUR AGENT INSTRUCTION]\",\r\n  AgentResourceRoleArn = \"[YOUR AGENT RESOURCE ROLE ARN]\",\r\n  FoundationModel = \"[YOUR FOUNDATIONLA MODEL]\",\r\n});\r\nvar bedrockAgent = new BedrockAgent(agentModel, client);\r\n<\/code><\/pre>\n<h5>Use an existing agent<\/h5>\n<p>You can also retrieve agents that you created previously and use it in Semantic Kernel.<\/p>\n<p>In Python, do the following<\/p>\n<pre class=\"prettyprint language-py\"><code class=\"language-py\">import boto3\r\nfrom semantic_kernel.agents.bedrock.bedrock_agent import BedrockAgent\r\n\r\nAGENT_ID = \"[YOUR AGENT ID]\"\r\n\r\nclient = boto3.client(\"bedrock-agent\")\r\nagent_model = client.get_agent(agentId=AGENT_ID)[\"agent\"]\r\nbedrock_agent = BedrockAgent(agent_model)<\/code><\/pre>\n<p>In .Net, do the following<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">using Amazon.BedrockAgent;\r\nusing Microsoft.SemanticKernel.Agents.Bedrock;\r\n...\r\nvar client = new AmazonBedrockAgentClient();\r\nvar getAgentResponse = await this.Client.GetAgentAsync(new() { AgentId = \"[YOUR AGENT ID]\" });\r\nvar bedrockAgent = new BedrockAgent(getAgentResponse.Agent, client);<\/code><\/pre>\n<h5>Interacting with the agent<\/h5>\n<p>Interacting with the agent is simple and intuitive.<\/p>\n<p>In Python, simply do the following<\/p>\n<pre class=\"prettyprint language-py\"><code class=\"language-py\">session_id = BedrockAgent.create_session_id()\r\nresponse = await bedrock_agent.get_response(session_id, \"your query\")\r\nprint(response)<\/code><\/pre>\n<p>In .Net, simple do the following<\/p>\n<pre class=\"prettyprint language-cs language-csharp\"><code class=\"language-cs language-csharp\">var responses = bedrockAgent.InvokeAsync(BedrockAgent.CreateSessionId(), UserQuery, null);\r\nawait foreach (var response in responses)\r\n{\r\n    Console.WriteLine(response.Content);\r\n}<\/code><\/pre>\n<p>For more advanced usage patterns and features including streaming, code interpretation, and kernel function, please visit our GitHub repository:<\/p>\n<p>Python: <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/python\/samples\/concepts\/agents\/bedrock_agent\">semantic-kernel\/python\/samples\/concepts\/agents\/bedrock_agent at main \u00b7 microsoft\/semantic-kernel<\/a><\/p>\n<p>.Net: <a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/tree\/main\/dotnet\/samples\/GettingStartedWithAgents\/BedrockAgent\">semantic-kernel\/dotnet\/samples\/GettingStartedWithAgents\/BedrockAgent at main \u00b7 microsoft\/semantic-kernel<\/a><\/p>\n<p>Happy coding!<\/p>\n<p><em>The Semantic Kernel team is dedicated to empowering developers by providing access to the latest advancements in the industry. We encourage you to leverage your creativity and build remarkable solutions with SK! Please reach out if you have any questions or feedback through our\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\/discussions\/categories\/general\" target=\"_blank\" rel=\"noopener\">Semantic Kernel GitHub Discussion Channel<\/a>. We look forward to hearing from you!\u00a0We would also love your support, if you\u2019ve enjoyed using Semantic Kernel, give us a star on\u00a0<a href=\"https:\/\/github.com\/microsoft\/semantic-kernel\" target=\"_blank\" rel=\"noopener\">GitHub<\/a>.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Overview of AWS Bedrock Agents AWS Bedrock Agents provide a managed service that facilitates the experimentation and rapid deployment of AI agents. Users can leverage proprietary AWS models as well as a diverse selection of models from various providers available on AWS Bedrock. Semantic Kernel&#8217;s Integration with AWS Bedrock Semantic Kernel now integrates with AWS [&hellip;]<\/p>\n","protected":false},"author":165150,"featured_media":2364,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[48,121,63,9],"class_list":["post-4092","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-semantic-kernel","tag-ai","tag-aws-bedrock","tag-microsoft-semantic-kernel","tag-semantic-kernel"],"acf":[],"blog_post_summary":"<p>Overview of AWS Bedrock Agents AWS Bedrock Agents provide a managed service that facilitates the experimentation and rapid deployment of AI agents. Users can leverage proprietary AWS models as well as a diverse selection of models from various providers available on AWS Bedrock. Semantic Kernel&#8217;s Integration with AWS Bedrock Semantic Kernel now integrates with AWS [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4092","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/users\/165150"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/comments?post=4092"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/posts\/4092\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media\/2364"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/media?parent=4092"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/categories?post=4092"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/agent-framework\/wp-json\/wp\/v2\/tags?post=4092"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}