本页还没有译文
本页 51 段还没译成한국어,下面显示的是英文原文。Composio integration
还没翻译译自英文(docs.langchain.com)本页 51 段都还没译
Composio is an integration platform that gives agents secure access to 1,000+ toolkits and 20,000+ tools across popular applications like GitHub, Slack, Notion, and more. Agents can use Composio through MCP or direct APIs to interact with external services while Composio handles authentication, permissions, and event-driven workflows.
The composio-langchain package wraps Composio tools as LangChain tools and works with LangChain's current create_agent API.
Overview
Integration details
| Class | Package | Serializable | JS support | Version |
|---|---|---|---|---|
Composio | composio-langchain | No | Yes |
See the Composio JS integration docs for JavaScript and TypeScript usage.
Tool features
- 1,000+ toolkits and 20,000+ tools: Prebuilt integrations for GitHub, Slack, Gmail, Jira, Notion, and more, available through MCP or direct APIs.
- Authentication management: Handles OAuth flows, API keys, and authentication state.
- Event-driven workflows: Trigger agents based on external events, such as new Slack messages or GitHub commits.
- Fine-grained permissions: Control tool access and data exposure per user.
- Enterprise controls: Supports governance, auditability, SSO, org-wide controls, and SOC 2 / ISO 27001:2022 certifications for enterprise security reviews.
- Custom tool support: Add proprietary APIs and internal tools.
Setup
The integration lives in the composio-langchain package.
pip install -U composio-langchain langchain langchain-openaiuv add composio-langchain langchain langchain-openaiCredentials
You will need a Composio API key. Sign up at composio.dev to get your API key.
import getpass
import os
if not os.environ.get("COMPOSIO_API_KEY"):
os.environ["COMPOSIO_API_KEY"] = getpass.getpass("Composio API key:\n")It's also helpful to set up LangSmith for tracing:
# os.environ["LANGSMITH_API_KEY"] = getpass.getpass("LangSmith API key:\n")
# os.environ["LANGSMITH_TRACING"] = "true"Instantiation
Initialize Composio with the LangChain provider. Create a session for the user and toolkit set you want the agent to access:
from composio import Composio
from composio_langchain import LangchainProvider
composio = Composio(provider=LangchainProvider())
session = composio.create(user_id="user_123", toolkits=["GITHUB"])
tools = session.tools()session.tools() returns Composio router tools such as COMPOSIO_SEARCH_TOOLS, COMPOSIO_GET_TOOL_SCHEMAS, and COMPOSIO_MANAGE_CONNECTIONS. The agent uses these tools to discover concrete toolkit tools, inspect schemas, manage authentication, and execute actions.
Available toolkits
Composio provides toolkits for many services:
| Category | Example toolkits |
|---|---|
| Productivity | GitHub, Slack, Gmail, Jira, Notion, Asana, Trello, ClickUp |
| Communication | Discord, Telegram, WhatsApp, Microsoft Teams |
| Development | GitLab, Bitbucket, Linear, Sentry |
| Data and analytics | Google Sheets, Airtable, HubSpot, Salesforce |
See the Composio toolkits catalog for the complete list.
Invocation
Discover tools
Use session.search(...) to inspect matching concrete toolkit tools and connection status before asking an agent to execute anything:
search = session.search(query="get authenticated github user")
for result in search.results:
print(result.primary_tool_slugs)
for status in search.toolkit_connection_statuses:
print(status.toolkit, status.has_active_connection, status.status_message)If the toolkit is not connected, Composio will guide the agent to use COMPOSIO_MANAGE_CONNECTIONS, or you can create an authorization link yourself as shown in Authentication setup.
Low-level tool loading
For most agent workflows, prefer composio.create(...) and session.tools(). The lower-level composio.tools.get(...) API is also available when you want to load direct tool lists yourself:
github_tools = composio.tools.get(
user_id="user_123",
toolkits=["GITHUB"],
limit=10,
)
read_scoped_tools = composio.tools.get(
user_id="user_123",
toolkits=["GITHUB"],
scopes=["read"],
limit=10,
)
specific_tool = composio.tools.get(
user_id="user_123",
tools=["GITHUB_GET_THE_AUTHENTICATED_USER"],
)Use within an agent
Here's a complete, read-only example using Composio tools with a LangChain agent. It asks the model to inspect available GitHub profile-reading tools without mutating external state.
import getpass
import os
if not os.environ.get("OPENAI_API_KEY"):
os.environ["OPENAI_API_KEY"] = getpass.getpass("OpenAI API key:\n")from composio import Composio
from composio_langchain import LangchainProvider
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
composio = Composio(provider=LangchainProvider())
session = composio.create(user_id="user_123", toolkits=["GITHUB"])
tools = session.tools()
model = ChatOpenAI(model="gpt-5.4-mini")
agent = create_agent(model=model, tools=tools)
result = agent.invoke(
{
"messages": [
(
"user",
"List available Composio tool names for reading GitHub user "
"profile data. Do not execute external account actions, do not "
"ask me to authenticate, and do not mutate anything.",
)
]
}
)
print(result["messages"][-1].content)Authentication setup
Tools that access a user's external account require that user to connect the corresponding toolkit.
For manual authentication, create a connection request from the session:
connection_request = session.authorize("github")
print(connection_request.redirect_url)After the user completes the authorization flow, the same user_id can use that connected account.
For in-chat authentication, allow the agent to call COMPOSIO_MANAGE_CONNECTIONS when a toolkit has no active connection. The agent can then guide the user through connecting the required account before executing toolkit actions.
Multi-user scenarios
Use a stable user_id for each application user. Each user connects their own accounts, and Composio executes toolkit actions using the credentials associated with that user_id.
session_alice = composio.create(user_id="alice", toolkits=["GITHUB"])
session_bob = composio.create(user_id="bob", toolkits=["GITHUB"])
alice_agent = create_agent(model=model, tools=session_alice.tools())
bob_agent = create_agent(model=model, tools=session_bob.tools())Event-driven workflows
Composio supports triggering agents based on external events. When events occur in connected apps, such as new GitHub commits or Slack messages, triggers can send structured payloads to your application.
Inspect trigger configuration
Before creating a trigger, inspect the required configuration:
from composio import Composio
composio = Composio()
trigger_type = composio.triggers.get_type("GITHUB_COMMIT_EVENT")
print(trigger_type.config)Create a trigger
Create triggers after the relevant account is connected and you have the required configuration:
trigger = composio.triggers.create(
slug="GITHUB_COMMIT_EVENT",
user_id="user_123",
trigger_config={
"owner": "composiohq",
"repo": "composio",
},
)
print(trigger.trigger_id)Webhooks
For production, configure webhooks in the Composio dashboard:
from fastapi import FastAPI, Request
app = FastAPI()
@app.post("/webhook")
async def webhook_handler(request: Request):
payload = await request.json()
if payload.get("triggerSlug") == "GITHUB_COMMIT_EVENT":
commit_data = payload.get("payload")
# Invoke your agent with commit_data here.
return {"status": "success"}For more details, see the Composio triggers documentation.
Custom tools
Composio allows you to create custom tools that can be used alongside built-in tools.
from pydantic import BaseModel, Field
class AddTwoNumbersInput(BaseModel):
a: int = Field(description="The first number to add")
b: int = Field(description="The second number to add")
@composio.tools.custom_tool
def add_two_numbers(request: AddTwoNumbersInput) -> int:
"""Add two numbers."""
return request.a + request.b
tools = session.tools()
tools.append(add_two_numbers)API reference
For detailed documentation of Composio features and configuration options, see: