> ## Documentation Index
> Fetch the complete documentation index at: https://langchain-5e9cc07a-preview-docsdy-1782337909-2539eb6.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Composio integration

> Access 500+ tools and integrations through Composio's unified API platform for AI agents, with OAuth handling, event-driven workflows, and multi-user support.

[Composio](https://composio.dev) is an integration platform that provides access to 500+ tools across popular applications like GitHub, Slack, Notion, and more. It enables AI agents to interact with external services through a unified API, handling authentication, permissions, and event-driven workflows.

## Overview

### Integration details

| Class    | Package                                                              | Serializable | [JS support](https://js.langchain.com/docs/integrations/tools/composio) |                                              Version                                             |
| :------- | :------------------------------------------------------------------- | :----------: | :---------------------------------------------------------------------: | :----------------------------------------------------------------------------------------------: |
| Composio | [`composio-langchain`](https://pypi.org/project/composio-langchain/) |       ❌      |                                    ✅                                    | ![PyPI - Version](https://img.shields.io/pypi/v/composio-langchain?style=flat-square\&label=%20) |

### Tool features

* **500+ Tool Access**: Prebuilt integrations for GitHub, Slack, Gmail, Jira, Notion, and more
* **Authentication Management**: Handles OAuth flows, API keys, and authentication state
* **Event-Driven Workflows**: Trigger agents based on external events (new Slack messages, GitHub issues, etc.)
* **Fine-Grained Permissions**: Control tool access and data exposure per user
* **Custom Tool Support**: Add proprietary APIs and internal tools

## Setup

The integration lives in the `composio-langchain` package.

<CodeGroup>
  ```python pip theme={null}
  pip install -U composio-langchain
  ```

  ```python uv theme={null}
  uv add composio-langchain
  ```
</CodeGroup>

### Credentials

You'll need a Composio API key. Sign up for free at [composio.dev](https://composio.dev) to get your API key.

```python Set API key icon="key" theme={null}
import getpass
import os

if not os.environ.get("COMPOSIO_API_KEY"):
    os.environ["COMPOSIO_API_KEY"] = getpass.getpass("Enter your Composio API key: ")
```

It's also helpful to set up [LangSmith](/langsmith/observability) for tracing:

```python Enable tracing icon="flask" theme={null}
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("Enter your LangSmith API key: ")
# os.environ["LANGSMITH_TRACING"] = "true"
```

## Instantiation

Initialize Composio with the LangChain provider and get tools from specific toolkits. Each toolkit represents a service (e.g., GitHub, Slack) with multiple tools (actions you can perform).

```python Initialize Composio icon="robot" theme={null}
from composio import Composio
from composio_langchain import LangchainProvider

# Initialize Composio with LangChain provider
composio = Composio(provider=LangchainProvider())

# Get tools from specific toolkits
# You can specify one or more toolkits
tools = composio.tools.get(
    user_id="default",
    toolkits=["GITHUB"]
)

print(f"Loaded {len(tools)} tools from GitHub toolkit")
```

### Available toolkits

Composio provides toolkits for various services:

**Productivity**: GitHub, Slack, Gmail, Jira, Notion, Asana, Trello, ClickUp
**Communication**: Discord, Telegram, WhatsApp, Microsoft Teams
**Development**: GitLab, Bitbucket, Linear, Sentry
**Data & Analytics**: Google Sheets, Airtable, HubSpot, Salesforce
**And 100+ more...**

## Invocation

### Get tools from multiple toolkits

You can load tools from multiple services at once:

```python theme={null}
# Get tools from multiple toolkits
tools = composio.tools.get(
    user_id="default",
    toolkits=["GITHUB", "SLACK", "GMAIL"]
)
```

### Get specific tools

Instead of entire toolkits, you can load specific tools:

```python theme={null}
# Get specific tools by name
tools = composio.tools.get(
    user_id="default",
    tools=["GITHUB_CREATE_ISSUE", "SLACK_SEND_MESSAGE"]
)
```

### User-specific tools

Composio supports multi-user scenarios with user-specific authentication:

```python theme={null}
# Get tools for a specific user
# This user must have authenticated their accounts first
tools = composio.tools.get(
    user_id="user_123",
    toolkits=["GITHUB"]
)
```

## Use within an agent

Here's a complete example using Composio tools with a LangChain agent to interact with GitHub:

<ChatModelTabs customVarName="llm" />

```python theme={null}
import os
import getpass

if not os.environ.get("OPENAI_API_KEY"):
    os.environ["OPENAI_API_KEY"] = getpass.getpass("Enter your OpenAI API key: ")
```

```python theme={null}
# | output: false
# | echo: false

from langchain.chat_models import init_chat_model

llm = init_chat_model(model="gpt-5.5", model_provider="openai")
```

```python Agent with Composio tools icon="robot" theme={null}
from composio import Composio
from composio_langchain import LangchainProvider
from langchain import hub
from langchain.agents import AgentExecutor, create_openai_functions_agent

# Pull the prompt template
prompt = hub.pull("hwchase17/openai-functions-agent")

# Initialize Composio
composio = Composio(provider=LangchainProvider())

# Get GitHub tools
tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])

# Define task
task = "Star a repo composiohq/composio on GitHub"

# Create agent
agent = create_openai_functions_agent(llm, tools, prompt)
agent_executor = AgentExecutor(agent=agent, tools=tools, verbose=True)

# Execute using agent_executor
agent_executor.invoke({"input": task})
```

### Event-driven workflows

Composio supports triggering agents based on external events. When events occur in connected apps (like new GitHub commits or Slack messages), triggers automatically send structured payloads to your application.

#### Creating a trigger

First, create a trigger for the events you want to monitor:

```python theme={null}
from composio import Composio

composio = Composio(api_key="your_api_key")
user_id = "user_123"

# Check what configuration is required for the trigger
trigger_type = composio.triggers.get_type("GITHUB_COMMIT_EVENT")
print(trigger_type.config)

# Create trigger with required configuration
trigger = composio.triggers.create(
    slug="GITHUB_COMMIT_EVENT",
    user_id=user_id,
    trigger_config={
        "owner": "composiohq",
        "repo": "composio"
    }
)

print(f"Trigger created: {trigger.trigger_id}")
```

#### Subscribing to triggers (Development)

For local development and prototyping, you can subscribe directly to triggers:

```python theme={null}
from composio import Composio

composio = Composio(api_key="your_api_key")

# Subscribe to trigger events
subscription = composio.triggers.subscribe()

# Define event handler
@subscription.handle(trigger_id="your_trigger_id")
def handle_github_commit(data):
    print(f"New commit detected: {data}")
    # Process the event with your agent
    # ... invoke your agent with the task

# Note: For production, use webhooks instead
```

#### Webhooks (Production)

For production, configure webhooks in the [Composio dashboard](https://platform.composio.dev/settings/events):

```python theme={null}
from fastapi import FastAPI, Request
import json

app = FastAPI()

@app.post("/webhook")
async def webhook_handler(request: Request):
    # Get the webhook payload
    payload = await request.json()

    print("Received trigger event:")
    print(json.dumps(payload, indent=2))

    # Process the event with your agent
    if payload.get("triggerSlug") == "GITHUB_COMMIT_EVENT":
        commit_data = payload.get("payload")
        # ... invoke your agent with commit_data

    return {"status": "success"}
```

For more details, see the [Composio Triggers documentation](https://docs.composio.dev/docs/using-triggers)

## Authentication setup

Before using tools that require authentication, users need to connect their accounts:

```python theme={null}
from composio import Composio

composio = Composio()

# Get authentication URL for a user
auth_connection = composio.integrations.create(
    user_id="user_123",
    integration="github"
)

print(f"Authenticate at: {auth_connection.redirect_url}")

# After authentication, the user's connected account will be available
# and tools will work with their credentials
```

## Multi-user scenarios

For applications with multiple users:

```python theme={null}
# Each user authenticates their own accounts
tools_user_1 = composio.tools.get(user_id="user_1", toolkits=["GITHUB"])
tools_user_2 = composio.tools.get(user_id="user_2", toolkits=["GITHUB"])

# Tools will use the respective user's credentials
# User 1's agent will act on User 1's GitHub account
agent_1 = create_agent(llm, tools_user_1)

# User 2's agent will act on User 2's GitHub account
agent_2 = create_agent(llm, tools_user_2)
```

## Advanced features

### Custom tools

Composio allows you to create custom tools that can be used alongside built-in tools. There are two types:

#### Standalone tools

Simple tools that don't require authentication:

```python theme={null}
from pydantic import BaseModel, Field
from composio import Composio

composio = Composio()

class AddTwoNumbersInput(BaseModel):
    a: int = Field(description="The first number to add")
    b: int = Field(description="The second number to add")

# Function name will be used as the tool slug
@composio.tools.custom_tool
def add_two_numbers(request: AddTwoNumbersInput) -> int:
    """Add two numbers."""
    return request.a + request.b

# Use with your agent
tools = composio.tools.get(user_id="default", toolkits=["GITHUB"])
tools.append(add_two_numbers)
```

#### Toolkit-based tools

Tools that require authentication and can use toolkit credentials:

```python theme={null}
from composio.types import ExecuteRequestFn

class GetIssueInfoInput(BaseModel):
    issue_number: int = Field(
        ..., description="The number of the issue to get information about"
    )

@composio.tools.custom_tool(toolkit="github")
def get_issue_info(
    request: GetIssueInfoInput,
    execute_request: ExecuteRequestFn,
    auth_credentials: dict,
) -> dict:
    """Get information about a GitHub issue."""
    response = execute_request(
        endpoint=f"/repos/composiohq/composio/issues/{request.issue_number}",
        method="GET",
        parameters=[
            {
                "name": "Accept",
                "value": "application/vnd.github.v3+json",
                "type": "header",
            },
            {
                "name": "Authorization",
                "value": f"Bearer {auth_credentials['access_token']}",
                "type": "header",
            },
        ],
    )
    return {"data": response.data}
```

Execute custom tools:

```python theme={null}
response = composio.tools.execute(
    user_id="default",
    slug="get_issue_info",  # Use function name as slug
    arguments={"issue_number": 1},
)
```

For more details, see the [Composio Custom Tools documentation](https://docs.composio.dev/docs/custom-tools)

### Fine-grained permissions

Control what actions tools can perform:

```python theme={null}
# Get tools with specific permissions
tools = composio.tools.get(
    user_id="default",
    toolkits=["GITHUB"],
    # Limit to read-only operations
    permissions=["read"]
)
```

***

## API reference

For detailed documentation of all Composio features and configurations, visit:

* [Composio Documentation](https://docs.composio.dev)
* [LangChain Provider Guide](https://docs.composio.dev/providers/langchain)
* [Available Tools & Actions](https://docs.composio.dev/toolkits/introduction)

***

<div className="source-links">
  <Callout icon="terminal-2">
    [Connect these docs](/use-these-docs) to Claude, VSCode, and more via MCP for real-time answers.
  </Callout>

  <Callout icon="edit">
    [Edit this page on GitHub](https://github.com/langchain-ai/docs/edit/main/src/oss/python/integrations/tools/composio.mdx) or [file an issue](https://github.com/langchain-ai/docs/issues/new/choose).
  </Callout>
</div>
