ListAgentActionGroups与 AWS SDK 或 CLI 配合使用 - Amazon Bedrock

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

ListAgentActionGroups与 AWS SDK 或 CLI 配合使用

以下代码示例演示如何使用 ListAgentActionGroups

操作示例是大型程序的代码摘录,必须在上下文中运行。在以下代码示例中,您可以查看此操作的上下文:

JavaScript
适用于 JavaScript (v3) 的软件开发工具包
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

列出代理的操作组。

// 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)
注意

还有更多相关信息 GitHub。在 AWS 代码示例存储库中查找完整示例,了解如何进行设置和运行。

列出代理的操作组。

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
  • 有关 API 的详细信息,请参阅适用ListAgentActionGroupsPython 的AWS SDK (Boto3) API 参考

有关 S AWS DK 开发者指南和代码示例的完整列表,请参阅将此服务与 AWS SDK 配合使用。本主题还包括有关入门的信息以及有关先前的 SDK 版本的详细信息。