Utilisation ListAgentActionGroups avec un AWS SDK ou une CLI - Amazon Bedrock

Les traductions sont fournies par des outils de traduction automatique. En cas de conflit entre le contenu d'une traduction et celui de la version originale en anglais, la version anglaise prévaudra.

Utilisation ListAgentActionGroups avec un AWS SDK ou une CLI

Les exemples de code suivants montrent comment utiliserListAgentActionGroups.

Les exemples d’actions sont des extraits de code de programmes de plus grande envergure et doivent être exécutés en contexte. Vous pouvez voir cette action en contexte dans l’exemple de code suivant :

JavaScript
SDK pour JavaScript (v3)
Note

Il y en a plus à ce sujet GitHub. Trouvez l'exemple complet et découvrez comment le configurer et l'exécuter dans le référentiel d'exemples de code AWS.

Répertoriez les groupes d'actions d'un 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); } }
  • Pour plus de détails sur l'API, reportez-vous ListAgentActionGroupsà la section Référence des AWS SDK for JavaScript API.

Python
SDK pour Python (Boto3)
Note

Il y en a plus à ce sujet GitHub. Trouvez l'exemple complet et découvrez comment le configurer et l'exécuter dans le référentiel d'exemples de code AWS.

Répertoriez les groupes d'actions d'un 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
  • Pour plus de détails sur l'API, consultez ListAgentActionGroupsle AWS manuel de référence de l'API SDK for Python (Boto3).

Pour obtenir la liste complète des guides de développement du AWS SDK et des exemples de code, consultezUtilisation de ce service avec un AWS SDK. Cette rubrique comprend également des informations sur le démarrage et sur les versions précédentes de SDK.