Le traduzioni sono generate tramite traduzione automatica. In caso di conflitto tra il contenuto di una traduzione e la versione originale in Inglese, quest'ultima prevarrà.
Utilizzo GetAgent
con un AWS SDK o una CLI
I seguenti esempi di codice mostrano come utilizzareGetAgent
.
Gli esempi di operazioni sono estratti di codice da programmi più grandi e devono essere eseguiti nel contesto. È possibile visualizzare questa operazione nel contesto nel seguente esempio di codice:
- JavaScript
-
- SDK per JavaScript (v3)
-
Trovate un agente.
// 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);
}
- Python
-
- SDK per Python (Boto3)
-
Trovate un agente.
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
Per un elenco completo delle guide per sviluppatori AWS SDK e degli esempi di codice, consulta. Utilizzo di questo servizio con un AWS SDK Questo argomento include anche informazioni su come iniziare e dettagli sulle versioni precedenti dell'SDK.