From improving the conversational experience to agent assistance, there are many ways generative artificial intelligence (ai) and foundation models (FM) can help deliver better, faster support. With the increasing availability and diversity of FM, it is difficult to experiment and stay up to date with the latest versions of models. Amazon Bedrock is a fully managed service that offers a selection of high-performance FMs from leading ai companies, such as AI21 Labs, Anthropic, Cohere, Meta, Stability ai, and Amazon. With Amazon Bedrock’s comprehensive capabilities, you can easily experiment with a variety of core FMs and privately customize them with your data using techniques such as fine-tuning and recovery augmented generation (RAG).
Amazon Bedrock Agents
In July, AWS announced Agent Preview for Amazon Bedrock, a new capability for developers to create fully managed agents with just a few clicks. Agents extend FMs to execute complex business tasks, from booking travel and processing insurance claims to creating advertising campaigns and managing inventory, all without writing any code. With fully managed agents, you don’t have to worry about provisioning or infrastructure management.
In this post, we provide a step-by-step guide with basic components to create a customer service bot. We use a text generation model (Anthropic Claude V2) and Amazon Bedrock agents for this solution. We provide an AWS CloudFormation template to provide the resources needed to build this solution. Then, we’ll walk you through the steps to create an agent for Amazon Bedrock.
React by requesting
FMs determine how to solve the tasks requested by users with a technique called React. It is a general paradigm that combines reasoning and action with FMs. ReAct asks FMs to generate traces of verbal reasoning and actions for a task. This allows the system to perform dynamic reasoning to create, maintain and adjust action plans while incorporating additional information into the reasoning. Structured prompts include a sequence of question-think-action-observation examples.
- The question is the task or problem to be solved requested by the user.
- The idea is a reasoning step that helps demonstrate to the FM how to approach the problem and identify an action to take.
- The action is an API that the model can call from an allowed set of APIs.
- Observation is the result of performing the action.
Components in agents for Amazon Bedrock
Behind the scenes, Amazon Bedrock agents automate rapid engineering and orchestration of user-requested tasks. They can securely augment prompts with company-specific information to provide responses to the user in natural language. The agent divides the task requested by the user into several steps and organizes subtasks with the help of FM. Action groups are tasks that the agent can perform autonomously. Action groups are mapped to an AWS Lambda function and related API schema to make API calls. The following diagram shows the structure of the agent.
Solution Overview
We used a use case from a shoe retailer to create the customer service robot. The bot helps customers shop for shoes by giving them options in a human-like conversation. Customers converse with the bot in natural language with multiple steps that invoke external APIs to perform subtasks. The following diagram illustrates the sample process flow.
The following diagram shows a high-level architecture of this solution.
- You can create an agent with Amazon Bedrock-compatible FMs, such as Anthropic Claude V2.
- Attach to the agent the API schema that resides in an Amazon Simple Storage Service (Amazon S3) bucket and a Lambda function that contains the business logic. (Note: This is a one-time setup step.)
- The agent uses the client requests to create a message using the ReAct framework. Then, use the API schema to invoke the corresponding code in the Lambda function.
- It can perform a variety of tasks, including sending email notifications, writing to databases, and triggering application APIs in Lambda functions.
In this post, we use the Lambda function to retrieve customer details, list the shoes that match the customer’s preferred activity, and finally place orders. Our code is backed by an in-memory SQLite database. You can use similar constructs to write to a persistent data store.
Previous requirements
To implement the solution provided in this post, you must have an AWS account and access to Amazon Bedrock with agents enabled (currently in preview). Use the AWS CloudFormation template to create the resource stack needed for your solution.
us-east-1 |
The CloudFormation template creates two IAM roles. Update these roles to enforce least privilege permissions as explained in Security Best Practices. Click here to learn which IAM features are available for use with Amazon Bedrock agents.
LambdaBasicExecutionRole
with full access to Amazon S3 and CloudWatch access to log in.AmazonBedrockExecutionRoleForAgents
with full access to Amazon S3 and full access to Lambda.
Important: Amazon Bedrock agents must be prefixed with the role name AmazonBedrockExecutionRoleForAgents_*
Bedrock Agent Configuration
In the next two sections, we will guide you through creating and testing an agent.
Create an agent for Amazon Bedrock
To create an agent, open the Amazon Bedrock console and choose Agents in the left navigation pane. Then select Create agent.
This starts the agent creation workflow.
- Provide agent details: Give the agent a name and description (optional). Select the service role created by the CloudFormation stack and select Next.
- Select a base model: In it Select model screen, select a model. Provide clear and precise instructions to the agent on what tasks to perform and how to interact with users.
- Add action groups: An action is a task that the agent can perform by making API calls. A set of actions make up a group of actions. Provides an API schema that defines all APIs in the action group. You must provide an API schema in the OpenAPI Scheme JSON format. The Lambda function contains the business logic necessary to make API calls. You must associate a Lambda function with each action group.
Give the action group a name and action description. Select the Lambda function, provide an API schema file, and select Next.
- In the final step, review the agent configuration and select Create agent.
Test and deploy agents for Amazon Bedrock
- Test the agent: After creating the agent, a dialog box displays the agent overview along with a working draft. The Amazon Bedrock console provides a user interface for testing your agent.
- Deploy: After a successful test, you can deploy your agent. To deploy an agent in your application, you must create an alias. Amazon Bedrock then automatically creates a version for that alias.
The following actions occur with the agent configuration above and the Lambda code provided with this post:
- The agent creates a message from instructions provided by the developer (such as “You are an agent who helps customers purchase shoes”), the API schemas needed to complete the tasks, and data source details. Automatic message creation saves weeks of experimenting with messages for different FMs.
- The agent organizes the task requested by the user, such as “I am looking for shoes”, by dividing it into smaller subtasks, such as obtaining customer details, matching the customer’s preferred activity with the shoe activity, and placing shoe orders. The agent determines the correct sequence of tasks and handles error scenarios along the way.
The following screenshot shows some examples of agent responses.
Selecting Show trace For each response, a dialog box displays the reasoning technique used by the agent and the final response generated by the FM.
Clean
To avoid incurring future charges, delete the resources. You can do this by removing the stack from the CloudFormation console.
Feel free to download and test the code used in this post from GitHub. agents for the Amazon Bedrock repository. You can also invoke Amazon Bedrock agents programmatically; a Jupyter notebook example is provided in the repository.
Conclusion
Amazon Bedrock agents can help you increase productivity, improve your customer service experience, or automate DevOps tasks. In this post, we show you how to set up agents for Amazon Bedrock to create a customer service bot.
We recommend that you learn more by reviewing the additional features of Amazon Bedrock. You can use the example code provided in this post to create your implementation. Try our workshop to gain hands-on experience with Amazon Bedrock.
About the authors
Amit Arora is an ai and ML architect at Amazon Web Services, helping enterprise customers use cloud-based machine learning services to rapidly scale their innovations. He is also an adjunct professor in the MSc Data Science and Analytics program at Georgetown University in Washington DC.
Manju Prasad is a Senior Solutions Architect within Strategic Accounts at Amazon Web Services. He focuses on providing technical guidance across a variety of domains, including ai/ML, to a prominent M&E client. Before joining AWS, he worked for companies in the Financial Services sector and also for a startup.
Archana Inapudi He is a Senior Solutions Architect at AWS and supports strategic customers. He has over a decade of experience helping clients design and build data analytics and database solutions. He is passionate about using technology to deliver value to customers and achieve business results.