AWS Lambda 에이전트 통합

AWS Lambda 에이전트 통합 (Agent with AWS lambda integration)

LangChain JavaScript로 AWS Lambda 툴을 가진 에이전트와 통합해요.

전체 문서: https://docs.aws.amazon.com/lambda/index.html

AWS Lambda는 Amazon Web Services(AWS)가 제공하는 서버리스 컴퓨팅 서비스로, 개발자가 서버를 프로비저닝하거나 관리할 필요 없이 애플리케이션과 서비스를 구축·실행할 수 있게 해줘요. 이 서버리스 아키텍처를 통해 코드 작성과 배포에 집중할 수 있고, AWS가 앱 실행에 필요한 인프라의 스케일링·패치·관리를 자동으로 처리해요.

에이전트에 제공하는 툴 목록에 AWSLambda를 포함하면, 에이전트가 필요한 목적을 위해 AWS 클라우드에서 실행 중인 코드를 호출할 수 있게 해줘요.

에이전트가 AWSLambda 툴을 사용할 때는 string 타입의 인자를 제공하며, 이 인자는 event 파라미터를 통해 Lambda 함수에 전달돼요.

이 퀵스타트는 에이전트가 Lambda 함수를 사용해 Amazon Simple Email Service로 이메일을 보내는 방법을 보여줘요. 이메일을 보내는 lambda 코드는 제공되지 않지만, 방법을 배우고 싶다면 Lambda와 SES로 이메일 보내는 방법을 참고하세요. 의도적으로 단순한 예제라는 점을 기억하세요; Lambda는 거의 무한한 다른 목적(더 많은 Langchain 실행 포함!)을 위해 코드를 실행하는 데 사용될 수 있어요.

자격 증명에 대한 참고 (Note about credentials):

  • AWS CLI로 aws configure를 실행하지 않았다면, region, accessKeyId, secretAccessKey를 AWSLambda 생성자에 제공해야 해요.
  • 해당 자격 증명에 대응하는 IAM 역할은 lambda 함수를 호출할 권한이 있어야 해요.
LangChain 패키지 설치에 대한 일반적인 지침은 [이 섹션](/oss/javascript/langchain/install)을 참고하세요.
npm install @langchain/openai @langchain/core
import { OpenAI } from "@langchain/openai";
import { SerpAPI } from "@langchain/classic/tools";
import { AWSLambda } from "@langchain/classic/tools/aws_lambda";
import { initializeAgentExecutorWithOptions } from "@langchain/classic/agents";

const model = new OpenAI({ temperature: 0 });
const emailSenderTool = new AWSLambda({
  name: "email-sender",
  // tell the Agent precisely what the tool does
  description:
    "Sends an email with the specified content to [email protected]",
  region: "us-east-1", // optional: AWS region in which the function is deployed
  accessKeyId: "abc123", // optional: access key id for an IAM user with invoke permissions
  secretAccessKey: "xyz456", // optional: secret access key for that IAM user
  functionName: "SendEmailViaSES", // the function name as seen in AWS Console
});
const tools = [emailSenderTool, new SerpAPI("api_key_goes_here")];
const executor = await initializeAgentExecutorWithOptions(tools, model, {
  agentType: "zero-shot-react-description",
});

const input = `Find out the capital of Croatia. Once you have it, email the answer to [email protected].`;
const result = await executor.invoke({ input });
console.log(result);

출처: 문서

본문

에이전트의 툴 목록에 AWSLambda 툴을 추가해 AWS 클라우드의 코드를 호출할 수 있어요. Lambda는 서버리스 컴퓨팅 서비스로, 툴 사용 시 string 타입 인자를 event 파라미터로 전달해 함수를 실행해요. 이 예제에서는 세부 정보를 가진 AWSLambda 툴을 생성하고 initializeAgentExecutorWithOptions로 에이전트에 등록해, 검색 결과를 이메일로 보내는 흐름을 보여줘요. AWS CLI 구성이 없다면 region·accessKeyId·secretAccessKey를 생성자에 제공해야 하며, 해당 IAM 역할에 lambda 호출 권한이 필요해요.

더 알아보기 (Learn more)