Composio
Comprehensive guide to building AI agents and applications with Composio. Choose between:
Tool Router - Create isolated, secure MCP sessions for AI agents with automatic authenticationDirect Execution - Build traditional apps with manual tool execution and CRUD operationsWhen to use
Use this skill when:
Building AI Agents:
Building chat-based or autonomous agents that need access to external tools (Gmail, Slack, GitHub, etc.)Creating multi-user applications with isolated tool access per sessionImplementing automatic authentication flows for external servicesIntegrating with AI frameworks (Vercel AI SDK, LangChain, OpenAI Agents, Claude)Using MCP (Model Context Protocol) for dynamic tool discoveryBuilding event-driven agents with triggersBuilding Traditional Applications:
Creating CRUD applications that execute tools directlyBuilding automation workflows without agent frameworksManaging connected accounts and authentication configurationsCreating custom tools with specific authentication requirementsImplementing multi-tenant applications with session isolationBuilding tools with pre/post-execution hooks and modifiers1. Building Agents
Use Tool Router to build interactive chat-based agents or autonomous long-running task agents. Tool Router creates isolated MCP sessions for users with scoped access to toolkits and tools.
Key Features:
Session-based isolation per userDynamic toolkit and tool configurationAutomatic authentication managementMCP-compatible server URLs for any AI frameworkConnection state querying for UI buildingReal-time event handling with triggers1.1 Session Management & Configuration
Essential patterns for creating agent sessions and configuring tools:
User ID Best Practices - Choose user IDs for security and isolationCreating Basic Sessions - Initialize Tool Router sessionsSession Lifecycle Best Practices - When to create new sessions vs reuseSession Configuration - Configure toolkits, tools, and filtersUsing Native Tools - Prefer native tools for performance and controlFramework Integration - Connect with Vercel AI, LangChain, OpenAI Agents1.2 Authentication Flows
Authentication patterns for seamless user experiences:
Auto Authentication in Chat - Enable in-chat authentication flowsManual Authorization - Use session.authorize() for explicit flowsConnection Management - Configure manageConnections, waitForConnections, and custom callback URLs1.3 Toolkit Querying & UI Building
Build connection UIs and check toolkit states:
Building Chat UIs - Build chat applications with toolkit selection, connection management, and session handlingQuery Toolkit States - Use session.toolkits() to check connections, filter toolkits, and build connection UIs1.4 Event-Driven Agents (Triggers)
Real-time event handling and webhook integration patterns:
Creating Triggers - Set up trigger instances for real-time eventsSubscribing to Events - Listen to trigger events in real-timeWebhook Verification - Verify and process incoming webhook payloadsManaging Triggers - Enable, disable, update, and list triggers2. Building Apps with Composio Tools
Use Composio for traditional applications where tools are executed manually without agent frameworks. This approach gives you full control over tool execution, authentication, and resource management.
Key Capabilities:
Direct tool execution with manual controlCRUD operations on connected accounts, auth configs, and toolkitsCustom tool creation with authenticationSession isolation for multi-tenant appsPre/post-execution hooks and modifiersEvent-driven workflows with triggers2.1 Core Operations
Fundamental patterns for fetching and executing tools:
Fetching Tools - Get tools with filters and searchDirect Tool Execution - Execute tools manually with parametersTool Version Management - Version pinning strategies for stability2.2 Resource Management (CRUD Patterns)
Manage authentication and connections programmatically:
Connected Accounts CRUD - Create, read, update, delete connected accountsAuth Config Management - Manage authentication configurationsToolkit Management - Query toolkits, categories, and auth requirements2.3 Extensibility & Customization
Extend Composio with custom tools and behavior:
Creating Custom Tools - Build standalone and toolkit-based toolsTool Modifiers - Schema modification and execution hooks2.4 Event-Driven Applications
Build reactive applications with triggers (shared with agents):
Creating Triggers - Set up trigger instances for real-time eventsSubscribing to Events - Listen to trigger events in real-timeWebhook Verification - Verify and process incoming webhooksManaging Triggers - Enable, disable, update, and list triggers2.5 User Context & Multi-Tenancy
Manage user context and multi-tenant isolation:
User ID Patterns - User vs organization IDs, shared vs isolated connectionsQuick Start Examples
Building an Agent with Tool Router
import { Composio } from '@composio/core';const composio = new Composio();
// Create a session with Gmail tools
const session = await composio.create('user_123', {
toolkits: ['gmail'],
manageConnections: true
});
// Use MCP URL with any AI framework
console.log('MCP URL:', session.mcp.url);
Building an App with Direct Execution
import { Composio } from '@composio/core';const composio = new Composio({
apiKey: 'your-api-key',
toolkitVersions: { github: '12082025_00' }
});
// Fetch tools
const tools = await composio.tools.get('user_123', {
toolkits: ['github']
});
// Execute a tool
const result = await composio.tools.execute('GITHUB_GET_REPO', {
userId: 'user_123',
arguments: { owner: 'composio', repo: 'sdk' },
});
console.log(result.data);
References
Tool Router (Agents):
Tool Router DocsMCP ProtocolFramework Integration ExamplesDirect Execution (Apps):
Tools APIConnected Accounts APIAuth Configs APIToolkits APICustom Tools GuideModifiersCore ConceptsShared:
Triggers APIWebhook Verification