Use ListAgentActionGroups with an AWS SDK or CLI - Amazon Bedrock

Use ListAgentActionGroups with an AWS SDK or CLI

The following code examples show how to use ListAgentActionGroups.

Action examples are code excerpts from larger programs and must be run in context. You can see this action in context in the following code example:

JavaScript
SDK for JavaScript (v3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

List the action groups for an agent.

// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. // SPDX-License-Identifier: Apache-2.0 import { fileURLToPath } from "url"; import { checkForPlaceholders } from "../lib/utils.js"; import { BedrockAgentClient, ListAgentActionGroupsCommand, paginateListAgentActionGroups, } from "@aws-sdk/client-bedrock-agent"; /** * Retrieves a list of Action Groups of an agent utilizing the paginator function. * * This function leverages a paginator, which abstracts the complexity of pagination, providing * a straightforward way to handle paginated results inside a `for await...of` loop. * * @param {string} agentId - The unique identifier of the agent. * @param {string} agentVersion - The version of the agent. * @param {string} [region='us-east-1'] - The AWS region in use. * @returns {Promise<ActionGroupSummary[]>} An array of action group summaries. */ export const listAgentActionGroupsWithPaginator = async ( agentId, agentVersion, region = "us-east-1", ) => { const client = new BedrockAgentClient({ region }); // Create a paginator configuration const paginatorConfig = { client, pageSize: 10, // optional, added for demonstration purposes }; const params = { agentId, agentVersion }; const pages = paginateListAgentActionGroups(paginatorConfig, params); // Paginate until there are no more results const actionGroupSummaries = []; for await (const page of pages) { actionGroupSummaries.push(...page.actionGroupSummaries); } return actionGroupSummaries; }; /** * Retrieves a list of Action Groups of an agent utilizing the ListAgentActionGroupsCommand. * * This function demonstrates the manual approach, sending a command to the client and processing the response. * Pagination must manually be managed. For a simplified approach that abstracts away pagination logic, see * the `listAgentActionGroupsWithPaginator()` example below. * * @param {string} agentId - The unique identifier of the agent. * @param {string} agentVersion - The version of the agent. * @param {string} [region='us-east-1'] - The AWS region in use. * @returns {Promise<ActionGroupSummary[]>} An array of action group summaries. */ export const listAgentActionGroupsWithCommandObject = async ( agentId, agentVersion, region = "us-east-1", ) => { const client = new BedrockAgentClient({ region }); let nextToken; const actionGroupSummaries = []; do { const command = new ListAgentActionGroupsCommand({ agentId, agentVersion, nextToken, maxResults: 10, // optional, added for demonstration purposes }); /** @type {{actionGroupSummaries: ActionGroupSummary[], nextToken?: string}} */ const response = await client.send(command); for (const actionGroup of response.actionGroupSummaries || []) { actionGroupSummaries.push(actionGroup); } nextToken = response.nextToken; } while (nextToken); return actionGroupSummaries; }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { // Replace the placeholders for agentId and agentVersion with an existing agent's id and version. // Ensure to remove the brackets '[]' before adding your data. // The agentId must be an alphanumeric string with exactly 10 characters. const agentId = "[ABC123DE45]"; // A string either containing `DRAFT` or a number with 1-5 digits (e.g., '123' or 'DRAFT'). const agentVersion = "[DRAFT]"; // Check for unresolved placeholders in agentId and agentVersion. checkForPlaceholders([agentId, agentVersion]); console.log("=".repeat(68)); console.log( "Listing agent action groups using ListAgentActionGroupsCommand:", ); for (const actionGroup of await listAgentActionGroupsWithCommandObject( agentId, agentVersion, )) { console.log(actionGroup); } console.log("=".repeat(68)); console.log( "Listing agent action groups using the paginateListAgents function:", ); for (const actionGroup of await listAgentActionGroupsWithPaginator( agentId, agentVersion, )) { console.log(actionGroup); } }
Python
SDK for Python (Boto3)
Note

There's more on GitHub. Find the complete example and learn how to set up and run in the AWS Code Examples Repository.

List the action groups for an agent.

def list_agent_action_groups(self, agent_id, agent_version): """ List the action groups for a version of an Amazon Bedrock Agent. :param agent_id: The unique identifier of the agent. :param agent_version: The version of the agent. :return: The list of action group summaries for the version of the agent. """ try: action_groups = [] paginator = self.client.get_paginator("list_agent_action_groups") for page in paginator.paginate( agentId=agent_id, agentVersion=agent_version, PaginationConfig={"PageSize": 10}, ): action_groups.extend(page["actionGroupSummaries"]) except ClientError as e: logger.error(f"Couldn't list action groups. {e}") raise else: return action_groups

For a complete list of AWS SDK developer guides and code examples, see Using this service with an AWS SDK. This topic also includes information about getting started and details about previous SDK versions.