Connery 工具包
使用此工具包,您可以将 Connery Actions 集成到您的 LangChain Agent 中。
注意
如果您只想在您的 Agent 中使用一个特定的 Connery Action,请查看 Connery Action 工具 文档。
什么是 Connery?
Connery 是一个用于 AI 的开源插件基础设施。
使用 Connery,您可以轻松创建一个包含一组操作的自定义插件,并将其无缝集成到您的 LangChain Agent 中。Connery 将负责处理关键方面,例如运行时、授权、密钥管理、访问管理、审计日志和其他重要功能。
此外,在我们的社区支持下,Connery 提供了各种即用型开源插件,以增加便利性。
了解更多关于 Connery 的信息
先决条件
要在您的 LangChain Agent 中使用 Connery Actions,您需要做一些准备工作
- 使用 快速入门 指南设置 Connery 运行器。
- 安装所有包含您想在 Agent 中使用的 Actions 的插件。
- 设置环境变量
CONNERY_RUNNER_URL
和CONNERY_RUNNER_API_KEY
,以便工具包可以与 Connery Runner 通信。
使用 Connery 工具包的示例
设置
要使用 Connery 工具包,您需要安装以下官方 peer dependency
- npm
- Yarn
- pnpm
npm install @langchain/openai @langchain/community @langchain/core
yarn add @langchain/openai @langchain/community @langchain/core
pnpm add @langchain/openai @langchain/community @langchain/core
提示
请参阅 此部分,了解有关安装集成包的通用说明。
用法
在下面的示例中,我们创建了一个 Agent,它使用两个 Connery Actions 来总结一个公共网页,并通过电子邮件发送摘要
- 来自 Summarization 插件的 总结公共网页 action。
- 来自 Gmail 插件的 发送电子邮件 action。
信息
您可以在 此处 查看此示例的 LangSmith 追踪。
import { ConneryService } from "@langchain/community/tools/connery";
import { ConneryToolkit } from "@langchain/community/agents/toolkits/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";
// Create a Connery Toolkit with all the available actions from the Connery Runner.
const conneryService = new ConneryService();
const conneryToolkit = await ConneryToolkit.createInstance(conneryService);
// Use OpenAI Functions agent to execute the prompt using actions from the Connery Toolkit.
const llm = new ChatOpenAI({ temperature: 0 });
const agent = await initializeAgentExecutorWithOptions(
conneryToolkit.tools,
llm,
{
agentType: "openai-functions",
verbose: true,
}
);
const result = await agent.invoke({
input:
`Make a short summary of the webpage http://www.paulgraham.com/vb.html in three sentences ` +
`and send it to ${recepientEmail}. Include the link to the webpage into the body of the email.`,
});
console.log(result.output);
API 参考
- ConneryService 来自
@langchain/community/tools/connery
- ConneryToolkit 来自
@langchain/community/agents/toolkits/connery
- ChatOpenAI 来自
@langchain/openai
- initializeAgentExecutorWithOptions 来自
langchain/agents
注意
Connery Action 是一个结构化工具,因此您只能在支持结构化工具的 Agent 中使用它。