-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add Connery Tool and Toolkit (#3499)
* 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
Showing
20 changed files
with
588 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
*/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
2c324c4
There was a problem hiding this comment.
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