Skip to main content

Connery Toolkit and Tools

Using the Connery toolkit and tools, you can integrate Connery Actions into your LangChain agent.

What is Connery?โ€‹

Connery is an open-source plugin infrastructure for AI.

With Connery, you can easily create a custom plugin with a set of actions and seamlessly integrate them into your LangChain agent. Connery will take care of critical aspects such as runtime, authorization, secret management, access management, audit logs, and other vital features.

Furthermore, Connery, supported by our community, provides a diverse collection of ready-to-use open-source plugins for added convenience.

Learn more about Connery:

Setupโ€‹

Installationโ€‹

You need to install the langchain_community package to use the Connery tools.

%pip install -qU langchain-community

Credentialsโ€‹

To use Connery Actions in your LangChain agent, you need to do some preparation:

  1. Set up the Connery runner using the Quickstart guide.
  2. Install all the plugins with the actions you want to use in your agent.
  3. Set environment variables CONNERY_RUNNER_URL and CONNERY_RUNNER_API_KEY so the toolkit can communicate with the Connery Runner.
import getpass
import os

for key in ["CONNERY_RUNNER_URL", "CONNERY_RUNNER_API_KEY"]:
if key not in os.environ:
os.environ[key] = getpass.getpass(f"Please enter the value for {key}: ")

Toolkitโ€‹

In the example below, we create an agent that uses two Connery Actions to summarize a public webpage and send the summary by email:

  1. Summarize public webpage action from the Summarization plugin.
  2. Send email action from the Gmail plugin.

You can see a LangSmith trace of this example here.

import os

from langchain.agents import AgentType, initialize_agent
from langchain_community.agent_toolkits.connery import ConneryToolkit
from langchain_community.tools.connery import ConneryService
from langchain_openai import ChatOpenAI

# Specify your Connery Runner credentials.
os.environ["CONNERY_RUNNER_URL"] = ""
os.environ["CONNERY_RUNNER_API_KEY"] = ""

# Specify OpenAI API key.
os.environ["OPENAI_API_KEY"] = ""

# Specify your email address to receive the email with the summary from example below.
recepient_email = "test@example.com"

# Create a Connery Toolkit with all the available actions from the Connery Runner.
connery_service = ConneryService()
connery_toolkit = ConneryToolkit.create_instance(connery_service)

# Use OpenAI Functions agent to execute the prompt using actions from the Connery Toolkit.
llm = ChatOpenAI(temperature=0)
agent = initialize_agent(
connery_toolkit.get_tools(), llm, AgentType.OPENAI_FUNCTIONS, verbose=True
)
result = agent.run(
f"""Make a short summary of the webpage http://www.paulgraham.com/vb.html in three sentences
and send it to {recepient_email}. Include the link to the webpage into the body of the email."""
)
print(result)


> Entering new AgentExecutor chain...

Invoking: `CA72DFB0AB4DF6C830B43E14B0782F70` with `{'publicWebpageUrl': 'http://www.paulgraham.com/vb.html'}`


{'summary': 'The author reflects on the concept of life being short and how having children made them realize the true brevity of life. They discuss how time can be converted into discrete quantities and how limited certain experiences are. The author emphasizes the importance of prioritizing and eliminating unnecessary things in life, as well as actively pursuing meaningful experiences. They also discuss the negative impact of getting caught up in online arguments and the need to be aware of how time is being spent. The author suggests pruning unnecessary activities, not waiting to do things that matter, and savoring the time one has.'}
Invoking: `CABC80BB79C15067CA983495324AE709` with `{'recipient': 'test@example.com', 'subject': 'Summary of the webpage', 'body': 'Here is a short summary of the webpage http://www.paulgraham.com/vb.html:\n\nThe author reflects on the concept of life being short and how having children made them realize the true brevity of life. They discuss how time can be converted into discrete quantities and how limited certain experiences are. The author emphasizes the importance of prioritizing and eliminating unnecessary things in life, as well as actively pursuing meaningful experiences. They also discuss the negative impact of getting caught up in online arguments and the need to be aware of how time is being spent. The author suggests pruning unnecessary activities, not waiting to do things that matter, and savoring the time one has.\n\nYou can find the full webpage [here](http://www.paulgraham.com/vb.html).'}`


{'messageId': '<2f04b00e-122d-c7de-c91e-e78e0c3276d6@gmail.com>'}I have sent the email with the summary of the webpage to test@example.com. Please check your inbox.

> Finished chain.
I have sent the email with the summary of the webpage to test@example.com. Please check your inbox.

NOTE: Connery Action is a structured tool, so you can only use it in the agents supporting structured tools.

Toolโ€‹

import os

from langchain.agents import AgentType, initialize_agent
from langchain_community.tools.connery import ConneryService
from langchain_openai import ChatOpenAI

# Specify your Connery Runner credentials.
os.environ["CONNERY_RUNNER_URL"] = ""
os.environ["CONNERY_RUNNER_API_KEY"] = ""

# Specify OpenAI API key.
os.environ["OPENAI_API_KEY"] = ""

# Specify your email address to receive the emails from examples below.
recepient_email = "test@example.com"

# Get the SendEmail action from the Connery Runner by ID.
connery_service = ConneryService()
send_email_action = connery_service.get_action("CABC80BB79C15067CA983495324AE709")

Run the action manually.

manual_run_result = send_email_action.run(
{
"recipient": recepient_email,
"subject": "Test email",
"body": "This is a test email sent from Connery.",
}
)
print(manual_run_result)

Run the action using the OpenAI Functions agent.

You can see a LangSmith trace of this example here.

llm = ChatOpenAI(temperature=0)
agent = initialize_agent(
[send_email_action], llm, AgentType.OPENAI_FUNCTIONS, verbose=True
)
agent_run_result = agent.run(
f"Send an email to the {recepient_email} and say that I will be late for the meeting."
)
print(agent_run_result)


> Entering new AgentExecutor chain...

Invoking: `CABC80BB79C15067CA983495324AE709` with `{'recipient': 'test@example.com', 'subject': 'Late for Meeting', 'body': 'Dear Team,\n\nI wanted to inform you that I will be late for the meeting today. I apologize for any inconvenience caused. Please proceed with the meeting without me and I will join as soon as I can.\n\nBest regards,\n[Your Name]'}`


{'messageId': '<d34a694d-50e0-3988-25da-e86b4c51d7a7@gmail.com>'}I have sent an email to test@example.com informing them that you will be late for the meeting.

> Finished chain.
I have sent an email to test@example.com informing them that you will be late for the meeting.

NOTE: Connery Action is a structured tool, so you can only use it in the agents supporting structured tools.

API referenceโ€‹

For detailed documentation of all Connery features and configurations head to the API reference:


Was this page helpful?