ListAgentsÚselo con un AWS SDK o CLI - Amazon Bedrock

Las traducciones son generadas a través de traducción automática. En caso de conflicto entre la traducción y la version original de inglés, prevalecerá la version en inglés.

ListAgentsÚselo con un AWS SDK o CLI

Los siguientes ejemplos de código muestran cómo utilizar ListAgents.

Los ejemplos de acciones son extractos de código de programas más grandes y deben ejecutarse en contexto. Puede ver esta acción en contexto en el siguiente ejemplo de código:

JavaScript
SDKpara JavaScript (v3)
nota

Hay más información. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

Enumere los agentes que pertenecen a una cuenta.

// 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); } }
  • Para API obtener más información, consulte ListAgentsla AWS SDK for JavaScript APIReferencia.

Python
SDKpara Python (Boto3)
nota

Hay más información. GitHub Busque el ejemplo completo y aprenda a configurar y ejecutar en el Repositorio de ejemplos de código de AWS.

Enumere los agentes que pertenecen a una cuenta.

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
  • Para API obtener más información, consulte ListAgentsla AWS SDKreferencia de Python (Boto3). API

Para obtener una lista completa de guías para AWS SDK desarrolladores y ejemplos de código, consulte. Uso de este servicio con un AWS SDK En este tema también se incluye información sobre cómo empezar y detalles sobre SDK las versiones anteriores.