Add an action group to your agent in Amazon Bedrock - Amazon Bedrock

Add an action group to your agent in Amazon Bedrock

After setting up the OpenAPI schema and Lambda function for your action group, you can create the action group. Select the tab corresponding to your method of choice and follow the steps:

Note

If you are using Anthropic Claude 3.5 Sonnet, make sure that your tool name which will be of the form httpVerb__actionGroupName__apiName follows the Anthropic tool name format ^[a-zA-Z0-9_-]{1,64}$. Your actionGroupName and apiName must not contain double underscores '__'.

Console

When you create an agent, you can add action groups to the working draft.

After an agent is created, you can add action groups to it by doing the following steps:

To add an action group to an agent
  1. Sign in to the AWS Management Console using an IAM role with Amazon Bedrock permissions, and open the Amazon Bedrock console at https://console.aws.amazon.com/bedrock/.

  2. Select Agents from the left navigation pane. Then, choose an agent in the Agents section.

  3. Choose Edit in Agent builder.

  4. In the Action groups section, choose Add.

  5. (Optional) In the Action group details section, change the automatically generated Name and provide an optional Description for your action group.

  6. In the Action group type section, select one of the following methods for defining the parameters that the agent can elicit from users to help carry out actions:

    1. Define with function details – Define parameters for your agent to elicit from the user in order to carry out the actions. For more information on adding functions, see Define function details for your agent's action groups in Amazon Bedrock.

    2. Define with API schemas – Define the API operations that the agent can invoke and the parameters . Use an OpenAPI schema that you created or use the console text editor to create the schema. For more information on setting up an OpenAPI schema, see Define OpenAPI schemas for your agent's action groups in Amazon Bedrock

  7. In the Action group invocation section, you set up what the agent does after it predicts the API or function that it should invoke and receives the parameters that it needs. Choose one of the following options:

    • Quick create a new Lambda function – recommended – Let Amazon Bedrock create a basic Lambda function for your agent that you can later modify in AWS Lambda for your use case. The agent will pass the API or function that it predicts and the parameters, based on the session, to the Lambda function.

    • Select an existing Lambda function – Choose a Lambda function that you created previously in AWS Lambda and the version of the function to use. The agent will pass the API or function that it predicts and the parameters, based on the session, to the Lambda function.

      Note

      To allow the Amazon Bedrock service principal to access the Lambda function, attach a resource-based policy to the Lambda function to allow the Amazon Bedrock service principal to access the Lambda function.

    • Return control – Rather than passing the parameters for the API or function that it predicts to the Lambda function, the agent returns control to your application by passing the action that it predicts should be invoked, in addition to the parameters and information for the action that it determined from the session, in the InvokeAgent response. For more information, see Return control to the agent developer by sending elicited information in an InvokeAgent response.

  8. Depending on your choice for the Action group type, you'll see one of the following sections:

    • If you selected Define with function details, you'll have an Action group function section. Do the following to define the function:

      1. Provide a Name and optional (but recommended) Description.

      2. To request confirmation from the user before the function is invoked, select Enabled. Requesting confirmation before invoking the function may safeguard your application from taking actions due to malicious prompt injections.

      3. In the Parameters subsection, choose Add parameter. Define the following fields:

        Field Description
        Name Give a name to the parameter.
        Description (optional) Describe the parameter.
        Type Specify the data type of the parameter.
        Required Specify whether the agent requires the parameter from the user.
      4. To add another parameter, choose Add parameter.

      5. To edit a field in a parameter, select the field and edit it as necessary.

      6. To delete a parameter, choose the delete icon ( Trapezoid-shaped diagram showing data flow from source to destination through AWS Transfer Family. ) in the row containing the parameter.

      If you prefer to define the function by using a JSON object, choose JSON editor instead of Table. The JSON object format is as follows (each key in the parameters object is a parameter name that you provide):

      { "name": "string", "description": "string", "parameters": [ { "name": "string", "description": "string", "required": "True" | "False", "type": "string" | "number" | "integer" | "boolean" | "array" } ] }

      To add another function to your action group by defining another set of parameters, choose Add action group function.

    • If you selected Define with API schemas, you'll have an Action group schema section with the following options:

      • To use an OpenAPI schema that you previously prepared with API descriptions, structures, and parameters for the action group, select Select API schema and provide a link to the Amazon S3 URI of the schema.

      • To define the OpenAPI schema with the in-line schema editor, select Define via in-line schema editor. A sample schema appears that you can edit.

        1. Select the format for the schema by using the dropdown menu next to Format.

        2. To import an existing schema from S3 to edit, select Import schema, provide the S3 URI, and select Import.

        3. To restore the schema to the original sample schema, select Reset and then confirm the message that appears by selecting Reset again.

  9. When you're done creating the action group, choose Add. If you defined an API schema, a green success banner appears if there are no issues. If there are issues validating the schema, a red banner appears. You have the following options:

    • Scroll through the schema to see the lines where an error or warning about formatting exists. An X indicates a formatting error, while an exclamation mark indicates a warning about formatting.

    • Select View details in the red banner to see a list of errors about the content of the API schema.

  10. Make sure to Prepare to apply the changes that you have made to the agent before testing it.

API

To create an action group, send a CreateAgentActionGroup request (see link for request and response formats and field details) with an Agents for Amazon Bedrock build-time endpoint. You must provide either a function schema or an OpenAPI schema.

See code examples

The following list describes the fields in the request:

  • The following fields are required:

    Field Short description
    agentId The ID of the agent that the action group belongs to.
    agentVersion The version of the agent that the action group belongs to.
    actionGroupName The name of the action group.
  • To define the parameters for the action group, you must specify one of the following fields (you can't specify both).

    Field Short description
    functionSchema Defines the parameters for the action group that the agent elicits from the user. For more information, see Define function details for your agent's action groups in Amazon Bedrock.
    apiSchema Specifies the OpenAPI schema defining the parameters for the action group or links to an S3 object containing it. For more information, see Define OpenAPI schemas for your agent's action groups in Amazon Bedrock.

    The following shows the general format of the functionSchema and apiSchema:

    • Each item in the functionSchema array is a FunctionSchema object. For each function, specify the following:

      • Provide a name and optional (but recommended) description.

      • Optionally, specify ENABLED for requireConfirmation field to request confirmation from the user before the function is invoked. Requesting confirmation before invoking the function may safeguard your application from taking actions due to malicious prompt injections.

      • In the parameters object, each key is a parameter name, mapped to details about it in a ParameterDetail object.

      The general format of the functionSchema is as follows:

      "functionSchema": [ { "name": "string", "description": "string", "requireConfirmation": ENABLED | DISABLED, "parameters": { "<string>": { "type": "string" | number | integer | boolean | array, "description": "string", "required": boolean }, ... // up to 5 parameters } }, ... // up to 11 functions ]
    • The APISchema can be in one of the following formats:

      1. For the following format, you can directly paste the JSON or YAML-formatted OpenAPI schema as the value.

        "apiSchema": { "payload": "string" }
      2. For the following format, specify the Amazon S3 bucket name and object key where the OpenAPI schema is stored.

        "apiSchema": { "s3": { "s3BucketName": "string", "s3ObjectKey": "string" } }
  • To configure how the action group handles the invocation of the action group after eliciting parameters from the user, you must specify one of the following fields within the actionGroupExecutor field.

    Field Short description
    lambda To send the parameters to a Lambda function to handle the action group invocation results, specify the Amazon Resource Name (ARN) of the Lambda. For more information, see Configure Lambda functions to send information an Amazon Bedrock agent elicits from the user.
    customControl To skip using a Lambda function and instead return the predicted action group, in addition to the parameters and information required for it, in the InvokeAgent response, specify RETURN_CONTROL. For more information, see Return control to the agent developer by sending elicited information in an InvokeAgent response.
  • The following fields are optional:

    Field Short description
    parentActionGroupSignature Specify AMAZON.UserInput to allow the agent to reprompt the user for more information if it doesn't have enough information to complete another action group. You must leave the description, apiSchema, and actionGroupExecutor fields blank if you specify this field.
    description A description of the action group.
    actionGroupState Whether to allow the agent to invoke the action group or not.
    clientToken An identifier to prevent requests from being duplicated.