Enable Foundation Models to Complete Tasks With Agents for Amazon Bedrock
Media/Author
AWS Blog
Date
Jul 26, 2023
This April, Swami Sivasubramanian, Vice President of Data and Machine Learning at AWS, announced Amazon Bedrock and Amazon Titan models as part of new tools for building with generative AI on AWS. Amazon Bedrock, currently available in preview, is a fully managed service that makes foundation models (FMs) from Amazon and leading AI startups—such as AI21 Labs, Anthropic, Cohere, and Stability AI—available through an API.
今年 4 月,AWS 数据和机器学习副总裁 Swami Sivasubramanian 宣布推出 Amazon Bedrock 和 Amazon Titan 模型,作为在 AWS 上构建生成式 AI 的新工具的一部分。 Amazon Bedrock 目前提供预览版,是一项完全托管的服务,可通过 API 提供来自 Amazon 和领先的 AI 初创公司(例如 AI21 Labs、Anthropic、Cohere 和 Stability AI)的基础模型 (FM)。
Today, I’m excited to announce the preview of agents for Amazon Bedrock, a new capability for developers to create fully managed agents in a few clicks. Agents for Amazon Bedrock accelerate the delivery of generative AI applications that can manage and perform tasks by making API calls to your company systems. Agents extend FMs to understand user requests, break down complex tasks into multiple steps, carry on a conversation to collect additional information, and take actions to fulfill the request.
今天,我很高兴地宣布推出 Amazon Bedrock 代理预览版,这是开发人员只需单击几下即可创建完全托管代理的新功能。 Amazon Bedrock 代理可加速生成式 AI 应用程序的交付,这些应用程序可以通过对公司系统进行 API 调用来管理和执行任务。代理扩展 FM 来理解用户请求,将复杂的任务分解为多个步骤,进行对话以收集附加信息,并采取行动来满足请求。

Using agents for Amazon Bedrock, you can automate tasks for your internal or external customers, such as managing retail orders or processing insurance claims. For example, an agent-powered generative AI e-commerce application can not only respond to the question, “Do you have this jacket in blue?” with a simple answer but can also help you with the task of updating your order or managing an exchange.
使用 Amazon Bedrock 代理,您可以为内部或外部客户自动执行任务,例如管理零售订单或处理保险索赔。例如,由代理驱动的生成式人工智能电子商务应用程序不仅可以回答“你有这件蓝色夹克吗?”的问题。答案很简单,但也可以帮助您完成更新订单或管理交换的任务。
For this to work, you first need to give the agent access to external data sources and connect it to existing APIs of other applications. This allows the FM that powers the agent to interact with the broader world and extend its utility beyond just language processing tasks. Second, the FM needs to figure out what actions to take, what information to use, and in which sequence to perform these actions. This is possible thanks to an exciting emerging behavior of FMs—their ability to reason. You can show FMs how to handle such interactions and how to reason through tasks by building prompts that include definitions and instructions. The process of designing prompts to guide the model towards desired outputs is known as prompt engineering.
为此,您首先需要授予代理访问外部数据源的权限,并将其连接到其他应用程序的现有 API。这使得 FM 能够为智能体提供支持,与更广阔的世界进行交互,并将其效用扩展到语言处理任务之外。其次,FM 需要弄清楚要采取什么行动、使用什么信息以及执行这些行动的顺序。这要归功于 FM 令人兴奋的新兴行为——它们的推理能力。您可以通过构建包含定义和说明的提示,向 FM 展示如何处理此类交互以及如何推理任务。设计提示以引导模型获得所需输出的过程称为提示工程。
Introducing Agents for Amazon Bedrock
Agents for Amazon Bedrock automate the prompt engineering and orchestration of user-requested tasks. Once configured, an agent automatically builds the prompt and securely augments it with your company-specific information to provide responses back to the user in natural language. The agent is able to figure out the actions required to automatically process user-requested tasks. It breaks the task into multiple steps, orchestrates a sequence of API calls and data lookups, and maintains memory to complete the action for the user.
Amazon Bedrock 代理可以自动执行用户请求的任务的快速工程和编排。配置完成后,代理会自动构建提示并使用您公司特定的信息安全地对其进行增强,以自然语言向用户提供响应。代理能够找出自动处理用户请求的任务所需的操作。它将任务分解为多个步骤,编排一系列 API 调用和数据查找,并维护内存以完成用户的操作。
With fully managed agents, you don’t have to worry about provisioning or managing infrastructure. You’ll have seamless support for monitoring, encryption, user permissions, and API invocation management without writing custom code. As a developer, you can use the Bedrock console or SDK to upload the API schema. The agent then orchestrates the tasks with the help of FMs and performs API calls using AWS Lambda functions.
借助完全托管的代理,您无需担心配置或管理基础设施。您将获得对监控、加密、用户权限和 API 调用管理的无缝支持,而无需编写自定义代码。作为开发人员,您可以使用 Bedrock 控制台或 SDK 上传 API 架构。然后,代理在 FM 的帮助下编排任务,并使用 AWS Lambda 函数执行 API 调用。
Primer on Advanced Reasoning and ReAct
You can help FMs to reason and figure out how to solve user-requested tasks with a reasoning technique called ReAct (synergizing reasoning and acting). Using ReAct, you can structure prompts to show an FM how to reason through a task and decide on actions that help find a solution. The structured prompts include a sequence of question-thought-action-observation examples.
您可以使用名为 ReAct(协同推理和行动)的推理技术帮助 FM 进行推理并弄清楚如何解决用户请求的任务。使用 ReAct,您可以构建提示,向 FM 展示如何推理任务并决定有助于找到解决方案的操作。结构化提示包括一系列问题-思考-行动-观察示例。
The question is the user-requested task or problem to solve. The thought is a reasoning step that helps demonstrate to the FM how to tackle the problem and identify an action to take. The action is an API that the model can invoke from an allowed set of APIs. The observation is the result of carrying out the action. The actions that the FM is able to choose from are defined by a set of instructions that are prepended to the example prompt text. Here is an illustration of how you would build up a ReAct prompt:
问题是用户请求的任务或要解决的问题。这个想法是一个推理步骤,有助于向 FM 展示如何解决问题并确定要采取的行动。该操作是模型可以从允许的 API 集调用的 API。观察是执行行动的结果。 FM 能够选择的操作由一组附加在示例提示文本之前的指令定义。以下是如何构建 ReAct 提示的说明:

The good news is that Bedrock performs the heavy lifting for you! Behind the scenes, agents for Amazon Bedrock build the prompts based on the information and actions you provide.
好消息是 Bedrock 会为您完成繁重的工作! Amazon Bedrock 代理在幕后根据您提供的信息和操作构建提示。
Now, let me show you how to get started with agents for Amazon Bedrock.
现在,让我向您展示如何开始使用 Amazon Bedrock 代理。
Create an Agent for Amazon Bedrock
Let’s assume you’re a developer at an insurance company and want to provide a generative AI application that helps the insurance agency owners automate repetitive tasks. You create an agent in Bedrock and integrate it into your application.
假设您是一家保险公司的开发人员,希望提供一个生成式 AI 应用程序来帮助保险机构所有者自动执行重复性任务。您在 Bedrock 中创建一个代理并将其集成到您的应用程序中。
To get started with the agent, open the Bedrock console, select Agents in the left navigation panel, then choose Create Agent.
要开始使用代理,请打开 Bedrock 控制台,在左侧导航面板中选择代理,然后选择创建代理。

This starts the agent creation workflow.
这将启动代理创建工作流程。
- Provide agent details including agent name, description (optional), whether the agent is allowed to request additional user inputs, and the AWS Identity and Access Management (IAM) service role that gives your agent access to other required services, such as Amazon Simple Storage Service (Amazon S3) and AWS Lambda.
提供代理详细信息,包括代理名称、描述(可选)、是否允许代理请求其他用户输入,以及使您的代理能够访问其他所需服务(例如 Amazon Simple Storage)的 AWS Identity and Access Management (IAM) 服务角色服务 (Amazon S3) 和 AWS Lambda。

- Select a foundation model from Bedrock that fits your use case. Here, you provide an instruction to your agent in natural language. The instruction tells the agent what task it’s supposed to perform and the persona it’s supposed to assume. For example, “You are an agent designed to help with processing insurance claims and managing pending paperwork.”
从 Bedrock 中选择适合您的使用案例的基础模型。在这里,您可以用自然语言向您的代理提供指示。该指令告诉代理应该执行什么任务以及应该承担的角色。例如,“您是一名代理人,旨在帮助处理保险索赔和管理待处理的文书工作。”

- Add action groups. An action is a task that the agent can perform automatically by making API calls to your company systems. A set of actions is defined in an action group. Here, you provide an API schema that defines the APIs for all the actions in the group. You also must provide a Lambda function that represents the business logic for each API. For example, let’s define an action group called ClaimManagementActionGroup that manages insurance claims by pulling a list of open claims, identifying outstanding paperwork for each claim, and sending reminders to policy holders. Make sure to capture this information in the action group description.The business logic for my action group is captured in the Lambda function InsuranceClaimsLambda. This AWS Lambda function implements methods for the following API calls:
open-claims
,identify-missing-documents
, andsend-reminders.
Here’s a short extract from my OrderManagementLambda:
添加操作组。操作是代理可以通过对公司系统进行 API 调用来自动执行的任务。操作组中定义了一组操作。在这里,您提供一个 API 架构,该架构定义组中所有操作的 API。您还必须提供一个 Lambda 函数来表示每个 API 的业务逻辑。例如,让我们定义一个名为 ClaimManagementActionGroup 的操作组,该组通过提取未结索赔列表、识别每项索赔的未完成文书工作并向保单持有人发送提醒来管理保险索赔。确保在操作组描述中捕获此信息。

我的操作组的业务逻辑在 Lambda 函数 InsuranceClaimsLambda 中捕获。此 AWS Lambda 函数实现了以下 API 调用的方法:
open-claims
、 identify-missing-documents
和 send-reminders.
下面是我的 OrderManagementLambda 的简短摘录:Python Python
Note that you also must provide an API schema in the OpenAPI schema JSON format. Here’s what my API schema file
insurance_claim_schema.json
looks like:请注意,您还必须提供 OpenAPI 架构 JSON 格式的 API 架构。我的 API 架构文件
insurance_claim_schema.json
如下所示:JSON JSON
When a user asks your agent to complete a task, Bedrock will use the FM you configured for the agent to identify the sequence of actions and invoke the corresponding Lambda functions in the right order to solve the user-requested task.
当用户要求您的代理完成任务时,Bedrock 将使用您为代理配置的 FM 来识别操作顺序,并按正确的顺序调用相应的 Lambda 函数来解决用户请求的任务。
- In the final step, review your agent configuration and choose Create Agent.
在最后一步中,检查您的代理配置并选择创建代理。

- Congratulations, you’ve just created your first agent in Amazon Bedrock!
恭喜,您刚刚在 Amazon Bedrock 中创建了第一个代理!

Deploy an Agent for Amazon Bedrock
To deploy an agent in your application, you must create an alias. Bedrock then automatically creates a version for that alias.要在应用程序中部署代理,您必须创建别名。然后,Bedrock 会自动为该别名创建一个版本。
- In the Bedrock console, select your agent, then select Deploy, and choose Create to create an alias.
在 Bedrock 控制台中,选择您的代理,然后选择部署,然后选择创建以创建别名。

- Provide an alias name and description and choose whether to create a new version or use an existing version of your agent to associate with this alias.
提供别名和描述,并选择是创建新版本还是使用代理的现有版本与此别名关联。

- This saves a snapshot of the agent code and configuration and associates an alias with this snapshot or version. You can use the alias to integrate the agent into your applications.
这将保存代理代码和配置的快照,并将别名与该快照或版本相关联。您可以使用别名将代理集成到您的应用程序中。

Now, let’s test the insurance agent! You can do this right in the Bedrock console.
现在,让我们来测试一下保险代理人吧!您可以直接在 Bedrock 控制台中执行此操作。
Let’s ask the agent to “Send reminder to all policy holders with open claims and pending paper work.” You can see how the FM-powered agent is able to understand the user request, break down the task into steps (collect the open insurance claims, lookup the claim IDs, send reminders), and perform the corresponding actions.
让我们要求代理人“向所有有未决索赔和待处理文书工作的保单持有人发送提醒。”您可以看到基于 FM 的代理如何理解用户请求、将任务分解为多个步骤(收集未结保险索赔、查找索赔 ID、发送提醒)并执行相应的操作。

Agents for Amazon Bedrock can help you increase productivity, improve your customer service experience, or automate DevOps tasks. I’m excited to see what use cases you will implement!
Amazon Bedrock 代理可以帮助您提高工作效率、改善客户服务体验或自动执行开发运营任务。我很高兴看到您将实现哪些用例!