Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Rename middlewares to modifiers
haxzie committed
May 21, 2025 at 17:06 UTC
d472f178634f549a3291c3c2b5e0dae9f3537ca8
3 files changed
+216
-341
README.md
+214
-339
@@ -1,27 +1,214 @@
1
-# Composio SDK
1
+# Composio SDK v3
2
3
-The core Composio SDK which allows users to interact with the Composio Platform. It provides a powerful and flexible way to manage and execute tools, handle authentication, and integrate with various platforms and frameworks.
3
+The Composio SDK is a powerful toolkit that enables you to integrate third-party tools and services into your applications. It helps you connect to various services (toolkits), execute tools, and manage user connections seamlessly.
4
+
5
+## Features
6
+
7
+- Execute tools from various services (GitHub, Gmail, Slack, etc.)
8
+- Manage user connections to external services
9
+- Create custom tools with your own logic
10
+- Integrate with AI providers like OpenAI
11
+- Powerful middleware and modifier support
12
+- Extensive error handling
13
+
14
+## Documentation
15
+
16
+The SDK is thoroughly documented in the [docs](./docs) directory:
17
+
18
+- [Overview](./docs/overview.md) - Introduction and key concepts
19
+- [Getting Started](./docs/getting-started.md) - Quick start guide
20
+- [Core Concepts](./docs/core-concepts.md) - Fundamental SDK concepts
21
+
22
+### API Reference
23
+
24
+- [Composio Class](./docs/api/composio.md) - Main SDK class
25
+- [Tools](./docs/api/tools.md) - Using and creating tools
26
+- [Toolkits](./docs/api/toolkits.md) - Working with tool collections
27
+- [Connected Accounts](./docs/api/connected-accounts.md) - User authentication
28
+- [Auth Configs](./docs/api/auth-configs.md) - Authentication configuration
29
+- [Custom Tools](./docs/api/custom-tools.md) - Creating your own tools
30
+- [Providers](./docs/api/providers.md) - AI integration options
31
+
32
+### Provider Documentation
33
+
34
+- [OpenAI Provider](./docs/providers/openai.md) - Using OpenAI with Composio
35
+- [Custom Providers](./docs/providers/custom.md) - Creating new providers
36
+
37
+### Advanced Topics
38
+
39
+- [Error Handling](./docs/advanced/error-handling.md) - Managing errors
40
+- [Middleware and Modifiers](./docs/advanced/modifiers.md) - Customizing tools
41
+- [Telemetry](./docs/advanced/telemetry.md) - SDK usage tracking
42
+- [Custom Providers](./docs/advanced/custom-providers.md) - Detailed provider guide
43
+
44
+## Installation
45
+
46
+```bash
47
+# Using npm
48
+npm install @composio/core
49
+
50
+# Using yarn
51
+yarn add @composio/core
52
+
53
+# Using pnpm
54
+pnpm add @composio/core
55
+```
56
+
57
+## Quick Start
58
+
59
+```typescript
60
+import { Composio } from '@composio/core';
61
+
62
+// Initialize the SDK
63
+const composio = new Composio({
64
+ apiKey: 'your-api-key',
65
+});
66
+
67
+// Get tools from a specific toolkit
68
+const tools = await composio.tools.get('default', {
69
+ toolkits: ['github'],
70
+});
71
+
72
+// Execute a tool
73
+const result = await composio.tools.execute('GITHUB_GET_REPO', {
74
+ userId: 'default',
75
+ arguments: {
76
+ owner: 'composio',
77
+ repo: 'sdk',
78
+ },
79
+});
80
+
81
+console.log(result.data);
82
+```
83
+
84
+## OpenAI Integration
85
+
86
+```typescript
87
+import { Composio } from '@composio/core';
88
+import OpenAI from 'openai';
89
+
90
+// Initialize Composio and OpenAI
91
+const composio = new Composio({
92
+ apiKey: 'your-composio-api-key',
93
+});
94
+
95
+const openai = new OpenAI({
96
+ apiKey: 'your-openai-api-key',
97
+});
98
+
99
+// Get GitHub tools
100
+const tools = await composio.tools.get('default', {
101
+ toolkits: ['github'],
102
+});
103
+
104
+// Create a chat completion with the tools
105
+const completion = await openai.chat.completions.create({
106
+ model: 'gpt-4',
107
+ messages: [
108
+ { role: 'system', content: 'You are a helpful assistant with access to GitHub tools.' },
109
+ { role: 'user', content: 'Find information about the Composio SDK repository' },
110
+ ],
111
+ tools, // Pass the tools to OpenAI
112
+});
113
+
114
+// If the model wants to use a tool
115
+if (completion.choices[0].message.tool_calls) {
116
+ const toolCall = completion.choices[0].message.tool_calls[0];
117
+ const args = JSON.parse(toolCall.function.arguments);
118
+
119
+ // Execute the tool
120
+ const result = await composio.tools.execute(toolCall.function.name, {
121
+ userId: 'default',
122
+ arguments: args,
123
+ });
124
+
125
+ console.log(result.data);
126
+}
127
+```
128
+
129
+## Creating Custom Tools
130
+
131
+```typescript
132
+// Create a custom tool
133
+const customTool = await composio.tools.createCustomTool({
134
+ name: 'Weather Forecast',
135
+ description: 'Get the weather forecast for a location',
136
+ slug: 'WEATHER_FORECAST',
137
+ inputParameters: {
138
+ type: 'object',
139
+ properties: {
140
+ location: {
141
+ type: 'string',
142
+ description: 'The location to get the forecast for',
143
+ },
144
+ days: {
145
+ type: 'integer',
146
+ description: 'Number of days for the forecast',
147
+ default: 3,
148
+ },
149
+ },
150
+ required: ['location'],
151
+ },
152
+ outputParameters: {
153
+ type: 'object',
154
+ properties: {
155
+ forecast: {
156
+ type: 'array',
157
+ items: {
158
+ type: 'object',
159
+ properties: {
160
+ date: { type: 'string' },
161
+ temperature: { type: 'number' },
162
+ conditions: { type: 'string' },
163
+ },
164
+ },
165
+ },
166
+ },
167
+ },
168
+ handler: async (params, context) => {
169
+ try {
170
+ const { location, days = 3 } = params.arguments;
171
+
172
+ // Your implementation here
173
+ const forecast = [
174
+ { date: '2025-05-21', temperature: 72, conditions: 'Sunny' },
175
+ { date: '2025-05-22', temperature: 68, conditions: 'Partly Cloudy' },
176
+ { date: '2025-05-23', temperature: 65, conditions: 'Rainy' },
177
+ ];
178
+
179
+ return {
180
+ data: { forecast },
181
+ successful: true,
182
+ error: null,
183
+ };
184
+ } catch (error) {
185
+ return {
186
+ data: {},
187
+ successful: false,
188
+ error: error.message,
189
+ };
190
+ }
191
+ },
192
+});
193
+```
194
195
## Project Structure
196
197
```
198
composio/
199
├── packages/ # Main packages directory
10
-│ ├── core/ # Core SDK package
11
-│ │ └── core/ # Core SDK package
12
-│ ├── providers/ # Provider implementations
13
-│ │ ├── openai/ # OpenAI provider
14
-│ │ ├── vercel/ # Vercel AI provider
15
-│ │ ├── langchain/ # LangChain provider
16
-│ │ └── cloudflare/ # Cloudflare provider
17
-│ └── wrappers/ # Runtime-specific wrappers
18
-├── examples/ # Example implementations
19
-│ ├── langchain/ # LangChain example
20
-│ ├── openai/ # OpenAI example
21
-│ ├── pre-processors/ # Pre-processors example
22
-│ └── vercel/ # Vercel AI example
23
-├── scripts/ # Development and build scripts
24
-└── .github/ # GitHub configuration
200
+│ ├── core/ # Core SDK package
201
+│ └── providers/ # Provider implementations
202
+├── examples/ # Example implementations
203
+│ ├── connected-accounts/ # Connected accounts examples
204
+│ ├── langchain/ # LangChain integration examples
205
+│ ├── openai/ # OpenAI integration examples
206
+│ ├── modifiers/ # Modifiers examples
207
+│ ├── toolkits/ # Toolkits examples
208
+│ └── vercel/ # Vercel AI examples
209
+├── docs/ # Documentation
210
+├── scripts/ # Development and build scripts
211
+└── .github/ # GitHub configuration
212
```
213
214
## Development Setup
@@ -125,6 +312,15 @@ pnpm changeset:release
312
313
- Follow the instructions to release the packages
314
315
+## Environment Variables
316
+
317
+- `COMPOSIO_API_KEY`: Your Composio API key
318
+- `COMPOSIO_BASE_URL`: Custom API base URL (optional)
319
+- `COMPOSIO_LOG_LEVEL`: Logging level (silent, error, warn, info, debug)
320
+- `COMPOSIO_DISABLE_TELEMETRY`: Disable telemetry when set to "true"
321
+- `DEVELOPMENT`: Development mode flag
322
+- `CI`: CI environment flag
323
+
324
## Contributing
325
326
We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for more details.
@@ -135,325 +331,4 @@ ISC License
331
332
## Support
333
138
-For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
139
-
140
-## Core Features
141
-
142
-- **Tools**: Manage and execute tools within the Composio ecosystem. Includes functionality to list, retrieve, and execute tools.
143
-- **Toolkits**: Organize and manage collections of tools for specific use cases.
144
-- **Triggers**: Create and manage event triggers that can execute tools based on specific conditions.
145
-- **AuthConfigs**: Configure authentication providers and settings.
146
-- **ConnectedAccounts**: Manage third-party service connections.
147
-- **ActionExecution**: Track and manage the execution of actions within the platform.
148
-
149
-## Installation
150
-
151
-### Core SDK
152
-
153
-```bash
154
-npm install @composio/core
155
-# or
156
-yarn add @composio/core
157
-# or
158
-pnpm add @composio/core
159
-```
160
-
161
-### Providers
162
-
163
-```bash
164
-# Install OpenAI provider (included in core)
165
-npm install @composio/openai
166
-
167
-# Install Vercel AI provider
168
-npm install @composio/vercel
169
-
170
-# Install Langchain provider
171
-npm install @composio/langchain
172
-```
173
-
174
-## Getting Started
175
-
176
-### Basic Usage with OpenAI Provider
177
-
178
-```typescript
179
-import { Composio } from '@composio/core';
180
-import { OpenAIProvider } from '@composio/openai-provider';
181
-
182
-const composio = new Composio({
183
- apiKey: process.env.COMPOSIO_API_KEY,
184
- // OpenAIProvider is the default, so this is optional
185
- provider: new OpenAIProvider(),
186
-});
187
-
188
-// Fetch a single tool by it's slug
189
-const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS');
190
-
191
-// Fetch multiple tools
192
-const tools = await composio.tools.get('user123', {
193
- category: 'search',
194
- limit: 10,
195
-});
196
-```
197
-
198
-## Using with a Provider
199
-
200
-### Example with Vercel AI Provider
201
-
202
-```typescript
203
-import { Composio } from '@composio/core';
204
-import { VercelProvider } from '@composio/vercel-provider';
205
-
206
-const composio = new Composio({
207
- apiKey: process.env.COMPOSIO_API_KEY,
208
- provider: new VercelProvider(),
209
-});
210
-
211
-// Fetch tools for Vercel AI SDK
212
-const tools = await composio.tools.get('user123', {
213
- category: 'search',
214
-});
215
-
216
-// Use tools with Vercel AI SDK
217
-const completion = await ai.chat({
218
- messages: [{ role: 'user', content: 'Search for posts about React' }],
219
- tools: tools,
220
-});
221
-```
222
-
223
-## Modifiers
224
-
225
-Composio SDK supports powerful modifiers to transform tool schemas and execution behavior.
226
-
227
-### Schema Modifiers
228
-
229
-Schema modifiers allow you to transform tool schemas before they are used:
230
-
231
-```typescript
232
-const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
233
- modifyToolSchema: (toolSlug: string, tool: Tool) => ({
234
- ...tool,
235
- description: 'Enhanced HackerNews search with additional features',
236
- inputParameters: {
237
- ...tool.inputParameters,
238
- limit: {
239
- type: 'number',
240
- description: 'Maximum number of posts to return',
241
- default: 10,
242
- },
243
- },
244
- }),
245
-});
246
-```
247
-
248
-### Execution Modifiers
249
-
250
-For agentic providers (like Vercel AI and Langchain), you can also modify tool execution behavior:
251
-
252
-```typescript
253
-const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
254
- // Transform input before execution
255
- beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
256
- ...params,
257
- arguments: {
258
- ...params.arguments,
259
- limit: Math.min((params.arguments?.limit as number) || 10, 100),
260
- },
261
- }),
262
-
263
- // Transform output after execution
264
- afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
265
- ...response,
266
- data: {
267
- ...response.data,
268
- posts: (response.data?.posts as any[]).map(post => ({
269
- ...post,
270
- url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
271
- })),
272
- },
273
- }),
274
-});
275
-```
276
-
277
-## Connected Accounts
278
-
279
-Composio SDK provides a powerful way to manage third-party service connections through Connected Accounts. This feature allows you to authenticate with various services and maintain those connections.
280
-
281
-### Creating a Connected Account
282
-
283
-```typescript
284
-import { Composio } from '@composio/core';
285
-
286
-const composio = new Composio({
287
- apiKey: process.env.COMPOSIO_API_KEY,
288
-});
289
-
290
-// Create a connected account
291
-const connectionRequest = await composio.createConnectedAccount(
292
- 'user123', // userId
293
- 'id-of-auth-config', // authConfigId
294
- {
295
- redirectUrl: 'https://your-app.com/callback',
296
- data: {
297
- // Additional data for the connection
298
- scope: ['read', 'write'],
299
- },
300
- }
301
-);
302
-
303
-// Wait for the connection to be established
304
-// Default timeout is 60 seconds
305
-const connectedAccount = await connectionRequest.waitForConnection();
306
-```
307
-
308
-### Waiting for Connection to be Established
309
-
310
-The SDK provides a convenient way to wait for a connection to be established using the `waitForConnection` method:
311
-
312
-```typescript
313
-// From a ConnectionRequest instance (after creating a connected account)
314
-// With default timeout (60 seconds)
315
-const connectedAccount = await connectionRequest.waitForConnection();
316
-
317
-// With custom timeout (2 minutes)
318
-const connectedAccount = await connectionRequest.waitForConnection(120000);
319
-
320
-// Directly from the ConnectedAccounts class (with an existing connected account ID)
321
-const connectedAccount = await composio.connectedAccounts.waitForConnection('conn_abc123', 60000);
322
-```
323
-
324
-The method polls the Composio API until:
325
-
326
-- The connection becomes `ACTIVE` (returns the connected account)
327
-- The connection enters a terminal state (`FAILED`, `EXPIRED`, `DELETED`) and throws an error
328
-- The timeout is exceeded (throws a timeout error)
329
-
330
-This is particularly useful for OAuth flows where the user needs to authorize the connection in a browser.
331
-
332
-### Managing Connected Accounts
333
-
334
-```typescript
335
-// List all connected accounts
336
-const accounts = await composio.connectedAccounts.list({
337
- userId: 'user123',
338
-});
339
-
340
-// Get a specific connected account
341
-const account = await composio.connectedAccounts.get('account_id');
342
-
343
-// Enable/Disable a connected account
344
-await composio.connectedAccounts.enable('account_id');
345
-await composio.connectedAccounts.disable('account_id');
346
-
347
-// Refresh credentials
348
-await composio.connectedAccounts.refresh('account_id');
349
-
350
-// Delete a connected account
351
-await composio.connectedAccounts.delete('account_id');
352
-```
353
-
354
-### Connection Statuses
355
-
356
-Connected accounts can have the following statuses:
357
-
358
-- `ACTIVE`: Connection is established and working
359
-- `INACTIVE`: Connection is temporarily disabled
360
-- `PENDING`: Connection is being processed
361
-- `INITIATED`: Connection request has started
362
-- `EXPIRED`: Connection credentials have expired
363
-- `FAILED`: Connection attempt failed
364
-
365
-### Authentication Schemes
366
-
367
-Composio supports various authentication schemes:
368
-
369
-- OAuth2
370
-- OAuth1
371
-- OAuth1a
372
-- API Key
373
-- Basic Auth
374
-- Bearer Token
375
-- Google Service Account
376
-- And more...
377
-
378
-## Development
379
-
380
-### Creating Custom Providers
381
-
382
-You can create custom providers by extending either `BaseNonAgenticProvider` or `BaseAgenticProvider`:
383
-
384
-#### Non-Agentic Provider
385
-
386
-```typescript
387
-import { BaseNonAgenticProvider } from '@composio/core';
388
-import type { Tool } from '@composio/core';
389
-
390
-interface CustomTool {
391
- name: string;
392
- // ... custom tool properties
393
-}
394
-
395
-export class CustomProvider extends BaseNonAgenticProvider<CustomTool[], CustomTool> {
396
- readonly name = 'custom-provider';
397
-
398
- wrapTool = (tool: Tool): CustomTool => ({
399
- name: tool.name,
400
- // ... map other properties
401
- });
402
-
403
- wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
404
-}
405
-```
406
-
407
-#### Agentic Provider
408
-
409
-```typescript
410
-import { BaseAgenticProvider } from '@composio/core';
411
-import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
412
-
413
-export class CustomAgenticProvider extends BaseAgenticProvider<CustomTool[], CustomTool> {
414
- readonly name = 'custom-agentic-provider';
415
-
416
- wrapTool = (tool: Tool): CustomTool => ({
417
- name: tool.name,
418
- // ... map other properties
419
- });
420
-
421
- wrapTools = (tools: Tool[]): CustomTool[] => tools.map(tool => this.wrapTool(tool));
422
-
423
- async executeToolCall(
424
- userId: string,
425
- tool: { name: string; arguments: unknown },
426
- options: pppppp,
427
- modifiers?: ExecuteToolModifiers
428
- ): Promise<string> {
429
- const result = await this.executeTool(
430
- tool.name,
431
- {
432
- arguments: tool.arguments,
433
- userId,
434
- ...options,
435
- },
436
- modifiers
437
- );
438
- return JSON.stringify(result);
439
- }
440
-}
441
-```
442
-
443
-To quickly create a new provider project, use the provided script:
444
-
445
-```bash
446
-# Create a non-agentic provider
447
-pnpm create:provider my-provider
448
-
449
-# Create an agentic provider
450
-pnpm create:provider my-provider --agentic
451
-```
452
-
453
-## Environment Variables
454
-
455
-- `COMPOSIO_API_KEY`: Your Composio API key
456
-- `COMPOSIO_BASE_URL`: Custom API base URL (optional)
457
-- `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
458
-- `DEVELOPMENT`: Development mode flag
459
-- `CI`: CI environment flag
334
+For support, please visit our [Documentation](./docs) or join our [Discord Community](https://discord.gg/composio).
docs/README.md
+1
-1
@@ -109,4 +109,4 @@ Check out our [examples directory](../examples) for complete code samples:
109
- [Error Handling](./advanced/error-handling.md)
110
- [Telemetry](./advanced/telemetry.md)
111
- [Custom Providers](./advanced/custom-providers.md)
112
-- [Middleware and Modifiers](./advanced/middleware.md)
112
+- [Modifiers](./advanced/modifiers.md)
docs/getting-started.md
+1
-1
@@ -270,4 +270,4 @@ Now that you understand the basics, you can:
270
- Explore [more examples](../examples) to see how to use Composio in different scenarios
271
- Learn about [custom providers](./api/providers.md) to integrate with other AI frameworks
272
- Understand [error handling](./advanced/error-handling.md) to make your application more robust
273
-- Implement [middleware and modifiers](./advanced/middleware.md) to customize tool execution
273
+- Implement [modifiers](./advanced/modifiers.md) to customize tool execution