Gunakan GetAgent dengan AWS SDK atau CLI - Amazon Bedrock

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

Gunakan GetAgent dengan AWS SDK atau CLI

Contoh kode berikut menunjukkan cara menggunakanGetAgent.

Contoh tindakan adalah kutipan kode dari program yang lebih besar dan harus dijalankan dalam konteks. Anda dapat melihat tindakan ini dalam konteks dalam contoh kode berikut:

JavaScript
SDK untuk JavaScript (v3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di AWS Repositori Contoh Kode.

Dapatkan agen.

// 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, GetAgentCommand, } from "@aws-sdk/client-bedrock-agent"; /** * Retrieves the details of an Amazon Bedrock Agent. * * @param {string} agentId - The unique identifier of the agent. * @param {string} [region='us-east-1'] - The AWS region in use. * @returns {Promise<import("@aws-sdk/client-bedrock-agent").Agent>} An object containing the agent details. */ export const getAgent = async (agentId, region = "us-east-1") => { const client = new BedrockAgentClient({ region }); const command = new GetAgentCommand({ agentId }); const response = await client.send(command); return response.agent; }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { // Replace the placeholders for agentId with an existing agent's id. // Ensure to remove the brackets '[]' before adding your data. // The agentId must be an alphanumeric string with exactly 10 characters. const agentId = "[ABC123DE45]"; // Check for unresolved placeholders in agentId. checkForPlaceholders([agentId]); console.log(`Retrieving agent with ID ${agentId}...`); const agent = await getAgent(agentId); console.log(agent); }
  • Untuk detail API, lihat GetAgentdi Referensi AWS SDK for JavaScript API.

Python
SDK untuk Python (Boto3)
catatan

Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankannya di AWS Repositori Contoh Kode.

Dapatkan agen.

def get_agent(self, agent_id, log_error=True): """ Gets information about an agent. :param agent_id: The unique identifier of the agent. :param log_error: Whether to log any errors that occur when getting the agent. If True, errors will be logged to the logger. If False, errors will still be raised, but not logged. :return: The information about the requested agent. """ try: response = self.client.get_agent(agentId=agent_id) agent = response["agent"] except ClientError as e: if log_error: logger.error(f"Couldn't get agent {agent_id}. {e}") raise else: return agent
  • Untuk detail API, lihat GetAgentdi AWS SDK for Python (Boto3) Referensi API.

Untuk daftar lengkap panduan pengembang AWS SDK dan contoh kode, lihatMenggunakan layanan ini dengan AWS SDK. Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.