Skip to main content
Open In ColabOpen on GitHub

AWS Lambda

Amazon AWS Lambda is a serverless computing service provided by Amazon Web Services (AWS). It helps developers to build and run applications and services without provisioning or managing servers. This serverless architecture enables you to focus on writing and deploying code, while AWS automatically takes care of scaling, patching, and managing the infrastructure required to run your applications.

本笔记本介绍了如何使用 AWS Lambda 工具。

通过在提供给智能体的工具列表中包含 AWS Lambda,您可以赋予智能体调用运行在 AWS 云中的代码的能力,以满足您的各种需求。

当一个代理使用 AWS Lambda 工具时,它将提供一个字符串类型的参数,该参数会通过事件参数传递到Lambda函数中。

首先,你需要安装 boto3 个 Python 包。

%pip install --upgrade --quiet  boto3 > /dev/null
%pip install --upgrade --quiet langchain-community

为了让代理使用该工具,您必须提供与您的 lambda 函数逻辑功能相匹配的名称和描述。

你必须提供函数的名称。

请注意,由于此工具实际上只是对 boto3 库的封装,您需要运行 aws configure 才能使用该工具。更多详细信息,请参见此处

from langchain.agents import AgentType, initialize_agent, load_tools
from langchain_openai import OpenAI

llm = OpenAI(temperature=0)

tools = load_tools(
["awslambda"],
awslambda_tool_name="email-sender",
awslambda_tool_description="sends an email with the specified content to test@testing123.com",
function_name="testFunction1",
)

agent = initialize_agent(
tools, llm, agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION, verbose=True
)

agent.run("Send an email to test@testing123.com saying hello world.")