Connery Action 工具
使用此工具,您可以将单个 Connery Action 集成到您的 LangChain 代理中。
注意
如果您想在代理中使用多个 Connery Action,请查看 Connery Toolkit 文档。
什么是 Connery?
Connery 是一个用于 AI 的开源插件基础设施。
借助 Connery,您可以轻松创建一个包含一组操作的自定义插件,并将其无缝集成到您的 LangChain 代理中。Connery 将负责处理诸如运行时、授权、密钥管理、访问管理、审计日志和其他重要功能等关键方面。
此外,在社区的支持下,Connery 还提供了各种即用型开源插件,以增加便利性。
了解更多关于 Connery 的信息
先决条件
要在您的 LangChain 代理中使用 Connery Action,您需要做一些准备工作
- 使用快速入门指南设置 Connery Runner。
- 安装所有包含您想在代理中使用的操作的插件。
- 设置环境变量
CONNERY_RUNNER_URL
和CONNERY_RUNNER_API_KEY
,以便工具包可以与 Connery Runner 通信。
使用 Connery Action 工具的示例
设置
要使用 Connery Action 工具,您需要安装以下官方对等依赖
- npm
- Yarn
- pnpm
npm install @langchain/community @langchain/core
yarn add @langchain/community @langchain/core
pnpm add @langchain/community @langchain/core
提示
有关安装集成包的通用说明,请参阅此部分。
用法
在下面的示例中,我们从 Connery Runner 获取操作的 ID,然后使用指定的参数调用它。
在这里,我们使用 Gmail 插件中 Send email 操作的 ID。
信息
您可以在此处查看此示例的 LangSmith 跟踪。
import { ConneryService } from "@langchain/community/tools/connery";
import { ChatOpenAI } from "@langchain/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
// Specify your Connery Runner credentials.
process.env.CONNERY_RUNNER_URL = "";
process.env.CONNERY_RUNNER_API_KEY = "";
// Specify OpenAI API key.
process.env.OPENAI_API_KEY = "";
// Specify your email address to receive the emails from examples below.
const recepientEmail = "test@example.com";
// Get the SendEmail action from the Connery Runner by ID.
const conneryService = new ConneryService();
const sendEmailAction = await conneryService.getAction(
"CABC80BB79C15067CA983495324AE709"
);
// Run the action manually.
const manualRunResult = await sendEmailAction.invoke({
recipient: recepientEmail,
subject: "Test email",
body: "This is a test email sent by Connery.",
});
console.log(manualRunResult);
// Run the action using the OpenAI Functions agent.
const llm = new ChatOpenAI({ temperature: 0 });
const agent = await initializeAgentExecutorWithOptions([sendEmailAction], llm, {
agentType: "openai-functions",
verbose: true,
});
const agentRunResult = await agent.invoke({
input: `Send an email to the ${recepientEmail} and say that I will be late for the meeting.`,
});
console.log(agentRunResult);
API 文档
- ConneryService from
@langchain/community/tools/connery
- ChatOpenAI from
@langchain/openai
- initializeAgentExecutorWithOptions from
langchain/agents
注意
Connery Action 是一个结构化工具,因此您只能在支持结构化工具的代理中使用它。