Composio Connectors Integration
Relevant source files
The following files were used as context for generating this wiki page:
The Composio Connectors Integration is a core system within the OpenChat project that enables AI models to interact with external third-party services like Gmail, Notion, GitHub, and Slack. By leveraging the Composio SDK, the application transforms an AI chat interface into an agentic assistant capable of executing real-world tasks such as sending emails, managing calendar events, and updating project management tools.
This integration bridges the gap between conversational AI and functional automation. It handles OAuth authentication flows, tool conversion for the Vercel AI SDK, and provides a unified UI for users to manage their service connections. The system is designed to work both in real-time chat sessions and within autonomously scheduled background agents.
Sources: src/lib/composio-server.ts, README.md:21-30, src/routes/settings/connectors.tsx:160-165
System Architecture
The integration follows a tiered architecture involving a frontend configuration UI, a server-side proxy for secure Composio API communication, and a backend integration within Convex for persisting user connection states.
High-Level Data Flow
The flow begins with the user connecting a service in the settings menu, which triggers an OAuth flow via the Composio API. Once connected, the AI model can dynamically request tools associated with that service.
This diagram shows the end-to-end lifecycle of a service connection from initialization to consumption by the AI agent.
Sources: src/routes/settings/connectors.tsx:64-110, src/lib/composio-server.ts:71-115
Core Components
1. Connection Management
The connection lifecycle is handled primarily through server-side functions that interact with the @composio/core SDK. Key operations include initiating OAuth, polling for connection completion, and disconnecting accounts.
| Function | Location | Description |
|---|---|---|
initiateConnection | composio-server.ts | Generates a redirect URL for OAuth and a connection request ID. |
waitForConnection | composio-server.ts | Polls the Composio API to verify if the user successfully authorized the app. |
disconnectAccount | composio-server.ts | Removes the connection for a specific connectionId and refreshes the tool cache. |
getAuthConfigId | composio-utils.ts | Resolves the specific OAuth configuration ID (e.g., gmail_oauth) from environment variables. |
Sources: src/lib/composio-server.ts:75-132, src/lib/tests/composio-utils.test.ts:16-118
2. Tool Integration & Conversion
Composio tools are fetched dynamically based on the user's active connections. These tools are converted from Composio's internal format to the Vercel AI SDK v5 format to allow the AI model to perform tool calls.
- Caching: To optimize performance, converted tools are cached. If a cache hit occurs,
addExecuteFunctionsToCachereconstructs the tools and attaches the necessaryexecutelogic to call the Composio API. - Execution: When a tool is triggered, the
executefunction maps the model's arguments to the Composio tool execution endpoint.
Sources: src/lib/composio-server.ts:40-69, src/lib/composio-server.ts:140-185
AI Agent Integration
The integration allows AI models to use tools through a delegation pattern. Instead of calling service tools directly, the model uses a create_agent tool.
Agent Tooling Flow
When an AI model needs to use a connector (e.g., Gmail), it invokes the create_agent tool with a specific task and the required toolkit slugs.
This sequence illustrates how the primary chat model delegates specific service-related tasks to a specialized sub-agent.
Sources: src/lib/prompt_config.ts:133-145, convex/scheduled_ai.ts:192-205
Prompt Engineering
The system prompt is dynamically built to inform the AI which connectors are currently available for the specific user.
| Status | Prompt Inclusion |
|---|---|
| Enabled | Included in "Currently enabled integrations" with name and description. |
| Disabled | Listed under "Connected but disabled" to inform the user they exist but are inactive. |
| Not Connected | Listed under "Not connected" to prompt the user to visit settings if needed. |
Sources: src/lib/prompt_config.ts:130-175, convex/scheduled_ai.ts:134-165
UI Implementation
The Connector Settings Page provides a categorized view of all supported integrations. It uses optimistic updates for toggling connector status to ensure a responsive user experience.
- Categories: Services are grouped into "Google Workspace", "Communication", and "Development & Productivity".
- State Management: Tracks "idle" vs "connecting" states per connector to display loading skeletons or spinners.
- Action UI: The
ConnectorToolCallcomponent provides detailed visibility into the raw JSON request and response data of a tool execution, including execution time and success/failure status.
Sources: src/routes/settings/connectors.tsx:112-140, src/components/tool/connector_tool_call.tsx:160-250
Supported Connectors
The system identifies connectors using internal slugs which are mapped to user-friendly names and descriptions.
| Connector Type | Auth Config ID (Default) | Primary Actions |
|---|---|---|
gmail | gmail_oauth | Reading/Sending emails |
googlecalendar | googlecalendar_oauth | Managing events |
notion | notion_oauth | Page and Database operations |
github | github_oauth | Issues and PR management |
slack | slack_oauth | Messaging channels/users |
Sources: src/lib/config/tests/tools.test.ts:25-50, src/lib/tests/composio-utils.test.ts:25-115
Conclusion
The Composio Connectors Integration transforms OpenChat from a standard LLM interface into a functional workspace assistant. By abstracting the complexities of OAuth and tool formatting behind a standardized server utility and Convex backend, it provides a scalable way to add new service integrations while maintaining a unified experience for both real-time users and background agents.