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

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

GetAgent与 AWS SDK 或 CLI 配合使用

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

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

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, 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); }
  • 有关 API 的详细信息,请参阅 AWS SDK for JavaScript API 参考GetAgent中的。

Python
SDK for Python (Boto3)
注意

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

获取代理。

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

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