Composio Tutorial: Tool Integration Platform for AI Agents
Composio is an open-source platform that enables AI agents to connect with 250+ external tools and applications such as GitHub, Slack, Gmail, Google Sheets, Jira, and many more. With Composio, you can build AI agents that don't just think but also take real-world actions through secure, managed API integrations.
In this tutorial, we'll learn how to use Composio from installation and authentication to building AI agents that can interact with various tools automatically.
Why Composio?
Building AI agents that interact with external tools typically requires significant boilerplate code: managing OAuth tokens, writing API wrappers, handling rate limiting, and ensuring security. Composio solves all these problems by providing:
- Managed Authentication: OAuth2, API Key, and Basic Auth handled automatically
- 250+ Pre-built Integrations: GitHub, Slack, Gmail, Notion, Jira, Linear, Google Drive, and more
- Framework Agnostic: Supports LangChain, CrewAI, AutoGen, LlamaIndex, OpenAI, and other frameworks
- Type-safe Actions: Every tool action has a clear schema for input and output
- Execution Environment: Supports local, Docker, and cloud execution
Installation
Python SDK Installation
pip install composio-core
For integration with specific frameworks, install additional packages:
# For OpenAI
pip install composio-openai
For LangChain
pip install composio-langchain
For CrewAI
pip install composio-crewai
For Autogen
pip install composio-autogen
For LlamaIndex
pip install composio-llamaindex
CLI Installation
Composio provides a CLI for managing connections and tools:
pip install composio-core
Login to Composio
composio login
Check status
composio whoami
API Key Setup
After logging in, you can obtain your API key from the Composio dashboard:
export COMPOSIOAPIKEY="your-api-key-here"
Or save it in a .env file:
COMPOSIOAPIKEY=your-api-key-here
Basic Usage
Connecting an App
The first step is connecting the application you want your agent to use. Composio handles the OAuth process automatically:
from composio import ComposioToolSet, App, Action
Initialize toolset
toolset = ComposioToolSet()
Start connection to GitHub
This will open a browser for OAuth authorization
entity = toolset.getentity(id="default")
connectionrequest = entity.initiateconnection(
appname=App.GITHUB
)
print(f"Open this URL to authorize: {connectionrequest.redirectUrl}")
print(f"Connection status: {connectionrequest.connectionStatus}")
For CLI, the connection process is simpler:
# Add GitHub connection
composio add github
Add Slack connection
composio add slack
View active connections
composio connections
Using Tools with OpenAI
Here's a simple example using Composio with OpenAI to create an agent that can interact with GitHub:
from composioopenai import ComposioToolSet, Action
from openai import OpenAI
Initialize
client = OpenAI()
toolset = ComposioToolSet()
Get GitHub tools
tools = toolset.get
tools(actions=[
Action.GITHUBCREATEISSUE,
Action.GITHUBLISTREPOS,
Action.GITHUBSTARREPO,
])
Make request to OpenAI with tools
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{
"role": "system",
"content": "You are an assistant that helps manage GitHub repositories."
},
{
"role": "user",
"content": "Create a new issue in 'myorg/myproject' repo with title 'Fix login bug' and description 'Login page returns 500 error when using SSO'"
}
],
tools=tools,
toolchoice="auto"
)
Execute tool calls
result = toolset.handletoolcalls(response)
print(result)