Skip to main content

Connery Action 工具

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

note

如果要在您的代理中使用多个 Connery Action, 请参阅 Connery Toolkit 文档。

什么是 Connery?

Connery 是一个面向 AI 的开源插件基础设施。

通过 Connery,您可以轻松创建一个包含一组动作的自定义插件,并无缝集成到您的 LangChain 代理中。 Connery 将负责运行时、授权、密钥管理、访问管理、审计日志以及其他关键功能等重要方面。

此外,Connery 得益于我们社区的支持,提供了多种现成的开源插件,以增加便利性。

了解更多关于 Connery 的信息:

前提条件

要在您的 LangChain 代理中使用 Connery Actions,您需要进行一些准备工作:

  1. 使用 快速入门 指南设置 Connery 运行器。
  2. 安装所有您希望在代理中使用的动作对应的插件。
  3. 设置环境变量 CONNERY_RUNNER_URLCONNERY_RUNNER_API_KEY,以便工具包可以与 Connery Runner 进行通信。

使用 Connery Action 工具的示例

安装

要使用 Connery Action 工具,您需要安装以下官方对等依赖项:

npm install @langchain/community @langchain/core

:::提示 请参阅安装集成包的一般说明部分。 :::

使用方法

在下面的示例中,我们通过其 ID 从 Connery Runner 获取一个动作,然后使用指定的参数调用它。

这里我们使用了 Gmail 插件中 发送邮件 动作的 ID。

info

您可以在 此处 查看该示例的 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 = "[email protected]";

// 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({ model: "gpt-4o-mini", 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 是一个结构化工具,因此只能在支持结构化工具的代理中使用它。

相关内容


Was this page helpful?


You can also leave detailed feedback on GitHub.