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 tool options
haxzie committed
May 14, 2025 at 15:36 UTC
85b30c44e434c06d1e3520b31e6e6bdf128075f6
10 files changed
+90
-79
packages/core/src/composio.ts
+5
-5
@@ -8,7 +8,7 @@ import { BaseComposioToolset } from './toolset/BaseToolset';
8
import { Telemetry } from './telemetry/Telemetry';
9
import { BaseTelemetryTransport } from './telemetry/TelemetryTransport';
10
import type { TelemetryMetadata } from './types/telemetry.types';
11
-import type { ToolsetModifierType } from './types/modifiers.types';
11
+import type { ToolsetOptions } from './types/modifiers.types';
12
import type { ToolListParams } from './types/tool.types';
13
import { getSDKConfig } from './utils/sdk';
14
import logger from './utils/logger';
@@ -196,12 +196,12 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
196
/**
197
* Fetch all the tools from Composio.
198
* @param {ToolListParams} params Parameters to fetch the tools.
199
- * @param {ToolsetModifierType<TToolset>} modifiers Modifiers to apply to the tools.
199
+ * @param {ToolsetOptions<TToolset>} modifiers Modifiers to apply to the tools.
200
* @returns {Promise<ReturnType<TToolset['getTools']>>} The tools from the toolset.
201
*/
202
getTools<T extends TToolset>(
203
params?: ToolListParams,
204
- modifiers?: ToolsetModifierType<T>
204
+ modifiers?: ToolsetOptions<T>
205
): Promise<ReturnType<T['getTools']>> {
206
return this.toolset.getTools(params, modifiers) as Promise<ReturnType<T['getTools']>>;
207
}
@@ -209,12 +209,12 @@ export class Composio<TToolset extends BaseComposioToolset<unknown, unknown> = O
209
/**
210
* Fetch a tool from Composio by its slug.
211
* @param {string} slug slug of the tool
212
- * @param {ToolsetModifierType<TToolset>} modifiers to be applied to the tool
212
+ * @param {ToolsetOptions<TToolset>} modifiers to be applied to the tool
213
* @returns {Promise<ReturnType<TToolset['getToolBySlug']>>} The tool from the toolset.
214
*/
215
getToolBySlug<T extends TToolset>(
216
slug: string,
217
- modifiers?: ToolsetModifierType<T>
217
+ modifiers?: ToolsetOptions<T>
218
): Promise<ReturnType<T['getToolBySlug']>> {
219
return this.toolset.getToolBySlug(slug, modifiers) as Promise<ReturnType<T['getToolBySlug']>>;
220
}
packages/core/src/index.ts
+3
-1
@@ -9,7 +9,9 @@ export { Tool, ToolListParams, ToolListParamsSchema } from './types/tool.types';
9
export { Toolset } from './types/toolset.types';
10
// Type exports
11
export type {
12
- ModifiersParams,
12
+ ExecuteToolModifiers,
13
+ AgenticToolOptions,
14
+ ToolOptions,
15
TransformToolSchemaModifier,
16
BeforeToolExecuteModifier,
17
AfterToolExecuteModifier,
packages/core/src/models/Tools.ts
+2
-2
@@ -21,7 +21,7 @@ import {
21
} from '@composio/client/resources/tools';
22
import { CustomTools } from './CustomTools';
23
import { CustomToolOptions } from '../types/customTool.types';
24
-import { ExecuteToolModifiersParams, TransformToolSchemaModifier } from '../types/modifiers.types';
24
+import { ExecuteToolModifiers, TransformToolSchemaModifier } from '../types/modifiers.types';
25
26
/**
27
* This class is used to manage tools in the Composio SDK.
@@ -142,7 +142,7 @@ export class Tools {
142
async execute(
143
slug: string,
144
body: ToolExecuteParams,
145
- modifiers?: ExecuteToolModifiersParams
145
+ modifiers?: ExecuteToolModifiers
146
): Promise<ToolExecuteResponse> {
147
// apply local modifiers if they are provided
148
if (modifiers && modifiers.beforeToolExecute) {
packages/core/src/toolset/BaseToolset.ts
+8
-8
@@ -1,7 +1,7 @@
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 { ModifiersParams, SchemaModifiersParams } from '../types/modifiers.types';
4
+import { AgenticToolOptions, ToolOptions } from '../types/modifiers.types';
5
6
/**
7
* Base class for non-agentic toolsets that only support schema modifiers
@@ -18,12 +18,9 @@ export abstract class BaseNonAgenticToolset<TToolCollection, TTool>
18
this.composio = composio;
19
}
20
21
- abstract getTools(
22
- params?: ToolListParams,
23
- modifiers?: SchemaModifiersParams
24
- ): Promise<TToolCollection>;
21
+ abstract getTools(params?: ToolListParams, modifiers?: ToolOptions): Promise<TToolCollection>;
22
26
- abstract getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<TTool>;
23
+ abstract getToolBySlug(slug: string, modifiers?: ToolOptions): Promise<TTool>;
24
25
abstract wrapTool(tool: Tool): TTool;
26
@@ -52,9 +49,12 @@ export abstract class BaseAgenticToolset<TToolCollection, TTool>
49
this.composio = composio;
50
}
51
55
- abstract getTools(params?: ToolListParams, modifiers?: ModifiersParams): Promise<TToolCollection>;
52
+ abstract getTools(
53
+ params?: ToolListParams,
54
+ modifiers?: AgenticToolOptions
55
+ ): Promise<TToolCollection>;
56
57
- abstract getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<TTool>;
57
+ abstract getToolBySlug(slug: string, modifiers?: AgenticToolOptions): Promise<TTool>;
58
59
abstract wrapTool(tool: Tool): TTool;
60
packages/core/src/toolset/ComposioToolset.ts
+3
-3
@@ -1,4 +1,4 @@
1
-import { SchemaModifiersParams } from '../types/modifiers.types';
1
+import { ToolOptions } from '../types/modifiers.types';
2
import { Tool, ToolListParams } from '../types/tool.types';
3
import { BaseNonAgenticToolset } from './BaseToolset';
4
@@ -28,8 +28,8 @@ export class ComposioToolset extends BaseNonAgenticToolset<Array<CustomTool>, Cu
28
return tools?.map(tool => this.wrapTool(tool as Tool)) ?? [];
29
}
30
31
- async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<CustomTool> {
32
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
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);
34
}
35
packages/core/src/toolset/OpenAIToolset.ts
+14
-17
@@ -10,9 +10,9 @@
10
import { OpenAI } from 'openai';
11
import { Stream } from 'openai/streaming';
12
import { BaseNonAgenticToolset } from './BaseToolset';
13
-import { Tool, ToolListParams } from '../types/tool.types';
13
+import { Tool, ToolExecuteParams, ToolListParams } from '../types/tool.types';
14
import logger from '../utils/logger';
15
-import { ExecuteToolModifiersParams, SchemaModifiersParams } from '../types/modifiers.types';
15
+import { ExecuteToolModifiers, ToolOptions } from '../types/modifiers.types';
16
17
export type OpenAiTool = OpenAI.ChatCompletionTool;
18
export type OpenAiToolCollection = Array<OpenAiTool>;
@@ -41,16 +41,13 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
41
* @param modifiers - Optional modifiers to transform tool schemas
42
* @returns The tools.
43
*/
44
- async getTools(
45
- params?: ToolListParams,
46
- modifiers?: SchemaModifiersParams
47
- ): Promise<OpenAiToolCollection> {
48
- const tools = await this.getComposio()?.tools.getTools(params, modifiers?.schema);
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)) ?? [];
47
}
48
52
- async getToolBySlug(slug: string, modifiers?: SchemaModifiersParams): Promise<OpenAiTool> {
53
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
49
+ async getToolBySlug(slug: string, modifiers?: ToolOptions): Promise<OpenAiTool> {
50
+ const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
51
return this.wrapTool(tool);
52
}
53
@@ -63,7 +60,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
60
async executeToolCall(
61
tool: OpenAI.ChatCompletionMessageToolCall,
62
userId?: string,
66
- modifiers?: ExecuteToolModifiersParams
63
+ modifiers?: ExecuteToolModifiers
64
): Promise<string> {
65
const toolSchema = await this.getComposio().tools.getToolBySlug(tool.function.name);
66
const appSlug = toolSchema?.toolkit?.slug.toLowerCase();
@@ -71,9 +68,9 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
68
throw new Error('App slug not found');
69
}
70
const connectedAccountId = this.getComposio().getConnectedAccountId(appSlug);
74
- const payload = {
75
- entity_id: userId ?? this.getComposio().userId,
76
- connected_account_id: connectedAccountId,
71
+ const payload: ToolExecuteParams = {
72
+ userId: userId ?? this.getComposio().userId,
73
+ connectedAccountId: connectedAccountId,
74
arguments: JSON.parse(tool.function.arguments),
75
};
76
const results = await this.getComposio().tools.execute(toolSchema.slug, payload, modifiers);
@@ -90,7 +87,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
87
async handleToolCall(
88
chatCompletion: OpenAI.ChatCompletion,
89
userId?: string,
93
- modifiers?: ExecuteToolModifiersParams
90
+ modifiers?: ExecuteToolModifiers
91
) {
92
const outputs: string[] = [];
93
for (const message of chatCompletion.choices) {
@@ -111,7 +108,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
108
async handleAssistantMessage(
109
run: OpenAI.Beta.Threads.Run,
110
userId?: string,
114
- modifiers?: ExecuteToolModifiersParams
111
+ modifiers?: ExecuteToolModifiers
112
) {
113
const tool_calls = run.required_action?.submit_tool_outputs?.tool_calls || [];
114
const tool_outputs: Array<OpenAI.Beta.Threads.Runs.RunSubmitToolOutputsParams.ToolOutput> =
@@ -151,7 +148,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
148
runStream: Stream<OpenAI.Beta.Assistants.AssistantStreamEvent>,
149
thread: OpenAI.Beta.Threads.Thread,
150
userId?: string,
154
- modifiers?: ExecuteToolModifiersParams
151
+ modifiers?: ExecuteToolModifiers
152
) {
153
// @TODO: Log the run stream
154
const defaultUserId = this.getComposio()?.userId;
@@ -238,7 +235,7 @@ export class OpenAIToolset extends BaseNonAgenticToolset<OpenAiToolCollection, O
235
run: OpenAI.Beta.Threads.Run,
236
thread: OpenAI.Beta.Threads.Thread,
237
userId?: string,
241
- modifiers?: ExecuteToolModifiersParams
238
+ modifiers?: ExecuteToolModifiers
239
) {
240
const defaultUserId = this.getComposio()?.userId;
241
while (['queued', 'in_progress', 'requires_action'].includes(run.status)) {
packages/core/src/types/modifiers.types.ts
+20
-17
@@ -26,31 +26,34 @@ export type AfterToolExecuteModifier = (
26
export type TransformToolSchemaModifier = (toolSlug: string, toolSchema: Tool) => Tool;
27
28
/**
29
- * Modifiers for the toolset
30
- * This is used by Agentic toolsets
29
+ * Non Agentic tool options. These are used by Non-Agentic toolsets
30
*/
32
-export type ModifiersParams = {
33
- beforeToolExecute?: BeforeToolExecuteModifier;
34
- afterToolExecute?: AfterToolExecuteModifier;
35
- schema?: TransformToolSchemaModifier;
36
-};
37
-
38
-/**
39
- * Modifiers for the tool schema
40
- * This is used by Non-Agentic toolsets
41
- */
42
-export type SchemaModifiersParams = {
43
- schema?: TransformToolSchemaModifier;
31
+export type ToolOptions = {
32
+ /**
33
+ * Transform tool schema modifier
34
+ */
35
+ modifyToolSchema?: TransformToolSchemaModifier;
36
};
37
38
/**
39
* Modifiers for the tool execution
40
* This is used by execute call and handleToolCall of Non-Agentic toolsets
41
*/
50
-export type ExecuteToolModifiersParams = {
42
+export type ExecuteToolModifiers = {
43
+ /**
44
+ * Before tool execute modifier
45
+ */
46
beforeToolExecute?: BeforeToolExecuteModifier;
47
+ /**
48
+ * After tool execute modifier
49
+ */
50
afterToolExecute?: AfterToolExecuteModifier;
51
};
52
55
-export type ToolsetModifierType<T extends BaseComposioToolset<unknown, unknown>> =
56
- T extends BaseAgenticToolset<unknown, unknown> ? ModifiersParams : SchemaModifiersParams;
53
+/**
54
+ * Agentic tool options. These are used by Agentic toolsets
55
+ */
56
+export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
57
+
58
+export type ToolsetOptions<T extends BaseComposioToolset<unknown, unknown>> =
59
+ T extends BaseAgenticToolset<unknown, unknown> ? AgenticToolOptions : ToolOptions;
packages/toolsets/cloudflare/src/index.ts
+11
-9
@@ -10,11 +10,13 @@
10
* @module toolsets/cloudflare
11
*/
12
import { AiTextGenerationToolInput } from '@cloudflare/workers-types';
13
-import { BaseNonAgenticToolset, Tool, ToolListParams } from '@composio/core';
13
import {
15
- ExecuteToolModifiersParams,
16
- SchemaModifiersParams,
17
-} from 'packages/core/src/types/modifiers.types';
14
+ BaseNonAgenticToolset,
15
+ Tool,
16
+ ToolListParams,
17
+ ExecuteToolModifiers,
18
+ ToolOptions,
19
+} from '@composio/core';
20
21
type AiToolCollection = Record<string, AiTextGenerationToolInput>;
22
@@ -57,13 +59,13 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
59
*/
60
override async getTools(
61
query?: ToolListParams,
60
- modifiers?: SchemaModifiersParams
62
+ modifiers?: ToolOptions
63
): Promise<AiToolCollection> {
64
if (!this.getComposio()) {
65
throw new Error('Client not set');
66
}
67
66
- const tools = await this.getComposio().tools.getTools(query, modifiers?.schema);
68
+ const tools = await this.getComposio().tools.getTools(query, modifiers?.modifyToolSchema);
69
return tools.reduce(
70
(tools, tool) => ({
71
...tools,
@@ -75,12 +77,12 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
77
78
override async getToolBySlug(
79
slug: string,
78
- modifiers?: SchemaModifiersParams
80
+ modifiers?: ToolOptions
81
): Promise<AiTextGenerationToolInput> {
82
if (!this.getComposio()) {
83
throw new Error('Client not set');
84
}
83
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
85
+ const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
86
return this.wrapTool(tool);
87
}
88
@@ -93,7 +95,7 @@ export class CloudflareToolset extends BaseNonAgenticToolset<
95
async executeToolCall(
96
tool: { name: string; arguments: unknown },
97
userId?: string,
96
- modifiers?: ExecuteToolModifiersParams
98
+ modifiers?: ExecuteToolModifiers
99
): Promise<string> {
100
if (!this.getComposio()) {
101
throw new Error('Client not set');
packages/toolsets/langchain/src/index.ts
+12
-7
@@ -9,9 +9,14 @@
9
* @packageDocumentation
10
* @module toolsets/langchain
11
*/
12
-import { BaseAgenticToolset, jsonSchemaToModel, Tool, ToolListParams } from '@composio/core';
12
+import {
13
+ BaseAgenticToolset,
14
+ jsonSchemaToModel,
15
+ Tool,
16
+ ToolListParams,
17
+ AgenticToolOptions,
18
+} from '@composio/core';
19
import { DynamicStructuredTool } from '@langchain/core/tools';
14
-import { ModifiersParams } from 'packages/core/src/types/modifiers.types';
20
21
export type LangChainToolCollection = Array<DynamicStructuredTool>;
22
export class LangchainToolset extends BaseAgenticToolset<
@@ -24,7 +29,7 @@ export class LangchainToolset extends BaseAgenticToolset<
29
* @param tool - The tool to wrap.
30
* @returns The wrapped tool.
31
*/
27
- wrapTool(tool: Tool, modifiers?: ModifiersParams): DynamicStructuredTool {
32
+ wrapTool(tool: Tool, modifiers?: AgenticToolOptions): DynamicStructuredTool {
33
const toolName = tool.slug;
34
const description = tool.description;
35
const appName = tool.toolkit?.name?.toLowerCase();
@@ -68,17 +73,17 @@ export class LangchainToolset extends BaseAgenticToolset<
73
*/
74
override async getTools(
75
params?: ToolListParams,
71
- modifiers?: ModifiersParams
76
+ modifiers?: AgenticToolOptions
77
): Promise<LangChainToolCollection> {
73
- const tools = await this.getComposio()?.tools.getTools(params, modifiers?.schema);
78
+ const tools = await this.getComposio()?.tools.getTools(params, modifiers?.modifyToolSchema);
79
return tools?.map(tool => this.wrapTool(tool, modifiers)) ?? [];
80
}
81
82
override async getToolBySlug(
83
slug: string,
79
- modifiers?: ModifiersParams
84
+ modifiers?: AgenticToolOptions
85
): Promise<DynamicStructuredTool> {
81
- const tool = await this.getComposio()?.tools.getToolBySlug(slug, modifiers?.schema);
86
+ const tool = await this.getComposio()?.tools.getToolBySlug(slug, modifiers?.modifyToolSchema);
87
return this.wrapTool(tool as Tool, modifiers);
88
}
89
}
packages/toolsets/vercel/src/index.ts
+12
-10
@@ -10,13 +10,15 @@
10
* @packageDocumentation
11
* @module toolsets/vercel
12
*/
13
-import { BaseAgenticToolset, Tool as ComposioTool, ToolListParams } from '@composio/core';
13
+import {
14
+ BaseAgenticToolset,
15
+ Tool as ComposioTool,
16
+ ToolListParams,
17
+ ExecuteToolModifiers,
18
+ AgenticToolOptions,
19
+} from '@composio/core';
20
import type { Tool as VercelTool } from 'ai';
21
import { jsonSchema, tool } from 'ai';
16
-import {
17
- ExecuteToolModifiersParams,
18
- ModifiersParams,
19
-} from 'packages/core/src/types/modifiers.types';
22
23
type VercelToolCollection = Record<string, VercelTool>;
24
export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, VercelTool> {
@@ -30,7 +32,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
32
*/
33
override async getTools(
34
params?: ToolListParams,
33
- modifiers?: ModifiersParams
35
+ modifiers?: AgenticToolOptions
36
): Promise<VercelToolCollection> {
37
if (!this.getComposio()) {
38
throw new Error('Client not initialized');
@@ -45,8 +47,8 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
47
);
48
}
49
48
- override async getToolBySlug(slug: string, modifiers?: ModifiersParams): Promise<VercelTool> {
49
- const tool = await this.getComposio().tools.getToolBySlug(slug, modifiers?.schema);
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);
53
}
54
@@ -59,7 +61,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
61
async executeToolCall(
62
tool: { name: string; arguments: unknown },
63
userId?: string,
62
- modifiers?: ExecuteToolModifiersParams
64
+ modifiers?: ExecuteToolModifiers
65
): Promise<string> {
66
if (!this.getComposio()) {
67
throw new Error('Client not initialized');
@@ -82,7 +84,7 @@ export class VercelToolset extends BaseAgenticToolset<VercelToolCollection, Verc
84
return JSON.stringify(results);
85
}
86
85
- wrapTool(composioTool: ComposioTool, modifiers?: ExecuteToolModifiersParams): VercelTool {
87
+ wrapTool(composioTool: ComposioTool, modifiers?: ExecuteToolModifiers): VercelTool {
88
return tool({
89
description: composioTool.description,
90
parameters: jsonSchema(composioTool.inputParameters ?? {}),