Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
Add userId in tool calls
haxzie committed
May 14, 2025 at 17:28 UTC
7e99ce2ac074ea75f213b63b45b170c797567ab8
11 files changed
+242
-145
examples/pre-processors/src/index.ts
+8
-45
@@ -8,56 +8,19 @@ const composio = new Composio({
8
apiKey: process.env.COMPOSIO_API_KEY,
9
});
10
11
-const tools = await composio.getTools(
12
- {
13
- toolkitSlug: 'HACKERNEWS',
14
- },
15
- {}
16
-);
17
-// Local modifiers
18
-const tool = await composio.getToolBySlug('HACKERNEWS_GET_USER', {
19
- modifyToolSchema: (toolSlug, toolSchema) => {
20
- toolSchema.inputParameters = {};
21
- return toolSchema;
22
- },
23
-});
11
+const userId = 'default';
12
25
-// local modifiers, with tool as helper
26
-// @ts-ignore
27
-composio.toolset.handleToolCall({}, '', {
28
- beforeToolExecute: (toolSlug, toolExecuteParams) => {
29
- if (toolSlug === 'HACKERNEWS_GET_USER') {
30
- toolExecuteParams.arguments = {};
31
- }
32
- return toolExecuteParams;
13
+const tools = composio.tools.get(userId, 'HACKERNEWS_GET_USER', {
14
+ modifyToolSchema: (toolSlug, tool) => {
15
+ return {
16
+ ...tool,
17
+ description: 'This is a modified description',
18
+ };
19
},
20
});
21
36
-/**
37
- * Agentic toolset
38
- */
22
const vercelComposio = new Composio({
40
- apiKey: process.env.COMPOSIO_API_KEY,
23
toolset: new VercelToolset(),
24
});
25
44
-const verceltools = await vercelComposio.getTools(
45
- {
46
- toolkitSlug: 'HACKERNEWS',
47
- },
48
- {
49
- beforeToolExecute: (toolSlug, toolExecuteParams) => {
50
- if (toolSlug === 'HACKERNEWS_GET_USER') {
51
- toolExecuteParams.arguments = {};
52
- }
53
- return toolExecuteParams;
54
- },
55
- afterToolExecute: (toolSlug, toolExecuteResponse) => {
56
- if (toolSlug === 'HACKERNEWS_GET_USER') {
57
- toolExecuteResponse.data = { message: 'Hello, world!' };
58
- }
59
- return toolExecuteResponse;
60
- },
61
- }
62
-);
63
-console.log(verceltools);
26
+const vercelTools = vercelComposio.tools.get('default', {}, {});
packages/core/src/composio.ts
+8
-5
@@ -10,6 +10,7 @@ import { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
10
import type { TelemetryMetadata } from './types/telemetry.types';
11
import type { ToolsetOptions } from './types/modifiers.types';
12
import type { ToolListParams } from './types/tool.types';
13
+import type { ToolOptions, AgenticToolOptions } from './types/modifiers.types';
14
import { getSDKConfig } from './utils/sdk';
15
import logger from './utils/logger';
16
import { IS_DEVELOPMENT_OR_CI } from './utils/constants';
@@ -58,7 +59,7 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
59
/**
60
* Core models for Composio.
61
*/
61
- tools: Tools;
62
+ tools: Tools<unknown, unknown, TToolset>;
63
toolkits: Toolkits;
64
triggers: Triggers;
65
toolset: TToolset;
@@ -123,7 +124,7 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
124
/**
125
* Initialize all the models with composio client.
126
*/
126
- this.tools = new Tools(this.client);
127
+ this.tools = new Tools(this.client, this.toolset);
128
this.toolkits = new Toolkits(this.client);
129
this.triggers = new Triggers(this.client);
130
this.authConfigs = new AuthConfigs(this.client);
@@ -200,10 +201,11 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
201
* @returns {Promise<ReturnType<TToolset['getTools']>>} The tools from the toolset.
202
*/
203
getTools<T extends TToolset>(
203
- params?: ToolListParams,
204
+ userId: string,
205
+ filters: ToolListParams,
206
modifiers?: ToolsetOptions<T>
207
): Promise<ReturnType<T['getTools']>> {
206
- return this.toolset.getTools(params, modifiers) as Promise<ReturnType<T['getTools']>>;
208
+ return this.tools.get(userId, filters, modifiers) as Promise<ReturnType<T['getTools']>>;
209
}
210
211
/**
@@ -213,9 +215,10 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
215
* @returns {Promise<ReturnType<TToolset['getToolBySlug']>>} The tool from the toolset.
216
*/
217
getToolBySlug<T extends TToolset>(
218
+ userId: string,
219
slug: string,
220
modifiers?: ToolsetOptions<T>
221
): Promise<ReturnType<T['getToolBySlug']>> {
219
- return this.toolset.getToolBySlug(slug, modifiers) as Promise<ReturnType<T['getToolBySlug']>>;
222
+ return this.tools.get(userId, slug, modifiers) as Promise<ReturnType<T['getToolBySlug']>>;
223
}
224
}
packages/core/src/index.ts
+5
-1
@@ -1,7 +1,11 @@
1
// Core exports
2
export { Composio } from './composio';
3
export { ComposioToolset } from './toolset/ComposioToolset';
4
-export { BaseAgenticToolset, BaseNonAgenticToolset } from './toolset/BaseToolset';
4
+export {
5
+ BaseComposioToolset,
6
+ BaseAgenticToolset,
7
+ BaseNonAgenticToolset,
8
+} from './toolset/BaseToolset';
9
export { OpenAIToolset } from './toolset/OpenAIToolset';
10
export { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
11
export { jsonSchemaToModel } from './utils/jsonSchema';
packages/core/src/models/Tools.ts
+60
-5
@@ -21,19 +21,32 @@ import {
21
} from '@composio/client/resources/tools';
22
import { CustomTools } from './CustomTools';
23
import { CustomToolOptions } from '../types/customTool.types';
24
-import { ExecuteToolModifiers, TransformToolSchemaModifier } from '../types/modifiers.types';
24
+import {
25
+ AgenticToolOptions,
26
+ ExecuteToolModifiers,
27
+ ToolOptions,
28
+ ToolsetOptions,
29
+ TransformToolSchemaModifier,
30
+} from '../types/modifiers.types';
31
+import { BaseComposioToolset } from '../toolset/BaseToolset';
32
33
/**
34
* This class is used to manage tools in the Composio SDK.
35
* It provides methods to list, get, and execute tools.
36
*/
30
-export class Tools {
37
+export class Tools<
38
+ TToolCollection,
39
+ TTool,
40
+ TToolset extends BaseComposioToolset<TToolCollection, TTool>,
41
+> {
42
private client: ComposioClient;
43
customTools: CustomTools;
44
+ private toolset: TToolset;
45
34
- constructor(client: ComposioClient) {
46
+ constructor(client: ComposioClient, toolset: TToolset) {
47
this.client = client;
48
this.customTools = new CustomTools(client);
49
+ this.toolset = toolset;
50
}
51
52
private transformToolCases(
@@ -61,7 +74,8 @@ export class Tools {
74
* This method fetches the tools from the Composio API and wraps them using the toolset.
75
* @returns {ToolList} List of tools
76
*/
64
- async getTools(
77
+ async getComposioTools(
78
+ userId: string,
79
query: ToolListParams = {},
80
modifier?: TransformToolSchemaModifier
81
): Promise<ToolList> {
@@ -106,7 +120,11 @@ export class Tools {
120
* @param slug The ID of the tool to be retrieved
121
* @returns {Promise<Tool>} The tool
122
*/
109
- async getToolBySlug(slug: string, modifier?: TransformToolSchemaModifier): Promise<Tool> {
123
+ async getComposioToolBySlug(
124
+ userId: string,
125
+ slug: string,
126
+ modifier?: TransformToolSchemaModifier
127
+ ): Promise<Tool> {
128
// check if the tool is a custom tool
129
const customTool = await this.customTools.getCustomToolBySlug(slug);
130
if (customTool) {
@@ -130,6 +148,24 @@ export class Tools {
148
return modifiedToool;
149
}
150
151
+ async get(userId: string, slug: string, options?: ToolsetOptions<TToolset>): Promise<TTool>;
152
+ async get(
153
+ userId: string,
154
+ filters: ToolListParams,
155
+ options?: ToolsetOptions<TToolset>
156
+ ): Promise<TToolCollection>;
157
+ async get(
158
+ userId: string,
159
+ arg1: ToolListParams | string,
160
+ options?: ToolsetOptions<TToolset>
161
+ ): Promise<TTool | TToolCollection> {
162
+ if (typeof arg1 === 'string') {
163
+ return this.toolset.getToolBySlug(userId, arg1, options);
164
+ } else {
165
+ return this.toolset.getTools(userId, arg1, options);
166
+ }
167
+ }
168
+
169
/**
170
* Exectes a given tool with the provided parameters.
171
*
@@ -162,6 +198,25 @@ export class Tools {
198
connectedAccountId: body.connectedAccountId,
199
});
200
} else {
201
+ // fetch connected accounts if doesn't exist
202
+ let connectedAccountId = body.connectedAccountId;
203
+ if (!connectedAccountId) {
204
+ const tool = await this.getComposioToolBySlug(body.userId, slug);
205
+ if (!tool.toolkit) {
206
+ throw new Error(`Unable to find toolkit for tool ${slug}`);
207
+ }
208
+ const connectedAccounts = await this.client.connectedAccounts.list({
209
+ user_id: body.userId,
210
+ toolkit_slug: tool.toolkit.slug,
211
+ });
212
+ // if no connected accounts, throw an error
213
+ if (connectedAccounts.items.length === 0) {
214
+ throw new Error('No connected accounts found');
215
+ }
216
+ // by default, use the first connected account
217
+ connectedAccountId = connectedAccounts.items[0].id;
218
+ }
219
+
220
result = await this.client.tools.execute(slug, {
221
allow_tracing: body.allowTracing,
222
connected_account_id: body.connectedAccountId,
packages/core/src/toolset/BaseToolset.ts
+54
-28
@@ -1,26 +1,23 @@
1
import type { Toolset } from '../types/toolset.types';
2
import type { Tool, ToolListParams } from '../types/tool.types';
3
import type { Composio } from '../composio';
4
-import { AgenticToolOptions, ToolOptions } from '../types/modifiers.types';
5
-
6
-/**
7
- * Base class for non-agentic toolsets that only support schema modifiers
8
- * This is used for toolsets that don't need to handle tool execution modifiers
9
- * eg: OpenAI, Anthropic, etc.
10
- */
11
-export abstract class BaseNonAgenticToolset<TToolCollection, TTool>
12
- implements Toolset<TTool, TToolCollection>
13
-{
4
+import { AgenticToolOptions, ExecuteToolModifiers, ToolOptions } from '../types/modifiers.types';
5
+
6
+// Type for backward compatibility and type constraints
7
+export abstract class BaseNonAgenticToolset<TToolCollection, TTool> {
8
protected composio: Composio<BaseComposioToolset<TToolCollection, TTool>> | undefined;
15
- protected DEFAULT_ENTITY_ID = 'default';
9
10
setComposio(composio: Composio<BaseComposioToolset<TToolCollection, TTool>>): void {
11
this.composio = composio;
12
}
13
21
- abstract getTools(params?: ToolListParams, modifiers?: ToolOptions): Promise<TToolCollection>;
14
+ abstract getTools(
15
+ userId: string,
16
+ params: ToolListParams,
17
+ options?: ToolOptions
18
+ ): Promise<TToolCollection>;
19
23
- abstract getToolBySlug(slug: string, modifiers?: ToolOptions): Promise<TTool>;
20
+ abstract getToolBySlug(userId: string, slug: string, options?: ToolOptions): Promise<TTool>;
21
22
abstract wrapTool(tool: Tool): TTool;
23
@@ -34,29 +31,26 @@ export abstract class BaseNonAgenticToolset<TToolCollection, TTool>
31
}
32
}
33
37
-/**
38
- * Base class for agentic toolsets that support full modifier capabilities
39
- * This is used for toolsets that need to handle tool execution modifiers
40
- * eg: Vercel, Langchain, etc.
41
- */
42
-export abstract class BaseAgenticToolset<TToolCollection, TTool>
43
- implements Toolset<TTool, TToolCollection>
44
-{
34
+export abstract class BaseAgenticToolset<TToolCollection, TTool> {
35
protected composio: Composio<BaseComposioToolset<TToolCollection, TTool>> | undefined;
46
- protected DEFAULT_ENTITY_ID = 'default';
36
37
setComposio(composio: Composio<BaseComposioToolset<TToolCollection, TTool>>): void {
38
this.composio = composio;
39
}
40
41
+ abstract getToolBySlug(
42
+ userId: string,
43
+ slug: string,
44
+ options?: AgenticToolOptions
45
+ ): Promise<TTool>;
46
+
47
abstract getTools(
53
- params?: ToolListParams,
54
- modifiers?: AgenticToolOptions
48
+ userId: string,
49
+ params: ToolListParams,
50
+ options?: AgenticToolOptions
51
): Promise<TToolCollection>;
52
57
- abstract getToolBySlug(slug: string, modifiers?: AgenticToolOptions): Promise<TTool>;
58
-
59
- abstract wrapTool(tool: Tool): TTool;
53
+ abstract wrapTool(userId: string, tool: Tool, modifers?: ExecuteToolModifiers): TTool;
54
55
protected getComposio(): Composio<BaseComposioToolset<TToolCollection, TTool>> {
56
if (!this.composio) {
@@ -68,7 +62,39 @@ export abstract class BaseAgenticToolset<TToolCollection, TTool>
62
}
63
}
64
71
-// Type for backward compatibility and type constraints
65
export type BaseComposioToolset<TToolCollection, TTool> =
66
| BaseNonAgenticToolset<TToolCollection, TTool>
67
| BaseAgenticToolset<TToolCollection, TTool>;
68
+
69
+// export abstract class BaseComposioToolset<
70
+// TToolCollection,
71
+// TTool,
72
+// TToolOptions extends ToolOptions | AgenticToolOptions,
73
+// > {
74
+// protected composio:
75
+// | Composio<BaseComposioToolset<TToolCollection, TTool, TToolOptions>>
76
+// | undefined;
77
+
78
+// setComposio(composio: Composio<BaseComposioToolset<TToolCollection, TTool, TToolOptions>>): void {
79
+// this.composio = composio;
80
+// }
81
+
82
+// abstract getTools(
83
+// userId: string,
84
+// params?: ToolListParams,
85
+// options?: TToolOptions
86
+// ): Promise<TToolCollection>;
87
+
88
+// abstract getToolBySlug(userId: string, slug: string, options?: TToolOptions): Promise<TTool>;
89
+
90
+// abstract wrapTool(userId: string, tool: Tool): TTool;
91
+
92
+// protected getComposio(): Composio<BaseComposioToolset<TToolCollection, TTool, TToolOptions>> {
93
+// if (!this.composio) {
94
+// throw new Error(
95
+// 'Client not initialized. Make sure the toolset is properly initialized with Composio.'
96
+// );
97
+// }
98
+// return this.composio;
99
+// }
100
+// }
packages/core/src/toolset/ComposioToolset.ts
+19
-7
@@ -1,6 +1,6 @@
1
import { ToolOptions } from '../types/modifiers.types';
2
import { Tool, ToolListParams } from '../types/tool.types';
3
-import { BaseNonAgenticToolset } from './BaseToolset';
3
+import { BaseComposioToolset, BaseNonAgenticToolset } from './BaseToolset';
4
5
/**
6
* This is a default toolset implementation for Composio.
@@ -23,14 +23,26 @@ export class ComposioToolset extends BaseNonAgenticToolset<Array<CustomTool>, Cu
23
return tool as CustomTool;
24
};
25
26
- async getTools(params?: ToolListParams): Promise<Array<CustomTool>> {
27
- const tools = await this.getComposio().tools.getTools(params);
28
- return tools?.map(tool => this.wrapTool(tool as Tool)) ?? [];
26
+ async getTools(
27
+ userId: string,
28
+ params?: ToolListParams,
29
+ options?: ToolOptions
30
+ ): Promise<Array<CustomTool>> {
31
+ const tools = await this.getComposio().tools.getComposioTools(
32
+ userId,
33
+ params,
34
+ options?.modifyToolSchema
35
+ );
36
+ return tools?.map(tool => this.wrapTool(tool)) ?? [];
37
}
38
31
- async getToolBySlug(slug: string, modifiers?: ToolOptions): Promise<CustomTool> {
32
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
33
- return this.wrapTool(tool as Tool);
39
+ async getToolBySlug(userId: string, slug: string, modifiers?: ToolOptions): Promise<CustomTool> {
40
+ const tool = await this.getComposio().tools.getComposioToolBySlug(
41
+ userId,
42
+ slug,
43
+ modifiers?.modifyToolSchema
44
+ );
45
+ return this.wrapTool(tool);
46
}
47
48
async test() {}
packages/core/src/toolset/OpenAIToolset.ts
+32
-31
@@ -9,7 +9,7 @@
9
*/
10
import { OpenAI } from 'openai';
11
import { Stream } from 'openai/streaming';
12
-import { BaseNonAgenticToolset } from './BaseToolset';
12
+import { BaseComposioToolset, BaseNonAgenticToolset } from './BaseToolset';
13
import { Tool, ToolExecuteParams, ToolListParams } from '../types/tool.types';
14
import logger from '../utils/logger';
15
import { ExecuteToolModifiers, ToolOptions } from '../types/modifiers.types';
@@ -41,13 +41,25 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
41
* @param modifiers - Optional modifiers to transform tool schemas
42
* @returns The tools.
43
*/
44
- async getTools(params?: ToolListParams, modifiers?: ToolOptions): Promise<OpenAiToolCollection> {
45
- const tools = await this.getComposio()?.tools.getTools(params, modifiers?.modifyToolSchema);
46
- return tools?.map(tool => this.wrapTool(tool as Tool)) ?? [];
44
+ async getTools(
45
+ userId: string,
46
+ params?: ToolListParams,
47
+ modifiers?: ToolOptions
48
+ ): Promise<OpenAiToolCollection> {
49
+ const tools = await this.getComposio()?.tools.getComposioTools(
50
+ userId,
51
+ params,
52
+ modifiers?.modifyToolSchema
53
+ );
54
+ return tools?.map(tool => this.wrapTool(tool)) ?? [];
55
}
56
49
- async getToolBySlug(slug: string, modifiers?: ToolOptions): Promise<OpenAiTool> {
50
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
57
+ async getToolBySlug(userId: string, slug: string, modifiers?: ToolOptions): Promise<OpenAiTool> {
58
+ const tool = await this.getComposio().tools.getComposioToolBySlug(
59
+ userId,
60
+ slug,
61
+ modifiers?.modifyToolSchema
62
+ );
63
return this.wrapTool(tool);
64
}
65
@@ -58,11 +70,14 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
70
* @returns {Promise<string>} The result of the tool call.
71
*/
72
async executeToolCall(
73
+ userId: string,
74
tool: OpenAI.ChatCompletionMessageToolCall,
62
- userId?: string,
75
modifiers?: ExecuteToolModifiers
76
): Promise<string> {
65
- const toolSchema = await this.getComposio().tools.getToolBySlug(tool.function.name);
77
+ const toolSchema = await this.getComposio().tools.getComposioToolBySlug(
78
+ userId,
79
+ tool.function.name
80
+ );
81
const appSlug = toolSchema?.toolkit?.slug.toLowerCase();
82
if (!appSlug) {
83
throw new Error('App slug not found');
@@ -85,14 +100,14 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
100
* @returns {Promise<string[]>} The results of the tool call.
101
*/
102
async handleToolCall(
103
+ userId: string,
104
chatCompletion: OpenAI.ChatCompletion,
89
- userId?: string,
105
modifiers?: ExecuteToolModifiers
106
) {
107
const outputs: string[] = [];
108
for (const message of chatCompletion.choices) {
109
if (message.message.tool_calls) {
95
- outputs.push(await this.executeToolCall(message.message.tool_calls[0], userId, modifiers));
110
+ outputs.push(await this.executeToolCall(userId, message.message.tool_calls[0], modifiers));
111
}
112
}
113
return outputs;
@@ -106,8 +121,8 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
121
* @returns {Promise<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput[]>} The tool outputs.
122
*/
123
async handleAssistantMessage(
124
+ userId: string,
125
run: OpenAI.Beta.Threads.Run,
110
- userId?: string,
126
modifiers?: ExecuteToolModifiers
127
) {
128
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
@@ -118,8 +133,8 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
133
134
// Execute each tool call and get the response
135
const tool_response = await this.executeToolCall(
121
- tool_call as OpenAI.ChatCompletionMessageToolCall,
136
userId,
137
+ tool_call as OpenAI.ChatCompletionMessageToolCall,
138
modifiers
139
);
140
@@ -144,14 +159,13 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
159
* @returns {AsyncGenerator<OpenAI.Beta.Assistants.AssistantStreamEvent, void, unknown>} The run stream.
160
*/
161
async *waitAndHandleAssistantStreamToolCalls(
162
+ userId: string,
163
client: OpenAI,
164
runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>,
165
thread: OpenAI.Beta.Threads.Thread,
150
- userId?: string,
166
modifiers?: ExecuteToolModifiers
167
) {
168
// @TODO: Log the run stream
154
- const defaultUserId = this.getComposio()?.userId;
169
let runId = null;
170
171
// Start processing the runStream events
@@ -169,11 +183,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
183
184
// Handle the 'requires_action' event
185
if (event.event === 'thread.run.requires_action') {
172
- const toolOutputs = await this.handleAssistantMessage(
173
- event.data,
174
- userId ?? defaultUserId,
175
- modifiers
176
- );
186
+ const toolOutputs = await this.handleAssistantMessage(userId, event.data, modifiers);
187
188
// Submit the tool outputs
189
await client.beta.threads.runs.submitToolOutputs(thread.id, runId, {
@@ -203,11 +213,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
213
214
while (['queued', 'in_progress', 'requires_action'].includes(finalRun.status)) {
215
if (finalRun.status === 'requires_action') {
206
- const toolOutputs = await this.handleAssistantMessage(
207
- finalRun,
208
- userId ?? defaultUserId,
209
- modifiers
210
- );
216
+ const toolOutputs = await this.handleAssistantMessage(userId, finalRun, modifiers);
217
218
// Submit tool outputs
219
finalRun = await client.beta.threads.runs.submitToolOutputs(thread.id, runId, {
@@ -231,20 +237,15 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
237
* @returns {Promise<OpenAI.Beta.Threads.Run>} The run object.
238
*/
239
async waitAndHandleAssistantToolCalls(
240
+ userId: string,
241
client: OpenAI,
242
run: OpenAI.Beta.Threads.Run,
243
thread: OpenAI.Beta.Threads.Thread,
237
- userId?: string,
244
modifiers?: ExecuteToolModifiers
245
) {
240
- const defaultUserId = this.getComposio()?.userId;
246
while (['queued', 'in_progress', 'requires_action'].includes(run.status)) {
247
// logger.debug(`Current run status: ${run.status}`);
243
- const tool_outputs = await this.handleAssistantMessage(
244
- run,
245
- userId ?? defaultUserId,
246
- modifiers
247
- );
248
+ const tool_outputs = await this.handleAssistantMessage(userId, run, modifiers);
249
if (run.status === 'requires_action') {
250
// logger.debug(
251
// `Submitting tool outputs for run ID: ${run.id} in thread ID: ${thread.id}`
packages/core/src/types/tool.types.ts
+1
-1
@@ -89,7 +89,7 @@ export const ToolExecuteParamsSchema = z.object({
89
connectedAccountId: z.string().optional(),
90
customAuthParams: CustomAuthParamsSchema.optional(),
91
arguments: z.record(z.string(), z.unknown()).optional(),
92
- userId: z.string().optional(),
92
+ userId: z.string(),
93
version: z.string().optional(),
94
text: z.string().optional(),
95
});
packages/toolsets/cloudflare/src/index.ts
+16
-6
@@ -11,11 +11,11 @@
11
*/
12
import { AiTextGenerationToolInput } from '@cloudflare/workers-types';
13
import {
14
- BaseNonAgenticToolset,
14
Tool,
15
ToolListParams,
16
ExecuteToolModifiers,
17
ToolOptions,
18
+ BaseNonAgenticToolset,
19
} from '@composio/core';
20
21
type AiToolCollection = Record<string, AiTextGenerationToolInput>;
@@ -58,6 +58,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
58
* @returns {Promise<Record<string, AiTextGenerationToolInput>>} The tools from the Cloudflare API.
59
*/
60
override async getTools(
61
+ userId: string,
62
query?: ToolListParams,
63
modifiers?: ToolOptions
64
): Promise<AiToolCollection> {
@@ -65,7 +66,11 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
66
throw new Error('Client not set');
67
}
68
68
- const tools = await this.getComposio().tools.getTools(query, modifiers?.modifyToolSchema);
69
+ const tools = await this.getComposio().tools.getComposioTools(
70
+ userId,
71
+ query,
72
+ modifiers?.modifyToolSchema
73
+ );
74
return tools.reduce(
75
(tools, tool) => ({
76
...tools,
@@ -76,13 +81,18 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
81
}
82
83
override async getToolBySlug(
84
+ userId: string,
85
slug: string,
86
modifiers?: ToolOptions
87
): Promise<AiTextGenerationToolInput> {
88
if (!this.getComposio()) {
89
throw new Error('Client not set');
90
}
85
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
91
+ const tool = await this.getComposio().tools.getComposioToolBySlug(
92
+ userId,
93
+ slug,
94
+ modifiers?.modifyToolSchema
95
+ );
96
return this.wrapTool(tool);
97
}
98
@@ -93,15 +103,15 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
103
* @returns The results of the tool call.
104
*/
105
async executeToolCall(
106
+ userId: string,
107
tool: { name: string; arguments: unknown },
97
- userId?: string,
108
modifiers?: ExecuteToolModifiers
109
): Promise<string> {
110
if (!this.getComposio()) {
111
throw new Error('Client not set');
112
}
113
104
- const toolSchema = await this.getComposio().tools.getToolBySlug(tool.name);
114
+ const toolSchema = await this.getComposio().tools.getComposioToolBySlug(userId, tool.name);
115
const appName = toolSchema?.toolkit?.name.toLowerCase();
116
if (!appName) {
117
throw new Error('App name not found');
@@ -111,7 +121,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
121
toolSchema.slug,
122
{
123
arguments: args,
114
- userId: userId ?? this.DEFAULT_ENTITY_ID,
124
+ userId,
125
connectedAccountId: this.getComposio()?.getConnectedAccountId(appName),
126
},
127
modifiers
packages/toolsets/langchain/src/index.ts
+16
-6
@@ -29,7 +29,7 @@ export class LangchainToolset extends BaseAgenticToolset<
29
* @param tool - The tool to wrap.
30
* @returns The wrapped tool.
31
*/
32
- wrapTool(tool: Tool, modifiers?: AgenticToolOptions): DynamicStructuredTool {
32
+ wrapTool(userId: string, tool: Tool, modifiers?: AgenticToolOptions): DynamicStructuredTool {
33
const toolName = tool.slug;
34
const description = tool.description;
35
const appName = tool.toolkit?.name?.toLowerCase();
@@ -44,7 +44,7 @@ export class LangchainToolset extends BaseAgenticToolset<
44
toolName,
45
{
46
arguments: kwargs[0] as Record<string, unknown>,
47
- userId: this.getComposio().userId ?? this.DEFAULT_ENTITY_ID,
47
+ userId,
48
connectedAccountId: connectedAccountId,
49
},
50
modifiers
@@ -72,18 +72,28 @@ export class LangchainToolset extends BaseAgenticToolset<
72
* @returns The tools.
73
*/
74
override async getTools(
75
+ userId: string,
76
params?: ToolListParams,
77
modifiers?: AgenticToolOptions
78
): Promise<LangChainToolCollection> {
78
- const tools = await this.getComposio()?.tools.getTools(params, modifiers?.modifyToolSchema);
79
- return tools?.map(tool => this.wrapTool(tool, modifiers)) ?? [];
79
+ const tools = await this.getComposio()?.tools.getComposioTools(
80
+ userId,
81
+ params,
82
+ modifiers?.modifyToolSchema
83
+ );
84
+ return tools?.map(tool => this.wrapTool(userId, tool, modifiers)) ?? [];
85
}
86
87
override async getToolBySlug(
88
+ userId: string,
89
slug: string,
90
modifiers?: AgenticToolOptions
91
): Promise<DynamicStructuredTool> {
86
- const tool = await this.getComposio()?.tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
87
- return this.wrapTool(tool as Tool, modifiers);
92
+ const tool = await this.getComposio()?.tools.getComposioToolBySlug(
93
+ userId,
94
+ slug,
95
+ modifiers?.modifyToolSchema
96
+ );
97
+ return this.wrapTool(userId, tool, modifiers);
98
}
99
}
packages/toolsets/vercel/src/index.ts
+23
-10
@@ -31,25 +31,34 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
31
* @returns The tools.
32
*/
33
override async getTools(
34
+ userId: string,
35
params?: ToolListParams,
36
modifiers?: AgenticToolOptions
37
): Promise<VercelToolCollection> {
38
if (!this.getComposio()) {
39
throw new Error('Client not initialized');
40
}
40
- const tools = await this.getComposio().tools.getTools(params);
41
+ const tools = await this.getComposio().tools.getComposioTools(userId, params);
42
return tools.reduce(
43
(tools, tool) => ({
44
...tools,
44
- [tool.slug]: this.wrapTool(tool as ComposioTool, modifiers),
45
+ [tool.slug]: this.wrapTool(userId, tool, modifiers),
46
}),
47
{}
48
);
49
}
50
50
- override async getToolBySlug(slug: string, modifiers?: AgenticToolOptions): Promise<VercelTool> {
51
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
52
- return this.wrapTool(tool as ComposioTool, modifiers);
51
+ override async getToolBySlug(
52
+ userId: string,
53
+ slug: string,
54
+ modifiers?: AgenticToolOptions
55
+ ): Promise<VercelTool> {
56
+ const tool = await this.getComposio().tools.getComposioToolBySlug(
57
+ userId,
58
+ slug,
59
+ modifiers?.modifyToolSchema
60
+ );
61
+ return this.wrapTool(userId, tool, modifiers);
62
}
63
64
/**
@@ -59,15 +68,15 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
68
* @returns {Promise<string>} The result of the tool call.
69
*/
70
async executeToolCall(
71
+ userId: string,
72
tool: { name: string; arguments: unknown },
63
- userId?: string,
73
modifiers?: ExecuteToolModifiers
74
): Promise<string> {
75
if (!this.getComposio()) {
76
throw new Error('Client not initialized');
77
}
78
70
- const toolSchema = await this.getComposio().tools.getToolBySlug(tool.name);
79
+ const toolSchema = await this.getComposio().tools.getComposioToolBySlug(userId, tool.name);
80
const appName = toolSchema?.name.toLowerCase();
81
const args = typeof tool.arguments === 'string' ? JSON.parse(tool.arguments) : tool.arguments;
82
@@ -75,7 +84,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
84
toolSchema.slug,
85
{
86
arguments: args,
78
- userId: userId ?? this.getComposio().userId,
87
+ userId: userId,
88
connectedAccountId: this.getComposio().getConnectedAccountId(appName),
89
},
90
modifiers
@@ -84,17 +93,21 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
93
return JSON.stringify(results);
94
}
95
87
- wrapTool(composioTool: ComposioTool, modifiers?: ExecuteToolModifiers): VercelTool {
96
+ wrapTool(
97
+ userId: string,
98
+ composioTool: ComposioTool,
99
+ modifiers?: ExecuteToolModifiers
100
+ ): VercelTool {
101
return tool({
102
description: composioTool.description,
103
parameters: jsonSchema(composioTool.inputParameters ?? {}),
104
execute: async params => {
105
return await this.executeToolCall(
106
+ userId,
107
{
108
name: composioTool.slug,
109
arguments: JSON.stringify(params),
110
},
97
- this.getComposio()?.userId,
111
modifiers
112
);
113
},