Amazon Bedrock용 에이전트를 사용하는 코드 예제 AWS SDKs - Amazon Bedrock

기계 번역으로 제공되는 번역입니다. 제공된 번역과 원본 영어의 내용이 상충하는 경우에는 영어 버전이 우선합니다.

Amazon Bedrock용 에이전트를 사용하는 코드 예제 AWS SDKs

다음 코드 예제는 Amazon Bedrock용 에이전트를 AWS 소프트웨어 개발 키트 () SDK 와 함께 사용하는 방법을 보여줍니다.

작업은 대규모 프로그램에서 발췌한 코드이며 컨텍스트에 맞춰 실행해야 합니다. 작업은 개별 서비스 함수를 호출하는 방법을 보여 주며 관련 시나리오와 교차 서비스 예시에서 컨텍스트에 맞는 작업을 볼 수 있습니다.

시나리오는 동일한 서비스 내에서 여러 함수를 호출하여 특정 태스크를 수행하는 방법을 보여주는 코드 예시입니다.

AWS SDK개발자 안내서 및 코드 예제의 전체 목록은 을 참조하십시오. 이 서비스를 다음과 함께 사용 AWS SDK 이 항목에는 시작하기 관련 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.

시작하기

다음 코드 예제는 Amazon Bedrock용 에이전트 사용을 시작하는 방법을 보여줍니다.

JavaScript
SDK 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, GetAgentCommand, paginateListAgents, } from "@aws-sdk/client-bedrock-agent"; /** * @typedef {Object} AgentSummary */ /** * A simple scenario to demonstrate basic setup and interaction with the Bedrock Agents Client. * * This function first initializes the Amazon Bedrock Agents client for a specific region. * It then retrieves a list of existing agents using the streamlined paginator approach. * For each agent found, it retrieves detailed information using a command object. * * Demonstrates: * - Use of the Bedrock Agents client to initialize and communicate with the AWS service. * - Listing resources in a paginated response pattern. * - Accessing an individual resource using a command object. * * @returns {Promise<void>} A promise that resolves when the function has completed execution. */ export const main = async () => { const region = "us-east-1"; console.log("=".repeat(68)); console.log(`Initializing Amazon Bedrock Agents client for ${region}...`); const client = new BedrockAgentClient({ region }); console.log(`Retrieving the list of existing agents...`); const paginatorConfig = { client }; const pages = paginateListAgents(paginatorConfig, {}); /** @type {AgentSummary[]} */ const agentSummaries = []; for await (const page of pages) { agentSummaries.push(...page.agentSummaries); } console.log(`Found ${agentSummaries.length} agents in ${region}.`); if (agentSummaries.length > 0) { for (const agentSummary of agentSummaries) { const agentId = agentSummary.agentId; console.log("=".repeat(68)); console.log(`Retrieving agent with ID: ${agentId}:`); console.log("-".repeat(68)); const command = new GetAgentCommand({ agentId }); const response = await client.send(command); const agent = response.agent; console.log(` Name: ${agent.agentName}`); console.log(` Status: ${agent.agentStatus}`); console.log(` ARN: ${agent.agentArn}`); console.log(` Foundation model: ${agent.foundationModel}`); } } console.log("=".repeat(68)); }; // Invoke main function if this file was run directly. if (process.argv[1] === fileURLToPath(import.meta.url)) { await main(); }
  • 자세한 API 내용은 AWS SDK for JavaScript APIReference의 다음 항목을 참조하십시오.