Verwendung ListAgentActionGroups mit einem AWS SDK oder CLI - Amazon Bedrock

Die vorliegende Übersetzung wurde maschinell erstellt. Im Falle eines Konflikts oder eines Widerspruchs zwischen dieser übersetzten Fassung und der englischen Fassung (einschließlich infolge von Verzögerungen bei der Übersetzung) ist die englische Fassung maßgeblich.

Verwendung ListAgentActionGroups mit einem AWS SDK oder CLI

Die folgenden Codebeispiele zeigen, wie es verwendet wirdListAgentActionGroups.

Beispiele für Aktionen sind Codeauszüge aus größeren Programmen und müssen im Kontext ausgeführt werden. Im folgenden Codebeispiel können Sie diese Aktion im Kontext sehen:

JavaScript
SDK für JavaScript (v3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Listet die Aktionsgruppen für einen Agenten auf.

// 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 für Python (Boto3)
Anmerkung

Es gibt noch mehr dazu GitHub. Sie sehen das vollständige Beispiel und erfahren, wie Sie das AWS -Code-Beispiel-Repository einrichten und ausführen.

Listet die Aktionsgruppen für einen Agenten auf.

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

Eine vollständige Liste der AWS SDK-Entwicklerhandbücher und Codebeispiele finden Sie unter. Verwenden dieses Dienstes mit einem AWS SDK Dieses Thema enthält auch Informationen zu den ersten Schritten und Details zu früheren SDK-Versionen.