AWS SDK または CLI ListAgentsで を使用する - Amazon Bedrock

翻訳は機械翻訳により提供されています。提供された翻訳内容と英語版の間で齟齬、不一致または矛盾がある場合、英語版が優先します。

AWS SDK または CLI ListAgentsで を使用する

以下のコード例は、ListAgents の使用方法を示しています。

アクション例は、より大きなプログラムからのコードの抜粋であり、コンテキスト内で実行する必要があります。次のコード例で、このアクションのコンテキストを確認できます。

JavaScript
SDK for 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 { BedrockAgentClient, ListAgentsCommand, paginateListAgents, } from "@aws-sdk/client-bedrock-agent"; /** * Retrieves a list of available Amazon Bedrock agents 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} [region='us-east-1'] - The AWS region in use. * @returns {Promise<AgentSummary[]>} An array of agent summaries. */ export const listAgentsWithPaginator = async (region = "us-east-1") => { const client = new BedrockAgentClient({ region }); const paginatorConfig = { client, pageSize: 10, // optional, added for demonstration purposes }; const pages = paginateListAgents(paginatorConfig, {}); // Paginate until there are no more results const agentSummaries = []; for await (const page of pages) { agentSummaries.push(...page.agentSummaries); } return agentSummaries; }; /** * Retrieves a list of available Amazon Bedrock agents utilizing the ListAgentsCommand. * * 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 `listAgentsWithPaginator()` example below. * * @param {string} [region='us-east-1'] - The AWS region in use. * @returns {Promise<AgentSummary[]>} An array of agent summaries. */ export const listAgentsWithCommandObject = async (region = "us-east-1") => { const client = new BedrockAgentClient({ region }); let nextToken; const agentSummaries = []; do { const command = new ListAgentsCommand({ nextToken, maxResults: 10, // optional, added for demonstration purposes }); /** @type {{agentSummaries: AgentSummary[], nextToken?: string}} */ const paginatedResponse = await client.send(command); agentSummaries.push(...(paginatedResponse.agentSummaries || [])); nextToken = paginatedResponse.nextToken; } while (nextToken); return agentSummaries; }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { console.log("=".repeat(68)); console.log("Listing agents using ListAgentsCommand:"); for (const agent of await listAgentsWithCommandObject()) { console.log(agent); } console.log("=".repeat(68)); console.log("Listing agents using the paginateListAgents function:"); for (const agent of await listAgentsWithPaginator()) { console.log(agent); } }
  • API の詳細については、「 API リファレンスListAgents」の「」を参照してください。 AWS SDK for JavaScript

Python
SDK for Python (Boto3)
注記

については、「」を参照してください GitHub。AWS コード例リポジトリ で全く同じ例を見つけて、設定と実行の方法を確認してください。

アカウントに属するエージェントを一覧表示します。

def list_agents(self): """ List the available Amazon Bedrock Agents. :return: The list of available bedrock agents. """ try: all_agents = [] paginator = self.client.get_paginator("list_agents") for page in paginator.paginate(PaginationConfig={"PageSize": 10}): all_agents.extend(page["agentSummaries"]) except ClientError as e: logger.error(f"Couldn't list agents. {e}") raise else: return all_agents
  • API の詳細については、 ListAgents AWS SDK for Python (Boto3) API リファレンスの「」を参照してください。

AWS SDK デベロッパーガイドとコード例の完全なリストについては、「」を参照してくださいAWS SDK でこのサービスを使用する。このトピックには、使用開始方法に関する情報と、以前の SDK バージョンの詳細も含まれています。