Create an agent - Amazon Bedrock

Create an agent

To create an agent, you set up the following components:

  • The configuration of the agent itself, which defines the purpose of the agent and the foundation model that it should use to interpret and generate prompts.

  • Action groups that define what actions the agent is designed to carry out.

  • (Optional) A knowledge base of data sources to augment the generative capabilities of the agent.

    Note

    If you plan to attach a knowledge base to your agent, first set up your knowledge base by following the steps at Knowledge base for Amazon Bedrock.

Prerequisites

Before you can create your agent, carry out the following steps.

  1. (Optional) If you opt out of using a role automatically created by Amazon Bedrock, set up a custom role by following the steps at Permissions to create and manage an agent.

  2. When you create an agent, you define action groups that your agent will carry out. For each action group, you need to set up the following items.

    1. Set up the Lambda function that defines the business logic for the action that your agent will carry out. For more information, see Action group Lambda functions.

      Note

      Configure permissions for your agent to be able to access the Lambda function. For more information, see Resource-based policy to allow Amazon Bedrock to invoke an action group Lambda function. You need to attach these permissions even if you use a role that is automatically created by Amazon Bedrock during the agent creation process.

    2. Set up the OpenAPI schema with the API description, structure, and parameters for the action group. Upload a schema you have created to an Amazon S3 bucket or define the schema with the help of the inline OpenAPI schema editor in the console after you have created the agent. For more information, see Action group OpenAPI schemas.

  3. Set up any knowledge bases that you want your agent to be able to query. For more information, see Knowledge base for Amazon Bedrock.

Steps to create an agent

To create an agent, visit https://console.aws.amazon.com/bedrock/ Choose Agents in the left navigation pane. Then select Create at the top right corner of the Agents section.

Provide agent details
  1. In the Agent name section, give the agent a name and an optional description.

  2. In the User input section, select whether you want the agent to request the user for additional information when trying to complete a task.

    • If you select Yes, during orchestration, if the agent determines that it needs to invoke an API in an action group, but doesn't have enough information to complete the API request, it returns an Observation reprompting the user for more information.

    • If you select No, the agent doesn't request the user for additional details and informs the user that it doesn't have enough information to complete the task.

  3. In the IAM permissions section, choose an AWS Identity and Access Management (IAM) role that provides Agents for Amazon Bedrock permission to access other AWS services. You can let Agents for Amazon Bedrock create the service role (for more information, see Service roles for Amazon Bedrock) or you can choose a custom role that you have created.

    Note

    The service role that Agents for Amazon Bedrock creates for you doesn't support permissions for features that are in preview. In order to use these features, you must attach the correct permissions to the service role.

    Note

    For information about the requirements for a custom role, see Permissions to create and manage an agent. Your custom role must begin with the prefix AmazonBedrockExecutionRoleForAgents_.

  4. By default, AWS encrypts sessions with your agent with a key that Agents for Amazon Bedrock owns. To encrypt your agent with your own key, select Customize encryption settings (advanced) in the KMS key selection section and Choose an AWS KMS key. If you want to create a new key, select Create an AWS KMS key and reload this window.

  5. In the Idle session timeout section, choose a duration of time. If the user has not responded in the same session after this amount of time, Amazon Bedrock no longer maintains the conversation history. Conversation history is used to both resume an interaction and to augment responses with context from the conversation.

  6. (Optional) In the Tags section, select Add new tag to associate tags with this agent. Fill in a key-value pair for each tag to add.

  7. Select Next when you are done setting up the agent configuration.

Select model
  1. For the agent to perform orchestration, you need to choose a model. In the Model details selection, choose a model provider and then choose a model in the dropdown menu to train your agent.

  2. In Instructions for the Agent, provide details to tell the agent what it should do and how it should interact with users. Refer to the following sample instructions:

    You are an office assistant in an insurance agency. You are friendly and polite. You help with managing insurance claims and coordinating pending paperwork.
Add Action groups
  1. Provide a name for your action group and describe what the action does in the Description for action groups.

  2. In Select Lambda function, choose a Lambda function that you created in AWS Lambda. The Lambda function provides the business logic that is carried out upon invoking the action. Choose the version of the function to use. For more information, see Action group Lambda functions

    Note

    Remember to attach a resource-based policy to the Lambda function to allow the Amazon Bedrock service principal to access the Lambda function. For more information, see Resource-based policy to allow Amazon Bedrock to invoke an action group Lambda function.

  3. In Select API schema, provide a link to the Amazon S3 URI of the schema with the API description, structure, and parameters for the action group. For more information, see Action group OpenAPI schemas.

    Note

    You can use the text editor to edit the schema after you have created the agent.

  4. Select Add another Action group to set up another action group for your agent. When you are done adding action groups, select Next.

Add knowledge bases
  1. If you have not yet created any knowledge bases, select Knowledge base in the left navigation pane and follow the instructions at Create a knowledge base to create one. Otherwise, select a knowledge base from the dropdown menu.

  2. Write a prompt in Knowledge base instructions for the agent to describe how the agent should use the knowledge base. For example, you can use the following text for a knowledge base called Domain name system details:

    Use this knowledge base whenever you are creating a DNS record
  3. Select Add another knowledge base to set up another knowledge base for your agent. When you are done adding knowledge bases, select Next.

Review the configuration of your agent and choose Edit for any sections you want to change. Select Create when you are ready to create the agent. When the process finishes, a green banner appears at the top to inform you that the agent was successfully created.