Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Remove global userIDs
haxzie committed
May 14, 2025 at 18:10 UTC
f169bb2edac92fc4ff56ae9459a4c2898bb9575d
5 files changed
+104
-177
README.md
+87
-148
@@ -11,6 +11,34 @@ The core Composio SDK which allows users to interact with the Composio Platform.
11
- **ConnectedAccounts**: Manage third-party service connections. Includes functionality to create, list, refresh, and manage the status of connected accounts.
12
- **ActionExecution**: Track and manage the execution of actions within the platform.
13
14
+## Installation
15
+
16
+```bash
17
+npm install @composio/core
18
+# or
19
+yarn add @composio/core
20
+# or
21
+pnpm add @composio/core
22
+```
23
+
24
+## Configuration
25
+
26
+```typescript
27
+interface ComposioConfig {
28
+ apiKey?: string; // Your Composio API key
29
+ baseURL?: string; // Custom API base URL (optional)
30
+ allowTracking?: boolean; // Enable/disable telemetry (default: true)
31
+ allowTracing?: boolean; // Enable/disable tracing (default: true)
32
+ toolset?: TToolset; // Custom toolset (default: OpenAIToolset)
33
+ telemetryTransport?: BaseTelemetryTransport; // Custom telemetry transport
34
+}
35
+
36
+const composio = new Composio({
37
+ apiKey: process.env.COMPOSIO_API_KEY,
38
+ toolset: new OpenAIToolset(), // Optional: defaults to OpenAIToolset
39
+});
40
+```
41
+
42
## Toolsets
43
44
Composio SDK supports two types of toolsets, each with different modifier capabilities:
@@ -19,8 +47,6 @@ Composio SDK supports two types of toolsets, each with different modifier capabi
47
48
These toolsets only support schema modifiers for transforming tool schemas. They are suitable for simple integrations like OpenAI, Anthropic, etc.
49
22
-Schema modifiers allow you to transform tool schemas using the `TransformToolSchemaModifier` function:
23
-
50
```typescript
51
import { Composio } from '@composio/core';
52
import { OpenAIToolset } from '@composio/openai-toolset';
@@ -32,8 +58,8 @@ const composio = new Composio({
58
});
59
60
// Get a tool with schema modifiers
35
-const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
36
- schema: (toolSlug: string, tool: Tool) => ({
61
+const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
62
+ modifyToolSchema: (toolSlug: string, tool: Tool) => ({
63
...tool,
64
description: 'Search HackerNews posts with improved description',
65
inputParameters: {
@@ -51,7 +77,7 @@ const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
77
78
These toolsets support full modifier capabilities, making them suitable for complex integrations like Vercel, Langchain, etc. They support:
79
54
-1. **Schema Modifiers**: Transform tool schemas using `TransformToolSchemaModifier`
80
+1. **Schema Modifiers**: Transform tool schemas using `modifyToolSchema`
81
2. **Execution Modifiers**: Transform tool execution behavior
82
- `beforeToolExecute`: Transform input parameters before execution
83
- `afterToolExecute`: Transform output after execution
@@ -69,9 +95,9 @@ const composio = new Composio({
95
});
96
97
// Get a tool with full modifier support
72
-const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
98
+const tool = await composio.getToolBySlug('user123', 'HACKERNEWS_SEARCH_POSTS', {
99
// Schema modifier
74
- schema: (toolSlug: string, tool: Tool) => ({
100
+ modifyToolSchema: (toolSlug: string, tool: Tool) => ({
101
...tool,
102
description: 'Search HackerNews posts with improved description',
103
inputParameters: {
@@ -101,125 +127,56 @@ const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
127
},
128
}),
129
});
104
-
105
-// Execute the tool with execution modifiers
106
-const result = await composio.toolset.executeTool(
107
- tool,
108
- {
109
- arguments: { query: 'AI', limit: 20 },
110
- },
111
- {
112
- beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
113
- ...params,
114
- arguments: {
115
- ...params.arguments,
116
- limit: Math.min((params.arguments?.limit as number) || 10, 100),
117
- },
118
- }),
119
- afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
120
- ...response,
121
- data: {
122
- ...response.data,
123
- posts: (response.data?.posts as any[]).map(post => ({
124
- ...post,
125
- url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
126
- })),
127
- },
128
- }),
129
- }
130
-);
130
```
131
133
-## Usage
132
+## Creating a Custom Toolset
133
135
-@composio/core ships with OpenAI toolset by default. You can directly use the tools from composio in `openai` methods.
134
+To create a new toolset, extend either `BaseNonAgenticToolset` or `BaseAgenticToolset` from `@composio/core`:
135
136
```typescript
138
-import { Composio } from '@composio/core';
139
-import type { Tool } from '@composio/core';
140
-
141
-// By default composio ships with OpenAI toolset (non-agentic)
142
-const composio = new Composio({
143
- apiKey: process.env.COMPOSIO_API_KEY,
144
-});
145
-
146
-// Get a tool with schema modifiers
147
-const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
148
- schema: (toolSlug: string, tool: Tool) => ({
149
- ...tool,
150
- description: 'Search HackerNews posts with improved description',
151
- inputParameters: {
152
- ...tool.inputParameters,
153
- limit: {
154
- type: 'number',
155
- description: 'Maximum number of posts to return',
156
- },
157
- },
158
- }),
159
-});
160
-console.log(tool);
161
-```
162
-
163
-For more examples, please check the `/examples` directory.
164
-
165
-## Using with a different toolset
166
-
167
-To use a different toolset, please install the recommended toolset packages.
168
-
169
-```typescript
170
-import { Composio } from '@composio/core';
171
-import { VercelToolset } from '@composio/vercel-toolset'; // Agentic toolset
172
-// or
173
-import { OpenAIToolset } from '@composio/openai-toolset'; // Non-agentic toolset
174
-import type { Tool, ToolExecuteParams, ToolExecuteResponse } from '@composio/core';
175
-
176
-const composio = new Composio({
177
- apiKey: process.env.COMPOSIO_API_KEY,
178
- toolset: new VercelToolset(), // or new OpenAIToolset()
179
-});
137
+import { BaseNonAgenticToolset } from '@composio/core';
138
+import type { Tool, ToolListParams, ToolOptions } from '@composio/core';
139
+
140
+interface CustomTool {
141
+ name: string;
142
+ // ... custom tool properties
143
+}
144
+
145
+export class CustomToolset extends BaseNonAgenticToolset<Array<CustomTool>, CustomTool> {
146
+ readonly FILE_NAME: string = 'custom/toolset.ts';
147
+
148
+ wrapTool = (tool: Tool): CustomTool => {
149
+ return {
150
+ name: tool.name,
151
+ // ... map other properties
152
+ };
153
+ };
154
+
155
+ async getTools(
156
+ userId: string,
157
+ params?: ToolListParams,
158
+ options?: ToolOptions
159
+ ): Promise<Array<CustomTool>> {
160
+ const tools = await this.getComposio().tools.getComposioTools(
161
+ userId,
162
+ params,
163
+ options?.modifyToolSchema
164
+ );
165
+ return tools?.map(tool => this.wrapTool(tool)) ?? [];
166
+ }
167
181
-// Get a tool with appropriate modifiers based on toolset type
182
-const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
183
- // Schema modifiers (supported by both types)
184
- schema: (toolSlug: string, tool: Tool) => ({
185
- ...tool,
186
- description: 'Search HackerNews posts with improved description',
187
- inputParameters: {
188
- ...tool.inputParameters,
189
- limit: {
190
- type: 'number',
191
- description: 'Maximum number of posts to return',
192
- },
193
- },
194
- }),
195
- // Execution modifiers (only for agentic toolsets)
196
- ...(composio.toolset instanceof VercelToolset && {
197
- beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
198
- ...params,
199
- arguments: {
200
- ...params.arguments,
201
- limit: Math.min((params.arguments?.limit as number) || 10, 100),
202
- },
203
- }),
204
- afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
205
- ...response,
206
- data: {
207
- ...response.data,
208
- posts: (response.data?.posts as any[]).map(post => ({
209
- ...post,
210
- url: post.url || `https://news.ycombinator.com/item?id=${post.id}`,
211
- })),
212
- },
213
- }),
214
- }),
215
-});
168
+ async getToolBySlug(userId: string, slug: string, options?: ToolOptions): Promise<CustomTool> {
169
+ const tool = await this.getComposio().tools.getComposioToolBySlug(
170
+ userId,
171
+ slug,
172
+ options?.modifyToolSchema
173
+ );
174
+ return this.wrapTool(tool);
175
+ }
176
+}
177
```
178
218
-## Creating a new toolset
219
-
220
-To create a new Toolset, you need to extend either `BaseNonAgenticToolset` or `BaseAgenticToolset` from `@composio/core` and implement the required methods.
221
-
222
-To quickly create a toolset project, execute the following command from the root of the project:
179
+To quickly create a toolset project, use the provided script:
180
181
```bash
182
# Create a non-agentic toolset (default)
@@ -229,40 +186,22 @@ pnpm run create-toolset <your-toolset-name>
186
pnpm run create-toolset <your-toolset-name> --agentic
187
```
188
232
-For example:
233
-
234
-```bash
235
-# Create a non-agentic toolset for Anthropic
236
-pnpm run create-toolset anthropic
189
+## Environment Variables
190
238
-# Create an agentic toolset for Langchain
239
-pnpm run create-toolset langchain --agentic
240
-```
191
+- `COMPOSIO_API_KEY`: Your Composio API key
192
+- `COMPOSIO_BASE_URL`: Custom API base URL
193
+- `COMPOSIO_LOGGING_LEVEL`: Logging level (silent, error, warn, info, debug)
194
+- `DEVELOPMENT`: Development mode flag
195
+- `CI`: CI environment flag
196
242
-The script will create a new toolset with the following structure:
197
+## Contributing
198
244
-```
245
-<toolset-name>/
246
-├── src/
247
-│ └── index.ts # Toolset implementation
248
-├── package.json # Package configuration
249
-├── tsconfig.json # TypeScript configuration
250
-├── tsup.config.ts # Build configuration
251
-└── README.md # Toolset documentation
252
-```
199
+We welcome contributions! Please see our [Contributing Guide](../../CONTRIBUTING.md) for more details.
200
254
-## Internal
201
+## License
202
256
-What's not included from @composio/client
203
+ISC License
204
258
-- [x] Org/Project Mangement with API Keys
259
-- [x] Trigger Subscriptions
260
-- [ ] Zod Schemas for type checking `Ideally strike a minimal balance, since backend has most`
261
-- [ ] Action Execution
262
-- [ ] CLI `Do we need this in the core SDK?`
263
-- [ ] MCP `Not required as this is not necessary`
264
-- [ ] Team Members
265
-- [ ] File uploads/user files
266
-- [ ] Tests
205
+## Support
206
268
-These models can be still be accessed via the SDK explicitly by using the `@composio/client`.
207
+For support, please visit our [Documentation](https://docs.composio.dev) or join our [Discord Community](https://discord.gg/composio).
packages/core/package.json
+1
@@ -37,6 +37,7 @@
37
"@composio/client": "0.1.0-alpha.9",
38
"openai": "^4.94.0",
39
"pusher-js": "^8.4.0",
40
+ "uuid": "^11.1.0",
41
"zod": "^3.24.2",
42
"zod-to-json-schema": "^3.24.5"
43
}
packages/core/src/composio.ts
+2
-29
@@ -16,6 +16,7 @@ import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
16
import { checkForLatestVersionFromNPM } from './utils/version';
17
import { OpenAIToolset } from './toolset/OpenAIToolset';
18
import { version } from '../package.json';
19
+import { getRandomUUID } from './utils/uuid';
20
21
export type ComposioConfig<TToolset extends BaseComposioToolset<unknown, unknown> = OpenAIToolset> =
22
{
@@ -24,8 +25,6 @@ export type ComposioConfig<TToolset extends BaseComposioToolset<unknown, unknown
25
allowTracking?: boolean;
26
allowTracing?: boolean;
27
toolset?: TToolset;
27
- userId?: string;
28
- connectedAccountIds?: Record<string, string>;
28
telemetryTransport?: BaseTelemetryTransport;
29
};
30
@@ -49,12 +48,6 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
48
49
private telemetry: Telemetry | undefined;
50
52
- /**
53
- * Context variables for the Composio SDK.
54
- */
55
- userId?: string;
56
- connectedAccountIds?: Record<string, string>;
57
-
51
/**
52
* Core models for Composio.
53
*/
@@ -85,11 +78,6 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
78
if (IS_DEVELOPMENT_OR_CI) {
79
logger.info(`Initializing Composio w API Key: [REDACTED] and baseURL: ${baseURLParsed}`);
80
}
88
- if (config.userId && config.connectedAccountIds) {
89
- logger.warn(
90
- 'When both userId and connectedAccountIds are provided, preference will be given to connectedAccountIds'
91
- );
92
- }
81
82
/**
83
* Initialize the Composio SDK client.
@@ -109,12 +97,6 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
97
allowTracking: config.allowTracking ?? true,
98
};
99
112
- /**
113
- * Set the context variables for the Composio SDK.
114
- */
115
- this.userId = config.userId ?? this.DEFAULT_USER_ID; // entity id of the user
116
- this.connectedAccountIds = config.connectedAccountIds ?? {}; // app name -> account id of the connected account
117
-
100
/**
101
* Set the default toolset, if not provided by the user.
102
*/
@@ -142,9 +124,9 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
124
baseUrl: baseURLParsed ?? '',
125
frameworkRuntime: 'node',
126
source: 'node', // @TODO: get the source
145
- sessionId: this.userId,
127
composioVersion: version,
128
isBrowser: typeof window !== 'undefined',
129
+ sessionId: getRandomUUID(), // @TODO: get the session id
130
},
131
config.telemetryTransport
132
);
@@ -173,15 +155,6 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
155
this.telemetry.instrumentTelemetry(this.toolset);
156
}
157
176
- /**
177
- * Get the connected account id for the given app name.
178
- * @param appName - The name of the app.
179
- * @returns {string | undefined} The connected account id for the given app name.
180
- */
181
- getConnectedAccountId(appName: string): string | undefined {
182
- return this.connectedAccountIds?.[appName];
183
- }
184
-
158
/**
159
* Get the Composio SDK client.
160
* @returns {ComposioClient} The Composio API client.
packages/core/src/utils/uuid.ts
new
+5
@@ -0,0 +1,5 @@
1
+import { v4 as uuidv4 } from 'uuid';
2
+
3
+export function getRandomUUID(): string {
4
+ return uuidv4();
5
+}
pnpm-lock.yaml
+9
@@ -123,6 +123,9 @@ importers:
123
pusher-js:
124
specifier: ^8.4.0
125
version: 8.4.0
126
+ uuid:
127
+ specifier: ^11.1.0
128
+ version: 11.1.0
129
zod:
130
specifier: ^3.24.2
131
version: 3.24.2
@@ -1966,6 +1969,10 @@ packages:
1969
resolution: {integrity: sha512-8XkAphELsDnEGrDxUOHB3RGvXz6TeuYSGEZBOjtTtPm2lwhGBjLgOzLHB63IUWfBpNucQjND6d3AOudO+H3RWQ==}
1970
hasBin: true
1971
1972
+ uuid@11.1.0:
1973
+ resolution: {integrity: sha512-0/A9rDy9P7cJ+8w1c9WD9V//9Wj15Ce2MPz8Ri6032usz+NfePxx5AcN3bN+r6ZL6jEo066/yNYB3tn4pQEx+A==}
1974
+ hasBin: true
1975
+
1976
web-streams-polyfill@4.0.0-beta.3:
1977
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
1978
engines: {node: '>= 14'}
@@ -3799,6 +3806,8 @@ snapshots:
3806
3807
uuid@10.0.0: {}
3808
3809
+ uuid@11.1.0: {}
3810
+
3811
web-streams-polyfill@4.0.0-beta.3: {}
3812
3813
webidl-conversions@3.0.1: {}