Skip to main content

Connery Action 工具

¥Connery Action Tool

使用此工具,你可以将单个 Connery Action 集成到你的 LangChain 代理中。

¥Using this tool, you can integrate individual Connery Action into your LangChain agent.

note

如果你想在代理中使用多个 Connery 操作,请查看 Connery 工具包 文档。

¥If you want to use more than one Connery Action in your agent, check out the Connery Toolkit 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:

先决条件

¥Prerequisites

要在你的 LangChain 代理中使用 Connery Actions,你需要做一些准备:

¥To use Connery Actions in your LangChain agent, you need to do some preparation:

  1. 使用 快速入门 指南设置 Connery Runner。

    ¥Set up the Connery runner using the Quickstart guide.

  2. 安装所有包含你想要在代理中使用的操作的插件。

    ¥Install all the plugins with the actions you want to use in your agent.

  3. 设置环境变量 CONNERY_RUNNER_URLCONNERY_RUNNER_API_KEY,以便工具包可以与 Connery Runner 通信。

    ¥Set environment variables CONNERY_RUNNER_URL and CONNERY_RUNNER_API_KEY so the toolkit can communicate with the Connery Runner.

Connery Action Tool 使用示例

¥Example of using Connery Action Tool

设置

¥Setup

要使用 Connery Action Tool,你需要安装以下官方依赖:

¥To use the Connery Action Tool you need to install the following official peer dependency:

npm install @langchain/community @langchain/core

用法

¥Usage

在下面的示例中,我们从 Connery Runner 中根据其 ID 获取操作,然后使用指定的参数调用它。

¥In the example below, we fetch action by its ID from the Connery Runner and then call it with the specified parameters.

这里,我们使用 Gmail 插件中“发送电子邮件”操作的 ID。

¥Here, we use the ID of the Send email action from the Gmail plugin.

info

你可以查看此示例 此处 的 LangSmith 跟踪。

¥You can see a LangSmith trace of this example here.

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 Reference:

note

Connery Action 是一个结构化工具,因此你只能在支持结构化工具的代理中使用它。

¥Connery Action is a structured tool, so you can only use it in the agents supporting structured tools.

¥Related