AWS Lambda
Amazon AWS Lambda是Amazon Web Services(AWS) 提供的一项无服务器计算服务。它帮助开发者在不配置或不管理服务器的情况下构建和运行应用程序及服务。这种无服务器架构使您能够专注于编写和部署代码,而 AWS 会自动处理运行应用程序所需的基础设施的扩展 、修补和管理。
本 Notebook 将介绍如何使用 AWS Lambda 工具。
通过将 AWS Lambda 工具包含在提供给 Agent 的工具列表中,您可以授权您的 Agent 调用您 AWS 云中运行的代码,以满足您的任何需求。
当 Agent 使用 AWS Lambda 工具时,它将提供一个字符串类型的参数,该参数将通过 event 参数传递到 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.")
Related
- Tool conceptual guide
- Tool how-to guides