-
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
Changes from 7 commits
0eb78e3
4bba1b5
a343afc
23132f4
35aab7a
d8672c5
47ecd9c
976e5fd
de85697
5241652
6faa978
ef639dd
ebdac21
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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_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> |
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.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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { | ||
ConneryToolkit, | ||
initializeAgentExecutorWithOptions, | ||
} from "langchain/agents"; | ||
import { OpenAI } from "langchain/llms/openai"; | ||
import { ConneryService } from "langchain/tools"; | ||
|
||
/** | ||
* 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ConneryService } from "langchain/tools"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hey team, just a heads up that I've flagged a change in the PR for review. The added code is accessing environment variables via |
||
|
||
/** | ||
* 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); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { Tool } from "@langchain/core/tools"; | ||
import { Toolkit } from "../base.js"; | ||
import { ConneryService } from "../../../tools/connery.js"; | ||
|
||
/** | ||
* A toolkit for working with Connery actions. | ||
* | ||
* Connery is an open-source plugin infrastructure for AI. | ||
* Source code: https://github.com/connery-io/connery-platform | ||
* | ||
* See an example of using this toolkit here: `./examples/src/agents/connery_mrkl.ts` | ||
* @extends Toolkit | ||
*/ | ||
export class ConneryToolkit extends Toolkit { | ||
tools: Tool[]; | ||
|
||
/** | ||
* Creates a ConneryToolkit instance based on the provided ConneryService instance. | ||
* It populates the tools property of the ConneryToolkit instance with the list of | ||
* available tools from the ConneryService instance. | ||
* @param conneryService The ConneryService instance. | ||
* @returns A Promise that resolves to a ConneryToolkit instance. | ||
*/ | ||
static async createInstance( | ||
conneryService: ConneryService | ||
): Promise<ConneryToolkit> { | ||
const toolkit = new ConneryToolkit(); | ||
toolkit.tools = []; | ||
|
||
const actions = await conneryService.listActions(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Neat! |
||
toolkit.tools.push(...actions); | ||
|
||
return toolkit; | ||
} | ||
} |
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.