-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Connery Tool and Toolkit #3499
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0eb78e3
Add ConneryApiClient class
machulav 4bba1b5
Intermediate sate
machulav a343afc
Fix ConneryToolkit typo and update ConneryService
machulav 23132f4
Merge branch 'main' into connery-tool
machulav 35aab7a
Init docs
machulav d8672c5
Merge branch 'connery-tool' of github.com:connery-io/langchainjs into…
machulav 47ecd9c
Update docs
machulav 976e5fd
Fix imports in docs
machulav de85697
Merge branch 'main' into connery-tool
machulav 5241652
Create entry points for the tool and toolkit
machulav 6faa978
Merge branch 'main' into connery-tool
machulav ef639dd
Fix the docs issue
machulav ebdac21
Merge branch 'main' into connery-tool
machulav File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Not blocking for this but the OpenAI Functions agent probably has the best performance right now
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.
Good point! I will add another example later.