Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
docs: update modifiers documentation to explain provider-specific limitations (#14)
Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com> Co-authored-by: musthaq@composio.dev <musthu.gm@gmail.com>
devin-ai-integration[bot] committed
May 24, 2025 at 12:18 UTC
e45516ba845704c6170c9873fd58ee8f06d56540
1 file changed
+217
-13
docs/advanced/modifiers.md
+217
-13
@@ -2,13 +2,15 @@
2
3
Composio SDK provides powerful middleware capabilities through modifiers that allow you to customize and extend the behavior of tools. This guide explains how to use modifiers to transform tool schemas, modify inputs before execution, and transform outputs after execution.
4
5
+> **Important:** Not all modifiers are supported by all provider types. Schema modifiers work with all providers, but execution modifiers (beforeExecute and afterExecute) are only supported by agentic providers. See the [Provider-Specific Modifier Support](#provider-specific-modifier-support) section for details.
6
+
7
## What are Modifiers?
8
9
Modifiers are functions that intercept and modify the normal flow of tool operations. Composio supports three types of modifiers:
10
9
-1. **Schema Modifiers**: Transform a tool's schema before it's wrapped for the provider
10
-2. **Before Execution Modifiers**: Modify inputs before a tool is executed
11
-3. **After Execution Modifiers**: Transform outputs after a tool has executed
11
+1. **Schema Modifiers**: Transform a tool's schema before it's wrapped for the provider (supported by all providers)
12
+2. **Before Execution Modifiers**: Modify inputs before a tool is executed (supported by agentic providers only)
13
+3. **After Execution Modifiers**: Transform outputs after a tool has executed (supported by agentic providers only)
14
15
### Schema Modifiers
16
@@ -121,9 +123,17 @@ const result = await composio.tools.execute(
123
124
### Using Multiple Modifiers
125
124
-You can use all three types of modifiers together:
126
+You can use multiple modifiers together, but remember that execution modifiers (beforeExecute and afterExecute) only work with agentic providers:
127
128
```typescript
129
+// With an agentic provider (e.g., Vercel, Langchain)
130
+const agenticProvider = new VercelProvider();
131
+const composio = new Composio({
132
+ apiKey: 'your-api-key',
133
+ provider: agenticProvider,
134
+});
135
+
136
+// All modifiers work with agentic providers
137
const tools = await composio.tools.get(
138
'default',
139
{
@@ -136,19 +146,45 @@ const tools = await composio.tools.get(
146
return tool;
147
},
148
139
- // Before execution modifier
149
+ // Before execution modifier (only works with agentic providers)
150
beforeExecute: (toolSlug, toolkitSlug, params) => {
151
// Modify execution parameters
152
return params;
153
},
154
145
- // After execution modifier
155
+ // After execution modifier (only works with agentic providers)
156
afterExecute: (toolSlug, toolkitSlug, result) => {
157
// Transform execution results
158
return result;
159
},
160
}
161
);
162
+
163
+// With a non-agentic provider (e.g., OpenAI)
164
+const nonAgenticProvider = new OpenAIProvider();
165
+const composioNonAgentic = new Composio({
166
+ apiKey: 'your-api-key',
167
+ provider: nonAgenticProvider,
168
+});
169
+
170
+// Only schema modifiers work with non-agentic providers
171
+const openaiTools = await composioNonAgentic.tools.get(
172
+ 'default',
173
+ {
174
+ toolkits: ['github'],
175
+ },
176
+ {
177
+ // Schema modifier (works with all providers)
178
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
179
+ // Enhance tool schema
180
+ return tool;
181
+ },
182
+
183
+ // These will be ignored by non-agentic providers
184
+ beforeExecute: () => {}, // No effect with non-agentic providers
185
+ afterExecute: () => {}, // No effect with non-agentic providers
186
+ }
187
+);
188
```
189
190
## Creating Reusable Modifiers
@@ -200,7 +236,98 @@ const result = await composio.tools.execute(
236
237
## Practical Use Cases
238
203
-### Caching Tool Results
239
+### Comparing Agentic and Non-Agentic Provider Usage
240
+
241
+Here's a side-by-side comparison of how to use modifiers with different provider types:
242
+
243
+```typescript
244
+// Example from examples/modifiers/src/index.ts
245
+
246
+// Non-agentic provider example (OpenAI)
247
+const openai = new Composio({
248
+ apiKey: process.env.COMPOSIO_API_KEY,
249
+ provider: new OpenAIProvider(),
250
+});
251
+
252
+// Schema modifiers work with non-agentic providers
253
+const nonAgenticTools = await openai.tools.get(
254
+ 'default',
255
+ 'HACKERNEWS_GET_USER',
256
+ {
257
+ // Schema modifier works with all providers
258
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
259
+ // Customize the input parameters
260
+ if (tool.inputParameters?.properties?.userId) {
261
+ tool.inputParameters.properties.userId.description = 'HackerNews username (e.g., "pg")';
262
+ }
263
+ return tool;
264
+ },
265
+ }
266
+);
267
+
268
+// Agentic provider example (Vercel)
269
+const vercel = new Composio({
270
+ apiKey: process.env.COMPOSIO_API_KEY,
271
+ provider: new VercelProvider(),
272
+});
273
+
274
+// All modifiers work with agentic providers
275
+const agenticTools = await vercel.tools.get(
276
+ 'default',
277
+ 'HACKERNEWS_GET_USER',
278
+ {
279
+ // Schema modifier
280
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
281
+ if (tool.inputParameters?.properties?.userId) {
282
+ tool.inputParameters.properties.userId.description = 'HackerNews username (e.g., "pg")';
283
+ }
284
+ return tool;
285
+ },
286
+ // Execution modifiers (only work with agentic providers)
287
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
288
+ console.log(`Executing ${toolSlug} from ${toolkitSlug}`);
289
+ return params;
290
+ },
291
+ afterExecute: (toolSlug, toolkitSlug, result) => {
292
+ if (result.successful) {
293
+ result.data.processedAt = new Date().toISOString();
294
+ }
295
+ return result;
296
+ },
297
+ }
298
+);
299
+```
300
+
301
+### Manual Execution Modifiers with Non-Agentic Providers
302
+
303
+For non-agentic providers, you can use the provider's helper methods to apply execution modifiers:
304
+
305
+```typescript
306
+// Get the OpenAI provider instance
307
+const openaiProvider = composio.provider as OpenAIProvider;
308
+
309
+// When handling a tool call from OpenAI
310
+const toolOutputs = await openaiProvider.handleToolCall(
311
+ 'default', // userId
312
+ completion, // OpenAI completion object
313
+ { connectedAccountId: 'account_123' }, // Options
314
+ {
315
+ // Manually apply execution modifiers
316
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
317
+ console.log(`Executing ${toolSlug}`);
318
+ return params;
319
+ },
320
+ afterExecute: (toolSlug, toolkitSlug, result) => {
321
+ result.data.processedAt = new Date().toISOString();
322
+ return result;
323
+ }
324
+ }
325
+);
326
+```
327
+
328
+### Caching Tool Results (Agentic Providers Only)
329
+
330
+> Note: This example uses execution modifiers and will only work with agentic providers.
331
332
```typescript
333
// Simple in-memory cache
@@ -367,20 +494,97 @@ const result = await composio.tools.execute(
494
);
495
```
496
497
+## Provider-Specific Modifier Support
498
+
499
+Composio SDK supports two types of providers:
500
+
501
+1. **Agentic Providers**: Providers that have control over tool execution (e.g., Vercel, Langchain)
502
+2. **Non-Agentic Providers**: Providers that only format tools but don't control execution (e.g., OpenAI)
503
+
504
+### Technical Differences
505
+
506
+The key technical distinction between these provider types affects which modifiers they support:
507
+
508
+- **Agentic Providers** receive an `ExecuteToolFn` parameter in their `wrapTool`/`wrapTools` methods, allowing them to embed execution modifiers directly into the wrapped tools. This means they support all three types of modifiers: schema, beforeExecute, and afterExecute.
509
+
510
+- **Non-Agentic Providers** only format tools for external consumption and don't control execution. When tools are wrapped by non-agentic providers, the context is lost, making it impossible to automatically apply execution modifiers. These providers only support schema modifiers.
511
+
512
+Here's how the provider implementations differ:
513
+
514
+```typescript
515
+// Non-Agentic Provider (e.g., OpenAI)
516
+class OpenAIProvider extends BaseNonAgenticProvider<OpenAiToolCollection, OpenAiTool> {
517
+ // No executeToolFn parameter
518
+ override wrapTool(tool: Tool): OpenAiTool {
519
+ // Simply formats the tool for OpenAI
520
+ return {
521
+ type: 'function',
522
+ function: {
523
+ name: tool.slug,
524
+ description: tool.description,
525
+ parameters: tool.inputParameters,
526
+ },
527
+ };
528
+ }
529
+}
530
+
531
+// Agentic Provider (e.g., Vercel)
532
+class VercelProvider extends BaseAgenticProvider<VercelToolCollection, VercelTool> {
533
+ // Receives executeToolFn parameter
534
+ wrapTool(tool: Tool, executeTool: ExecuteToolFn): VercelTool {
535
+ return tool({
536
+ description: tool.description,
537
+ parameters: jsonSchema(tool.inputParameters ?? {}),
538
+ execute: async params => {
539
+ // Can apply modifiers through executeTool
540
+ return await executeTool(tool.slug, params);
541
+ },
542
+ });
543
+ }
544
+}
545
+```
546
+
547
+### Using Modifiers with Non-Agentic Providers
548
+
549
+For non-agentic providers like OpenAI, you can still apply execution modifiers manually using the provider's helper methods:
550
+
551
+```typescript
552
+// Get OpenAI provider instance
553
+const openaiProvider = composio.provider as OpenAIProvider;
554
+
555
+// Execute a tool call with modifiers
556
+const result = await openaiProvider.executeToolCall(
557
+ 'default', // userId
558
+ toolCall, // OpenAI tool call object
559
+ { connectedAccountId: 'account_123' }, // Options
560
+ {
561
+ // Manually apply execution modifiers
562
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
563
+ console.log(`Executing ${toolSlug}`);
564
+ return params;
565
+ },
566
+ afterExecute: (toolSlug, toolkitSlug, result) => {
567
+ result.data.processedAt = new Date().toISOString();
568
+ return result;
569
+ }
570
+ }
571
+);
572
+```
573
+
574
## Type Definitions
575
576
```typescript
373
-// Schema Modifier
577
+// Schema Modifier (supported by all providers)
578
type TransformToolSchemaModifier = (toolSlug: string, toolkitSlug: string, tool: Tool) => Tool;
579
376
-// Before Execution Modifier
580
+// Before Execution Modifier (supported by agentic providers only)
581
type beforeExecuteModifier = (
582
toolSlug: string,
583
toolkitSlug: string,
584
params: ToolExecuteParams
585
) => ToolExecuteParams;
586
383
-// After Execution Modifier
587
+// After Execution Modifier (supported by agentic providers only)
588
type afterExecuteModifier = (
589
toolSlug: string,
590
toolkitSlug: string,
@@ -393,10 +597,10 @@ interface ExecuteToolModifiers {
597
afterExecute?: afterExecuteModifier;
598
}
599
396
-// Provider Options (includes schema modifier)
600
+// Provider Options
601
interface ProviderOptions<TProvider> {
602
modifySchema?: TransformToolSchemaModifier;
399
- beforeExecute?: beforeExecuteModifier;
400
- afterExecute?: afterExecuteModifier;
603
+ beforeExecute?: beforeExecuteModifier; // Only applied by agentic providers
604
+ afterExecute?: afterExecuteModifier; // Only applied by agentic providers
605
}
606
```