Skip to content

Commit

Permalink
Add Connery Tool and Toolkit (#3499)
Browse files Browse the repository at this point in the history
* Add ConneryApiClient class

* Intermediate sate

* Fix ConneryToolkit typo and update ConneryService
method name

* Init docs

* Update docs

* Fix imports in docs

* Create entry points for the tool and toolkit

* Fix the docs issue
  • Loading branch information
machulav authored Dec 5, 2023
1 parent 215594e commit 2c324c4
Show file tree
Hide file tree
Showing 20 changed files with 588 additions and 9 deletions.
2 changes: 2 additions & 0 deletions docs/api_refs/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"./langchain/src/agents/load.ts",
"./langchain/src/agents/toolkits/index.ts",
"./langchain/src/agents/toolkits/aws_sfn.ts",
"./langchain/src/agents/toolkits/connery/index.ts",
"./langchain/src/agents/toolkits/sql/index.ts",
"./langchain/src/agents/format_scratchpad/openai_functions.ts",
"./langchain/src/agents/format_scratchpad/openai_tools.ts",
Expand All @@ -38,6 +39,7 @@
"./langchain/src/tools/aws_lambda.ts",
"./langchain/src/tools/aws_sfn.ts",
"./langchain/src/tools/calculator.ts",
"./langchain/src/tools/connery.ts",
"./langchain/src/tools/render.ts",
"./langchain/src/tools/sql.ts",
"./langchain/src/tools/webbrowser.ts",
Expand Down
25 changes: 25 additions & 0 deletions docs/core_docs/docs/integrations/toolkits/connery.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CodeBlock from "@theme/CodeBlock";
import Example from "@examples/agents/connery_mrkl.ts";

# Connery Actions Toolkit

Using this toolkit, you can integrate Connery actions into your LangChain agents and chains.

## What is Connery?

Connery is an open-source plugin infrastructure for AI.

With Connery, you can easily create a custom plugin, which is essentially a set of actions, and use them in your LangChain agents and chains.
Connery will handle the rest: runtime, authorization, secret management, access management, audit logs, and other vital features.
Also, you can find a lot of ready-to-use plugins from our community.

Learn more about Connery:

- GitHub repository: https://github.com/connery-io/connery-platform
- Documentation: https://docs.connery.io

## Usage

This example shows how to create an agent with Connery actions using the Connery Actions Toolkit.

<CodeBlock language="typescript">{Example}</CodeBlock>
25 changes: 25 additions & 0 deletions docs/core_docs/docs/integrations/tools/connery.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import CodeBlock from "@theme/CodeBlock";
import Example from "@examples/tools/connery.ts";

# Connery Actions Tool

Using this tool, you can integrate individual Connery actions into your LangChain agents and chains.

## What is Connery?

Connery is an open-source plugin infrastructure for AI.

With Connery, you can easily create a custom plugin, which is essentially a set of actions, and use them in your LangChain agents and chains.
Connery will handle the rest: runtime, authorization, secret management, access management, audit logs, and other vital features.
Also, you can find a lot of ready-to-use plugins from our community.

Learn more about Connery:

- GitHub repository: https://github.com/connery-io/connery-platform
- Documentation: https://docs.connery.io

## Usage

This example shows how to create a tool for one specific Connery action and call it.

<CodeBlock language="typescript">{Example}</CodeBlock>
2 changes: 2 additions & 0 deletions environment_tests/test-exports-bun/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "langchain/load";
export * from "langchain/load/serializable";
export * from "langchain/agents";
export * from "langchain/agents/toolkits";
export * from "langchain/agents/toolkits/connery";
export * from "langchain/agents/format_scratchpad";
export * from "langchain/agents/format_scratchpad/openai_tools";
export * from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ export * from "langchain/agents/xml/output_parser";
export * from "langchain/agents/openai/output_parser";
export * from "langchain/base_language";
export * from "langchain/tools";
export * from "langchain/tools/connery";
export * from "langchain/tools/render";
export * from "langchain/tools/google_places";
export * from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-cf/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "langchain/load";
export * from "langchain/load/serializable";
export * from "langchain/agents";
export * from "langchain/agents/toolkits";
export * from "langchain/agents/toolkits/connery";
export * from "langchain/agents/format_scratchpad";
export * from "langchain/agents/format_scratchpad/openai_tools";
export * from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ export * from "langchain/agents/xml/output_parser";
export * from "langchain/agents/openai/output_parser";
export * from "langchain/base_language";
export * from "langchain/tools";
export * from "langchain/tools/connery";
export * from "langchain/tools/render";
export * from "langchain/tools/google_places";
export * from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-cjs/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const load = require("langchain/load");
const load_serializable = require("langchain/load/serializable");
const agents = require("langchain/agents");
const agents_toolkits = require("langchain/agents/toolkits");
const agents_toolkits_connery = require("langchain/agents/toolkits/connery");
const agents_format_scratchpad = require("langchain/agents/format_scratchpad");
const agents_format_scratchpad_openai_tools = require("langchain/agents/format_scratchpad/openai_tools");
const agents_format_scratchpad_log = require("langchain/agents/format_scratchpad/log");
Expand All @@ -12,6 +13,7 @@ const agents_xml_output_parser = require("langchain/agents/xml/output_parser");
const agents_openai_output_parser = require("langchain/agents/openai/output_parser");
const base_language = require("langchain/base_language");
const tools = require("langchain/tools");
const tools_connery = require("langchain/tools/connery");
const tools_render = require("langchain/tools/render");
const tools_google_places = require("langchain/tools/google_places");
const chains = require("langchain/chains");
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-esbuild/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as load from "langchain/load";
import * as load_serializable from "langchain/load/serializable";
import * as agents from "langchain/agents";
import * as agents_toolkits from "langchain/agents/toolkits";
import * as agents_toolkits_connery from "langchain/agents/toolkits/connery";
import * as agents_format_scratchpad from "langchain/agents/format_scratchpad";
import * as agents_format_scratchpad_openai_tools from "langchain/agents/format_scratchpad/openai_tools";
import * as agents_format_scratchpad_log from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ import * as agents_xml_output_parser from "langchain/agents/xml/output_parser";
import * as agents_openai_output_parser from "langchain/agents/openai/output_parser";
import * as base_language from "langchain/base_language";
import * as tools from "langchain/tools";
import * as tools_connery from "langchain/tools/connery";
import * as tools_render from "langchain/tools/render";
import * as tools_google_places from "langchain/tools/google_places";
import * as chains from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-esm/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import * as load from "langchain/load";
import * as load_serializable from "langchain/load/serializable";
import * as agents from "langchain/agents";
import * as agents_toolkits from "langchain/agents/toolkits";
import * as agents_toolkits_connery from "langchain/agents/toolkits/connery";
import * as agents_format_scratchpad from "langchain/agents/format_scratchpad";
import * as agents_format_scratchpad_openai_tools from "langchain/agents/format_scratchpad/openai_tools";
import * as agents_format_scratchpad_log from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ import * as agents_xml_output_parser from "langchain/agents/xml/output_parser";
import * as agents_openai_output_parser from "langchain/agents/openai/output_parser";
import * as base_language from "langchain/base_language";
import * as tools from "langchain/tools";
import * as tools_connery from "langchain/tools/connery";
import * as tools_render from "langchain/tools/render";
import * as tools_google_places from "langchain/tools/google_places";
import * as chains from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-vercel/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "langchain/load";
export * from "langchain/load/serializable";
export * from "langchain/agents";
export * from "langchain/agents/toolkits";
export * from "langchain/agents/toolkits/connery";
export * from "langchain/agents/format_scratchpad";
export * from "langchain/agents/format_scratchpad/openai_tools";
export * from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ export * from "langchain/agents/xml/output_parser";
export * from "langchain/agents/openai/output_parser";
export * from "langchain/base_language";
export * from "langchain/tools";
export * from "langchain/tools/connery";
export * from "langchain/tools/render";
export * from "langchain/tools/google_places";
export * from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions environment_tests/test-exports-vite/src/entrypoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ export * from "langchain/load";
export * from "langchain/load/serializable";
export * from "langchain/agents";
export * from "langchain/agents/toolkits";
export * from "langchain/agents/toolkits/connery";
export * from "langchain/agents/format_scratchpad";
export * from "langchain/agents/format_scratchpad/openai_tools";
export * from "langchain/agents/format_scratchpad/log";
Expand All @@ -12,6 +13,7 @@ export * from "langchain/agents/xml/output_parser";
export * from "langchain/agents/openai/output_parser";
export * from "langchain/base_language";
export * from "langchain/tools";
export * from "langchain/tools/connery";
export * from "langchain/tools/render";
export * from "langchain/tools/google_places";
export * from "langchain/chains";
Expand Down
2 changes: 2 additions & 0 deletions examples/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME=ADD_YOURS_HERE # Azure Portal -> Co
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=ADD_YOURS_HERE # Azure Portal -> Cognitive Services -> OpenAI -> Choose your instance -> Go to Azure OpenAI Studio -> Deployments
AZURE_OPENAI_API_VERSION=ADD_YOURS_HERE # Azure Portal -> Cognitive Services -> OpenAI -> Choose your instance -> Go to Azure OpenAI Studio -> Completions/Chat -> Choose Deployment -> View Code
AZURE_OPENAI_BASE_PATH=ADD_YOURS_HERE # Azure Portal -> Cognitive Services -> OpenAI -> Choose your instance -> Endpoint (optional)
CONNERY_RUNNER_URL=ADD_YOURS_HERE
CONNERY_RUNNER_API_KEY=ADD_YOURS_HERE
ELASTIC_URL=ADD_YOURS_HERE # http://127.0.0.1:9200
ELASTIC_USERNAME="elastic"
ELASTIC_PASSWORD=ADD_YOURS_HERE # Password for the 'elastic' user (at least 6 characters)
Expand Down
58 changes: 58 additions & 0 deletions examples/src/agents/connery_mrkl.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import { OpenAI } from "langchain/llms/openai";
import { initializeAgentExecutorWithOptions } from "langchain/agents";
import { ConneryToolkit } from "langchain/agents/toolkits/connery";
import { ConneryService } from "langchain/tools/connery";

/**
* This example shows how to create an agent with Connery actions using the Connery Actions Toolkit.
*
* Connery is an open-source plugin infrastructure for AI.
* Source code: https://github.com/connery-io/connery-platform
*
* To run this example, you need to do some preparation:
* 1. Set up the Connery runner. See a quick start guide here: https://docs.connery.io/docs/platform/quick-start/
* 2. Intsall the "Summarization" plugin (https://github.com/connery-io/summarization-plugin) on the runner.
* 3. Install the "Gmail" plugin (https://github.com/connery-io/gmail) on the runner.
* 4. Set environment variables CONNERY_RUNNER_URL and CONNERY_RUNNER_API_KEY in the ./examples/.env file of this repository.
*
* If you want to use only one particular Connery action in your agent,
* check out an example here: ./examples/src/tools/connery.ts
*/

const model = new OpenAI({ temperature: 0 });
const conneryService = new ConneryService();
const conneryToolkit = await ConneryToolkit.createInstance(conneryService);

const executor = await initializeAgentExecutorWithOptions(
conneryToolkit.tools,
model,
{
agentType: "zero-shot-react-description",
verbose: true,
}
);

/**
* In this example we use two Connery actions:
* 1. "Summarize public webpage" from the "Summarization" plugin.
* 2. "Send email" from the "Gmail" plugin.
*/
const input =
"Make a short summary of the webpage http://www.paulgraham.com/vb.html in three sentences " +
"and send it to [email protected]. Include the link to the webpage into the body of the email.";
const result = await executor.invoke({ input });
console.log(result.output);

/**
* As a result, you should receive an email similar to this:
*
* Subject: Summary of "Life is Short"
* Body: Here is a summary of the webpage "Life is Short" by Paul Graham:
* The author reflects on the shortness of life and how having children has made them realize
* the limited time they have. They argue that life is too short for unnecessary things,
* or "bullshit," and that one should prioritize avoiding it.
* They also discuss the importance of actively seeking out things that matter and not waiting to do them.
* The author suggests pruning unnecessary things, savoring the time one has, and not waiting to do what truly matters.
* They also discuss the effect of how one lives on the length of their life and the importance of being conscious of time.
* Link to webpage: http://www.paulgraham.com/vb.html
*/
37 changes: 37 additions & 0 deletions examples/src/tools/connery.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { ConneryService } from "langchain/tools/connery";

/**
* This example shows how to create a tool for one specific Connery action and call it.
*
* Connery is an open-source plugin infrastructure for AI.
* Source code: https://github.com/connery-io/connery-platform
*
* To run this example, you need to do some preparation:
* 1. Set up the Connery runner. See a quick start guide here: https://docs.connery.io/docs/platform/quick-start/
* 2. Install the "Gmail" plugin (https://github.com/connery-io/gmail) on the runner.
* 3. Set environment variables CONNERY_RUNNER_URL and CONNERY_RUNNER_API_KEY in the ./examples/.env file of this repository.
*
* If you want to use several Connery actions in your agent, check out the Connery Toolkit.
* Example of using Connery Toolkit: ./examples/src/agents/connery_mrkl.ts
*/

const conneryService = new ConneryService();

/**
* The "getAction" method fetches the action from the Connery runner by ID,
* constructs a LangChain tool object from it, and returns it to the caller.
*
* In this example, we use the ID of the "Send email" action from the "Gmail" plugin.
* You can find action IDs in the Connery runner.
*/
const tool = await conneryService.getAction("CABC80BB79C15067CA983495324AE709");

/**
* The "call" method of the tool takes a plain English prompt
* with all the information needed to run the Connery action behind the scenes.
*/
const result = await tool.call(
"Send an email to [email protected] with the subject 'Test email' and the body 'This is a test email sent from Langchain Connery tool.'"
);

console.log(result);
2 changes: 2 additions & 0 deletions langchain/.env.example
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ AZURE_OPENAI_API_COMPLETIONS_DEPLOYMENT_NAME=ADD_YOURS_HERE
AZURE_OPENAI_API_EMBEDDINGS_DEPLOYMENT_NAME=ADD_YOURS_HERE
AZURE_OPENAI_API_VERSION=ADD_YOURS_HERE
AZURE_OPENAI_BASE_PATH=ADD_YOURS_HERE
CONNERY_RUNNER_URL=ADD_YOURS_HERE
CONNERY_RUNNER_API_KEY=ADD_YOURS_HERE
CONVEX_URL=ADD_YOURS_HERE
ELASTIC_URL=http://127.0.0.1:9200
OPENSEARCH_URL=http://127.0.0.1:9200
Expand Down
6 changes: 6 additions & 0 deletions langchain/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ agents/toolkits.d.ts
agents/toolkits/aws_sfn.cjs
agents/toolkits/aws_sfn.js
agents/toolkits/aws_sfn.d.ts
agents/toolkits/connery.cjs
agents/toolkits/connery.js
agents/toolkits/connery.d.ts
agents/toolkits/sql.cjs
agents/toolkits/sql.js
agents/toolkits/sql.d.ts
Expand Down Expand Up @@ -58,6 +61,9 @@ tools/aws_sfn.d.ts
tools/calculator.cjs
tools/calculator.js
tools/calculator.d.ts
tools/connery.cjs
tools/connery.js
tools/connery.d.ts
tools/render.cjs
tools/render.js
tools/render.d.ts
Expand Down
16 changes: 16 additions & 0 deletions langchain/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@
"agents/toolkits/aws_sfn.cjs",
"agents/toolkits/aws_sfn.js",
"agents/toolkits/aws_sfn.d.ts",
"agents/toolkits/connery.cjs",
"agents/toolkits/connery.js",
"agents/toolkits/connery.d.ts",
"agents/toolkits/sql.cjs",
"agents/toolkits/sql.js",
"agents/toolkits/sql.d.ts",
Expand Down Expand Up @@ -70,6 +73,9 @@
"tools/calculator.cjs",
"tools/calculator.js",
"tools/calculator.d.ts",
"tools/connery.cjs",
"tools/connery.js",
"tools/connery.d.ts",
"tools/render.cjs",
"tools/render.js",
"tools/render.d.ts",
Expand Down Expand Up @@ -1492,6 +1498,11 @@
"import": "./agents/toolkits/aws_sfn.js",
"require": "./agents/toolkits/aws_sfn.cjs"
},
"./agents/toolkits/connery": {
"types": "./agents/toolkits/connery.d.ts",
"import": "./agents/toolkits/connery.js",
"require": "./agents/toolkits/connery.cjs"
},
"./agents/toolkits/sql": {
"types": "./agents/toolkits/sql.d.ts",
"import": "./agents/toolkits/sql.js",
Expand Down Expand Up @@ -1562,6 +1573,11 @@
"import": "./tools/calculator.js",
"require": "./tools/calculator.cjs"
},
"./tools/connery": {
"types": "./tools/connery.d.ts",
"import": "./tools/connery.js",
"require": "./tools/connery.cjs"
},
"./tools/render": {
"types": "./tools/render.d.ts",
"import": "./tools/render.js",
Expand Down
Loading

1 comment on commit 2c324c4

@vercel
Copy link

@vercel vercel bot commented on 2c324c4 Dec 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

langchainjs-docs – ./docs/core_docs/

langchainjs-docs-langchain.vercel.app
langchainjs-docs-ruddy.vercel.app
js.langchain.com
langchainjs-docs-git-main-langchain.vercel.app

Please sign in to comment.