Connery 工具包
¥Connery Toolkit
使用此工具包,你可以将 Connery Action 集成到你的 LangChain 代理中。
¥Using this toolkit, you can integrate Connery Actions into your LangChain agent.
如果你只想在代理中使用一个特定的 Connery 操作,请查看 Connery Action 工具 文档。
¥If you want to use only one particular Connery Action in your agent, check out the Connery Action Tool documentation.
什么是 Connery?
¥What is Connery?
Connery 是一个开源的 AI 插件基础架构。
¥Connery is an open-source plugin infrastructure for AI.
使用 Connery,你可以轻松创建包含一系列操作的自定义插件,并将其无缝集成到你的 LangChain 代理中。Connery 将负责关键方面,例如运行时、授权、密钥管理、访问管理、审计日志和其他重要功能。
¥With Connery, you can easily create a custom plugin with a set of actions and seamlessly integrate them into your LangChain agent. Connery will take care of critical aspects such as runtime, authorization, secret management, access management, audit logs, and other vital features.
此外,在我们社区的支持下,Connery 提供了丰富多样的即用型开源插件,以提供更多便利。
¥Furthermore, Connery, supported by our community, provides a diverse collection of ready-to-use open-source plugins for added convenience.
了解更多关于 Connery 的信息:
¥Learn more about Connery:
¥Documentation: https://docs.connery.io
先决条件
¥Prerequisites
要在你的 LangChain 代理中使用 Connery Actions,你需要做一些准备:
¥To use Connery Actions in your LangChain agent, you need to do some preparation:
使用 快速入门 指南设置 Connery Runner。
¥Set up the Connery runner using the Quickstart guide.
安装所有包含你想要在代理中使用的操作的插件。
¥Install all the plugins with the actions you want to use in your agent.
设置环境变量
CONNERY_RUNNER_URL
和CONNERY_RUNNER_API_KEY
,以便工具包可以与 Connery Runner 通信。¥Set environment variables
CONNERY_RUNNER_URL
andCONNERY_RUNNER_API_KEY
so the toolkit can communicate with the Connery Runner.
Connery Toolkit 使用示例
¥Example of using Connery Toolkit
设置
¥Setup
要使用 Connery Toolkit,你需要安装以下官方依赖:
¥To use the Connery Toolkit you need to install the following official 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
用法
¥Usage
在下面的示例中,我们创建一个代理,它使用两个 Connery Action 来汇总一个公共网页并通过电子邮件发送摘要:
¥In the example below, we create an agent that uses two Connery Actions to summarize a public webpage and send the summary by email:
从 Summarization 插件中总结公共网页操作。
¥Summarize public webpage action from the Summarization plugin.
从 Gmail 插件发送电子邮件操作。
¥Send email action from the Gmail plugin.
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 Reference:
- ConneryService from
@langchain/community/tools/connery
- ConneryToolkit from
@langchain/community/agents/toolkits/connery
- ChatOpenAI from
@langchain/openai
- initializeAgentExecutorWithOptions from
langchain/agents
Connery Action 是一个结构化工具,因此你只能在支持结构化工具的代理中使用它。
¥Connery Action is a structured tool, so you can only use it in the agents supporting structured tools.