Skip to content

Commit

Permalink
feat: replace composio.mdx docs with composio.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
abhishekpatil4 committed Jan 16, 2025
1 parent 9b261db commit 480fc6e
Show file tree
Hide file tree
Showing 2 changed files with 313 additions and 100 deletions.
313 changes: 313 additions & 0 deletions docs/docs/integrations/providers/composio.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,313 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "19062701",
"metadata": {},
"source": [
"# Composio\n",
"\n",
"> [Composio](https://composio.dev) is an integration platform that provides 250+ production-ready tools for AI agents with flexible authentication management."
]
},
{
"cell_type": "markdown",
"id": "1435b193",
"metadata": {},
"source": [
"## Installation and Usage"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "8d86323b",
"metadata": {
"vscode": {
"languageId": "shellscript"
}
},
"outputs": [],
"source": [
"%pip install composio-langchain langchain-openai"
]
},
{
"cell_type": "markdown",
"id": "0c67340b",
"metadata": {},
"source": [
"After the installation is complete, either run `composio login` or export your Composio API key as `COMPOSIO_API_KEY`. Get your Composio API key from [here](https://app.composio.dev)"
]
},
{
"cell_type": "markdown",
"id": "6e6acf0e",
"metadata": {},
"source": [
"## Example"
]
},
{
"cell_type": "markdown",
"id": "21258ea5",
"metadata": {},
"source": [
"In this example, we will use Composio's **GitHub** tool to star a repository on GitHub."
]
},
{
"cell_type": "markdown",
"id": "d34e7622",
"metadata": {},
"source": [
"### 1. Initialize Composio toolset & LLM"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3d2dfc9f",
"metadata": {},
"outputs": [],
"source": [
"from composio_langchain import Action, App, ComposioToolSet\n",
"from langchain import hub\n",
"from langchain.agents import AgentExecutor\n",
"from langchain.agents.openai_functions_agent.base import create_openai_functions_agent\n",
"from langchain_openai import ChatOpenAI\n",
"\n",
"toolset = ComposioToolSet()\n",
"llm = ChatOpenAI()"
]
},
{
"cell_type": "markdown",
"id": "320e02fc",
"metadata": {},
"source": [
"### 2. Connect your GitHub account"
]
},
{
"cell_type": "markdown",
"id": "540e33f6",
"metadata": {},
"source": [
"Using the CLI:"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "89f58167",
"metadata": {
"vscode": {
"languageId": "shellscript"
}
},
"outputs": [],
"source": [
"%composio add github"
]
},
{
"cell_type": "markdown",
"id": "198bb058",
"metadata": {},
"source": [
"Using the Python SDK:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "090504ff",
"metadata": {},
"outputs": [],
"source": [
"request = toolset.initiate_connection(app=App.GITHUB)\n",
"print(f\"Open this URL to authenticate: {request.redirectUrl}\")"
]
},
{
"cell_type": "markdown",
"id": "16901682",
"metadata": {},
"source": [
"### 3. Get Tools"
]
},
{
"cell_type": "markdown",
"id": "311f6647",
"metadata": {},
"source": [
"- Retrieving all the tools from an app (not recommended for production):"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0fa286d1",
"metadata": {},
"outputs": [],
"source": [
"tools = toolset.get_tools(apps=[App.GITHUB])"
]
},
{
"cell_type": "markdown",
"id": "7fcb3e09",
"metadata": {},
"source": [
"- Filtering tools based on **tags**:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "58b287f3",
"metadata": {},
"outputs": [],
"source": [
"tag = \"users\"\n",
"\n",
"filtered_action_enums = toolset.find_actions_by_tags(\n",
" App.GITHUB,\n",
" tags=[tag],\n",
")\n",
"\n",
"tools = toolset.get_tools(actions=filtered_action_enums)"
]
},
{
"cell_type": "markdown",
"id": "2cebb14a",
"metadata": {},
"source": [
"- Filtering tools based on **use case**:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8e849857",
"metadata": {},
"outputs": [],
"source": [
"use_case = \"Star a repository on GitHub\"\n",
"\n",
"filtered_action_enums = toolset.find_actions_by_use_case(\n",
" App.GITHUB, use_case=use_case, advanced=False\n",
")\n",
"\n",
"tools = toolset.get_tools(actions=filtered_action_enums)"
]
},
{
"cell_type": "markdown",
"id": "79b9d304",
"metadata": {},
"source": [
"Set `advanced` to True to get actions for complex use cases"
]
},
{
"cell_type": "markdown",
"id": "31c35669",
"metadata": {},
"source": [
"- Using specific tools, In this demo, we will use the `GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER` action from the GitHub app:"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e08d8461",
"metadata": {},
"outputs": [],
"source": [
"tools = toolset.get_tools(\n",
" actions=[Action.GITHUB_STAR_A_REPOSITORY_FOR_THE_AUTHENTICATED_USER]\n",
")"
]
},
{
"cell_type": "markdown",
"id": "02852ede",
"metadata": {},
"source": [
"Learn more about filtering actions [here](https://docs.composio.dev/patterns/tools/use-tools/use-specific-actions)"
]
},
{
"cell_type": "markdown",
"id": "ccc1392b",
"metadata": {},
"source": [
"### 4. Define agent"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5dcd53df",
"metadata": {},
"outputs": [],
"source": [
"prompt = hub.pull(\"hwchase17/openai-functions-agent\")\n",
"agent = create_openai_functions_agent(llm, tools, prompt)\n",
"agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)"
]
},
{
"cell_type": "markdown",
"id": "b9ea4b85",
"metadata": {},
"source": [
"### 5. Execute task"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "2295339b",
"metadata": {},
"outputs": [],
"source": [
"task = \"Star a repo composiohq/composio on GitHub\"\n",
"agent_executor.invoke({\"input\": task})"
]
},
{
"cell_type": "markdown",
"id": "623278ac",
"metadata": {},
"source": [
"More detailed list of tools can be found [here](https://app.composio.dev)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "langchain_repo",
"language": "python",
"name": "langchain_repo"
},
"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.9.17"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Loading

0 comments on commit 480fc6e

Please sign in to comment.