mirror of
https://github.com/hwchase17/langchain.git
synced 2026-04-02 18:32:56 +00:00
Use docusaurus versioning with a callout, merged master as well @hwchase17 @baskaryan --------- Signed-off-by: Weichen Xu <weichen.xu@databricks.com> Signed-off-by: Rahul Tripathi <rauhl.psit.ec@gmail.com> Co-authored-by: Leonid Ganeline <leo.gan.57@gmail.com> Co-authored-by: Leonid Kuligin <lkuligin@yandex.ru> Co-authored-by: Averi Kitsch <akitsch@google.com> Co-authored-by: Erick Friis <erick@langchain.dev> Co-authored-by: Nuno Campos <nuno@langchain.dev> Co-authored-by: Nuno Campos <nuno@boringbits.io> Co-authored-by: Bagatur <22008038+baskaryan@users.noreply.github.com> Co-authored-by: Eugene Yurtsev <eyurtsev@gmail.com> Co-authored-by: Martín Gotelli Ferenaz <martingotelliferenaz@gmail.com> Co-authored-by: Fayfox <admin@fayfox.com> Co-authored-by: Eugene Yurtsev <eugene@langchain.dev> Co-authored-by: Dawson Bauer <105886620+djbauer2@users.noreply.github.com> Co-authored-by: Ravindu Somawansa <ravindu.somawansa@gmail.com> Co-authored-by: Dhruv Chawla <43818888+Dominastorm@users.noreply.github.com> Co-authored-by: ccurme <chester.curme@gmail.com> Co-authored-by: Bagatur <baskaryan@gmail.com> Co-authored-by: WeichenXu <weichen.xu@databricks.com> Co-authored-by: Benito Geordie <89472452+benitoThree@users.noreply.github.com> Co-authored-by: kartikTAI <129414343+kartikTAI@users.noreply.github.com> Co-authored-by: Kartik Sarangmath <kartik@thirdai.com> Co-authored-by: Sevin F. Varoglu <sfvaroglu@octoml.ai> Co-authored-by: MacanPN <martin.triska@gmail.com> Co-authored-by: Prashanth Rao <35005448+prrao87@users.noreply.github.com> Co-authored-by: Hyeongchan Kim <kozistr@gmail.com> Co-authored-by: sdan <git@sdan.io> Co-authored-by: Guangdong Liu <liugddx@gmail.com> Co-authored-by: Rahul Triptahi <rahul.psit.ec@gmail.com> Co-authored-by: Rahul Tripathi <rauhl.psit.ec@gmail.com> Co-authored-by: pjb157 <84070455+pjb157@users.noreply.github.com> Co-authored-by: Eun Hye Kim <ehkim1440@gmail.com> Co-authored-by: kaijietti <43436010+kaijietti@users.noreply.github.com> Co-authored-by: Pengcheng Liu <pcliu.fd@gmail.com> Co-authored-by: Tomer Cagan <tomer@tomercagan.com> Co-authored-by: Christophe Bornet <cbornet@hotmail.com>
166 lines
5.7 KiB
Plaintext
166 lines
5.7 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"# Connery Action Tool\n",
|
|
"\n",
|
|
"Using this tool, you can integrate individual Connery Action into your LangChain agent.\n",
|
|
"\n",
|
|
"If you want to use more than one Connery Action in your agent,\n",
|
|
"check out the [Connery Toolkit](/docs/integrations/toolkits/connery) documentation.\n",
|
|
"\n",
|
|
"## What is Connery?\n",
|
|
"\n",
|
|
"Connery is an open-source plugin infrastructure for AI.\n",
|
|
"\n",
|
|
"With Connery, you can easily create a custom plugin with a set of actions and seamlessly integrate them into your LangChain agent.\n",
|
|
"Connery will take care of critical aspects such as runtime, authorization, secret management, access management, audit logs, and other vital features.\n",
|
|
"\n",
|
|
"Furthermore, Connery, supported by our community, provides a diverse collection of ready-to-use open-source plugins for added convenience.\n",
|
|
"\n",
|
|
"Learn more about Connery:\n",
|
|
"\n",
|
|
"- GitHub: https://github.com/connery-io/connery\n",
|
|
"- Documentation: https://docs.connery.io\n",
|
|
"\n",
|
|
"## Prerequisites\n",
|
|
"\n",
|
|
"To use Connery Actions in your LangChain agent, you need to do some preparation:\n",
|
|
"\n",
|
|
"1. Set up the Connery runner using the [Quickstart](https://docs.connery.io/docs/runner/quick-start/) guide.\n",
|
|
"2. Install all the plugins with the actions you want to use in your agent.\n",
|
|
"3. Set environment variables `CONNERY_RUNNER_URL` and `CONNERY_RUNNER_API_KEY` so the toolkit can communicate with the Connery Runner.\n",
|
|
"\n",
|
|
"## Example of using Connery Action Tool\n",
|
|
"\n",
|
|
"In the example below, we fetch action by its ID from the Connery Runner and then call it with the specified parameters.\n",
|
|
"\n",
|
|
"Here, we use the ID of the **Send email** action from the [Gmail](https://github.com/connery-io/gmail) plugin."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 11,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"import os\n",
|
|
"\n",
|
|
"from langchain.agents import AgentType, initialize_agent\n",
|
|
"from langchain_community.tools.connery import ConneryService\n",
|
|
"from langchain_openai import ChatOpenAI\n",
|
|
"\n",
|
|
"# Specify your Connery Runner credentials.\n",
|
|
"os.environ[\"CONNERY_RUNNER_URL\"] = \"\"\n",
|
|
"os.environ[\"CONNERY_RUNNER_API_KEY\"] = \"\"\n",
|
|
"\n",
|
|
"# Specify OpenAI API key.\n",
|
|
"os.environ[\"OPENAI_API_KEY\"] = \"\"\n",
|
|
"\n",
|
|
"# Specify your email address to receive the emails from examples below.\n",
|
|
"recepient_email = \"test@example.com\"\n",
|
|
"\n",
|
|
"# Get the SendEmail action from the Connery Runner by ID.\n",
|
|
"connery_service = ConneryService()\n",
|
|
"send_email_action = connery_service.get_action(\"CABC80BB79C15067CA983495324AE709\")"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Run the action manually."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": [
|
|
"manual_run_result = send_email_action.run(\n",
|
|
" {\n",
|
|
" \"recipient\": recepient_email,\n",
|
|
" \"subject\": \"Test email\",\n",
|
|
" \"body\": \"This is a test email sent from Connery.\",\n",
|
|
" }\n",
|
|
")\n",
|
|
"print(manual_run_result)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"Run the action using the OpenAI Functions agent.\n",
|
|
"\n",
|
|
"You can see a LangSmith trace of this example [here](https://smith.langchain.com/public/a37d216f-c121-46da-a428-0e09dc19b1dc/r)."
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 15,
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"name": "stdout",
|
|
"output_type": "stream",
|
|
"text": [
|
|
"\n",
|
|
"\n",
|
|
"\u001b[1m> Entering new AgentExecutor chain...\u001b[0m\n",
|
|
"\u001b[32;1m\u001b[1;3m\n",
|
|
"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]'}`\n",
|
|
"\n",
|
|
"\n",
|
|
"\u001b[0m\u001b[36;1m\u001b[1;3m{'messageId': '<d34a694d-50e0-3988-25da-e86b4c51d7a7@gmail.com>'}\u001b[0m\u001b[32;1m\u001b[1;3mI have sent an email to test@example.com informing them that you will be late for the meeting.\u001b[0m\n",
|
|
"\n",
|
|
"\u001b[1m> Finished chain.\u001b[0m\n",
|
|
"I have sent an email to test@example.com informing them that you will be late for the meeting.\n"
|
|
]
|
|
}
|
|
],
|
|
"source": [
|
|
"llm = ChatOpenAI(temperature=0)\n",
|
|
"agent = initialize_agent(\n",
|
|
" [send_email_action], llm, AgentType.OPENAI_FUNCTIONS, verbose=True\n",
|
|
")\n",
|
|
"agent_run_result = agent.run(\n",
|
|
" f\"Send an email to the {recepient_email} and say that I will be late for the meeting.\"\n",
|
|
")\n",
|
|
"print(agent_run_result)"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "markdown",
|
|
"metadata": {},
|
|
"source": [
|
|
"NOTE: Connery Action is a structured tool, so you can only use it in the agents supporting structured tools."
|
|
]
|
|
}
|
|
],
|
|
"metadata": {
|
|
"kernelspec": {
|
|
"display_name": "Python 3",
|
|
"language": "python",
|
|
"name": "python3"
|
|
},
|
|
"language_info": {
|
|
"codemirror_mode": {
|
|
"name": "ipython",
|
|
"version": 3
|
|
},
|
|
"file_extension": ".py",
|
|
"mimetype": "text/x-python",
|
|
"name": "python",
|
|
"nbconvert_exporter": "python",
|
|
"pygments_lexer": "ipython3",
|
|
"version": "3.10.13"
|
|
}
|
|
},
|
|
"nbformat": 4,
|
|
"nbformat_minor": 2
|
|
}
|