Skip to content

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 modifiers

haxzie24f1b70f29ed
diff --git a/docs/advanced/modifiers.md b/docs/advanced/modifiers.md
index 57f4aa177..c2e5bc3ef 100644
--- a/docs/advanced/modifiers.md
+++ b/docs/advanced/modifiers.md
@@ -22,7 +22,7 @@ const tools = await composio.tools.get(
toolkits: ['github'],
},
{
- modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
// Add a prefix to all tool descriptions
if (tool.description) {
tool.description = `[Enhanced] ${tool.description}`;
@@ -59,7 +59,7 @@ const result = await composio.tools.execute(
},
},
{
- beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
// Convert owner names to lowercase
if (params.arguments.owner) {
params.arguments.owner = params.arguments.owner.toLowerCase();
@@ -95,7 +95,7 @@ const result = await composio.tools.execute(
},
},
{
- afterToolExecute: (toolSlug, toolkitSlug, result) => {
+ afterExecute: (toolSlug, toolkitSlug, result) => {
// Only when execution was successful
if (result.successful) {
// Filter out sensitive data
@@ -131,19 +131,19 @@ const tools = await composio.tools.get(
},
{
// Schema modifier
- modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
// Enhance tool schema
return tool;
},
// Before execution modifier
- beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
// Modify execution parameters
return params;
},
// After execution modifier
- afterToolExecute: (toolSlug, toolkitSlug, result) => {
+ afterExecute: (toolSlug, toolkitSlug, result) => {
// Transform execution results
return result;
},
@@ -192,8 +192,8 @@ const result = await composio.tools.execute(
},
},
{
- beforeToolExecute: sanitizeInputs,
- afterToolExecute: addTimestamps,
+ beforeExecute: sanitizeInputs,
+ afterExecute: addTimestamps,
}
);
```
@@ -253,8 +253,8 @@ try {
},
},
{
- beforeToolExecute: cacheModifier,
- afterToolExecute: cacheAfterModifier,
+ beforeExecute: cacheModifier,
+ afterExecute: cacheAfterModifier,
}
);
@@ -300,7 +300,7 @@ const tools = await composio.tools.get(
toolkits: ['custom-api'],
},
{
- beforeToolExecute: authModifier,
+ beforeExecute: authModifier,
}
);
```
@@ -362,7 +362,7 @@ const result = await composio.tools.execute(
},
},
{
- afterToolExecute: pipeModifiers(addMetadata, formatDates, removeNulls),
+ afterExecute: pipeModifiers(addMetadata, formatDates, removeNulls),
}
);
```
@@ -374,14 +374,14 @@ const result = await composio.tools.execute(
type TransformToolSchemaModifier = (toolSlug: string, toolkitSlug: string, tool: Tool) => Tool;
// Before Execution Modifier
-type BeforeToolExecuteModifier = (
+type beforeExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
params: ToolExecuteParams
) => ToolExecuteParams;
// After Execution Modifier
-type AfterToolExecuteModifier = (
+type afterExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
result: ToolExecuteResponse
@@ -389,14 +389,14 @@ type AfterToolExecuteModifier = (
// Modifiers Object
interface ExecuteToolModifiers {
- beforeToolExecute?: BeforeToolExecuteModifier;
- afterToolExecute?: AfterToolExecuteModifier;
+ beforeExecute?: beforeExecuteModifier;
+ afterExecute?: afterExecuteModifier;
}
// Provider Options (includes schema modifier)
interface ProviderOptions<TProvider> {
- modifyToolSchema?: TransformToolSchemaModifier;
- beforeToolExecute?: BeforeToolExecuteModifier;
- afterToolExecute?: AfterToolExecuteModifier;
+ modifySchema?: TransformToolSchemaModifier;
+ beforeExecute?: beforeExecuteModifier;
+ afterExecute?: afterExecuteModifier;
}
```
diff --git a/docs/api/providers.md b/docs/api/providers.md
index a2e662b67..cf9432477 100644
--- a/docs/api/providers.md
+++ b/docs/api/providers.md
@@ -102,8 +102,8 @@ const result = await openaiProvider.executeToolCall(
toolCall,
{ connectedAccountId: 'conn_abc123' },
{
- beforeToolExecute: (toolSlug, toolkitSlug, params) => params,
- afterToolExecute: (toolSlug, toolkitSlug, result) => result,
+ beforeExecute: (toolSlug, toolkitSlug, params) => params,
+ afterExecute: (toolSlug, toolkitSlug, result) => result,
}
);
```
@@ -262,8 +262,8 @@ interface ExecuteToolFnOptions {
```typescript
interface ExecuteToolModifiers {
- beforeToolExecute?: BeforeToolExecuteModifier;
- afterToolExecute?: AfterToolExecuteModifier;
+ beforeExecute?: beforeExecuteModifier;
+ afterExecute?: afterExecuteModifier;
}
```
@@ -273,20 +273,20 @@ interface ExecuteToolModifiers {
type TransformToolSchemaModifier = (toolSlug: string, toolkitSlug: string, tool: Tool) => Tool;
```
-### BeforeToolExecuteModifier
+### beforeExecuteModifier
```typescript
-type BeforeToolExecuteModifier = (
+type beforeExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
params: ToolExecuteParams
) => ToolExecuteParams;
```
-### AfterToolExecuteModifier
+### afterExecuteModifier
```typescript
-type AfterToolExecuteModifier = (
+type afterExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
result: ToolExecuteResponse
diff --git a/docs/api/tools.md b/docs/api/tools.md
index 1946f419c..e346f0880 100644
--- a/docs/api/tools.md
+++ b/docs/api/tools.md
@@ -12,13 +12,13 @@ Retrieves tools based on the provided filters.
// Get tools from a specific toolkit
const githubTools = await composio.tools.get('default', {
toolkits: ['github'],
- limit: 10
+ limit: 10,
});
// Get tools with search
const searchTools = await composio.tools.get('default', {
search: 'user',
- important: true
+ important: true,
});
// Get a specific tool by slug
@@ -26,10 +26,10 @@ const tool = await composio.tools.get('default', 'GITHUB_GET_REPO');
// Get a tool with schema modifications
const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
- modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
+ modifySchema: (toolSlug, toolkitSlug, schema) => {
// Customize the tool schema
- return {...schema, description: 'Custom description'};
- }
+ return { ...schema, description: 'Custom description' };
+ },
});
```
@@ -49,23 +49,27 @@ Executes a given tool with the provided parameters.
// Execute a Composio API tool
const result = await composio.tools.execute('HACKERNEWS_GET_USER', {
userId: 'default',
- arguments: { userId: 'pg' }
+ arguments: { userId: 'pg' },
});
// Execute with modifiers
-const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
- userId: 'default',
- arguments: { owner: 'composio', repo: 'sdk' }
-}, {
- beforeToolExecute: (toolSlug, toolkitSlug, params) => {
- // Modify params before execution
- return params;
+const result = await composio.tools.execute(
+ 'GITHUB_GET_ISSUES',
+ {
+ userId: 'default',
+ arguments: { owner: 'composio', repo: 'sdk' },
},
- afterToolExecute: (toolSlug, toolkitSlug, result) => {
- // Transform result after execution
- return result;
+ {
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
+ // Modify params before execution
+ return params;
+ },
+ afterExecute: (toolSlug, toolkitSlug, result) => {
+ // Transform result after execution
+ return result;
+ },
}
-});
+);
```
**Parameters:**
@@ -77,6 +81,7 @@ const result = await composio.tools.execute('GITHUB_GET_ISSUES', {
**Returns:** Promise<ToolExecuteResponse> - The response from the tool execution
**Throws:**
+
- `ComposioCustomToolsNotInitializedError`: If the CustomTools instance is not initialized
- `ComposioToolNotFoundError`: If the tool with the given slug is not found
- `ComposioToolExecutionError`: If there is an error during tool execution
@@ -94,19 +99,19 @@ const customTool = await composio.tools.createCustomTool({
param1: {
type: 'string',
description: 'First parameter',
- required: true
- }
+ required: true,
+ },
},
outputParameters: {
result: {
type: 'string',
- description: 'The result of the operation'
- }
+ description: 'The result of the operation',
+ },
},
handler: async (params, context) => {
// Custom logic here
return { data: { result: 'Success!' } };
- }
+ },
});
```
@@ -127,14 +132,16 @@ const tools = await composio.tools.getRawComposioTools('default');
// Get tools with filters
const githubTools = await composio.tools.getRawComposioTools('default', {
toolkits: ['github'],
- important: true
+ important: true,
});
// Get tools with schema transformation
-const tools = await composio.tools.getRawComposioTools('default', {},
+const tools = await composio.tools.getRawComposioTools(
+ 'default',
+ {},
(toolSlug, toolkitSlug, tool) => {
// Add custom properties to tool schema
- return {...tool, customProperty: 'value'};
+ return { ...tool, customProperty: 'value' };
}
);
```
@@ -169,12 +176,12 @@ const tool = await composio.tools.getRawComposioToolBySlug('default', 'github');
```typescript
interface ToolListParams {
- tools?: string[]; // List of tool slugs to filter by
- cursor?: string; // Pagination cursor
- important?: string; // Filter for important tools
- limit?: string; // Limit the number of results
- search?: string; // Search term
- toolkits?: string[]; // List of toolkit slugs to filter by
+ tools?: string[]; // List of tool slugs to filter by
+ cursor?: string; // Pagination cursor
+ important?: string; // Filter for important tools
+ limit?: string; // Limit the number of results
+ search?: string; // Search term
+ toolkits?: string[]; // List of toolkit slugs to filter by
}
```
@@ -182,13 +189,13 @@ interface ToolListParams {
```typescript
interface ToolExecuteParams {
- allowTracing?: boolean; // Enable/disable tracing
- connectedAccountId?: string; // Connected account ID
+ allowTracing?: boolean; // Enable/disable tracing
+ connectedAccountId?: string; // Connected account ID
customAuthParams?: CustomAuthParams; // Custom auth parameters
arguments?: Record<string, unknown>; // Tool arguments
- userId: string; // User ID
- version?: string; // Tool version
- text?: string; // Text input
+ userId: string; // User ID
+ version?: string; // Tool version
+ text?: string; // Text input
}
```
@@ -196,11 +203,11 @@ interface ToolExecuteParams {
```typescript
interface ToolExecuteResponse {
- data: Record<string, unknown>; // Tool execution data
- error: string | null; // Error message (if any)
- successful: boolean; // Whether the execution was successful
- logId?: string; // Log ID for debugging
- sessionInfo?: unknown; // Session information
+ data: Record<string, unknown>; // Tool execution data
+ error: string | null; // Error message (if any)
+ successful: boolean; // Whether the execution was successful
+ logId?: string; // Log ID for debugging
+ sessionInfo?: unknown; // Session information
}
```
@@ -208,11 +215,11 @@ interface ToolExecuteResponse {
```typescript
interface CustomToolOptions {
- name: string; // Name of the custom tool
- description: string; // Description of the custom tool
- slug: string; // Unique slug for the custom tool
+ name: string; // Name of the custom tool
+ description: string; // Description of the custom tool
+ slug: string; // Unique slug for the custom tool
inputParameters: Record<string, unknown>; // Input parameters schema
outputParameters?: Record<string, unknown>; // Output parameters schema
handler: (params: ToolExecuteParams, context: ExecuteMetadata) => Promise<ToolExecuteResponse>; // Handler function
}
-```
\ No newline at end of file
+```
diff --git a/docs/providers/openai.md b/docs/providers/openai.md
index 06d251589..ba0e3f4d2 100644
--- a/docs/providers/openai.md
+++ b/docs/providers/openai.md
@@ -285,7 +285,7 @@ const tools = await composio.tools.get(
},
{
// Modify tool schema
- modifyToolSchema: (toolSlug, toolkitSlug, tool) => {
+ modifySchema: (toolSlug, toolkitSlug, tool) => {
// Make tool descriptions more concise for OpenAI
if (tool.description && tool.description.length > 100) {
tool.description = tool.description.substring(0, 100) + '...';
@@ -294,13 +294,13 @@ const tools = await composio.tools.get(
},
// Modify parameters before execution
- beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
console.log(`Executing ${toolSlug} tool`);
return params;
},
// Transform results after execution
- afterToolExecute: (toolSlug, toolkitSlug, result) => {
+ afterExecute: (toolSlug, toolkitSlug, result) => {
// Format the result data for better presentation
if (result.successful && toolSlug === 'GITHUB_GET_REPO') {
result.data = {
diff --git a/examples/modifiers/src/index.ts b/examples/modifiers/src/index.ts
index df4d3c68a..af2e858b3 100644
--- a/examples/modifiers/src/index.ts
+++ b/examples/modifiers/src/index.ts
@@ -10,7 +10,7 @@ const composio = new Composio({
const tools = await composio.tools.get('default', 'HACKERNEWS_GET_USER', {
// toolkit slug too
- modifyToolSchema: (toolSlug, toolkitSlug, toolSchema) => {
+ modifySchema: (toolSlug, toolkitSlug, toolSchema) => {
if (toolSlug === 'HACKERNEWS_GET_USER') {
toolSchema = {
...toolSchema,
@@ -44,15 +44,15 @@ const agenticTools = await vercel.tools.get(
// what is the type error i am getting here?
{ tools: ['HACKERNEWS_GET_USER'] },
{
- afterToolExecute: (toolSlug, toolkitSlug, result) => {
+ afterExecute: (toolSlug, toolkitSlug, result) => {
// modify the result
return result;
},
- beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ beforeExecute: (toolSlug, toolkitSlug, params) => {
// modify the params
return params;
},
- modifyToolSchema: (toolSlug, toolkitSlug, toolSchema) => {
+ modifySchema: (toolSlug, toolkitSlug, toolSchema) => {
// modify the tool schema
return toolSchema;
},
diff --git a/packages/core/README.md b/packages/core/README.md
index ca2cec2d1..a7ad6f385 100644
--- a/packages/core/README.md
+++ b/packages/core/README.md
@@ -70,7 +70,7 @@ Schema modifiers allow you to transform tool schemas before they are used:
```typescript
const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
- modifyToolSchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
+ modifySchema: (toolSlug: string, toolkitSlug: string, tool: Tool) => ({
...tool,
description: 'Enhanced HackerNews search with additional features',
inputParameters: {
@@ -92,7 +92,7 @@ For agentic providers (like Vercel AI and Langchain), you can also modify tool e
```typescript
const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
// Transform input before execution
- beforeToolExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
+ beforeExecute: (toolSlug: string, toolkitSlug: string, params: ToolExecuteParams) => ({
...params,
arguments: {
...params.arguments,
@@ -101,7 +101,7 @@ const tools = await composio.tools.get('user123', 'HACKERNEWS_SEARCH_POSTS', {
}),
// Transform output after execution
- afterToolExecute: (toolSlug: string, toolkitSlug: string, response: ToolExecuteResponse) => ({
+ afterExecute: (toolSlug: string, toolkitSlug: string, response: ToolExecuteResponse) => ({
...response,
data: {
...response.data,
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 9d4a582fc..0ac839f59 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -18,6 +18,6 @@ export type {
AgenticToolOptions,
ToolOptions,
TransformToolSchemaModifier,
- BeforeToolExecuteModifier,
- AfterToolExecuteModifier,
+ beforeExecuteModifier,
+ afterExecuteModifier,
} from './types/modifiers.types';
diff --git a/packages/core/src/models/Tools.ts b/packages/core/src/models/Tools.ts
index 0b91efafa..c9fb5032f 100644
--- a/packages/core/src/models/Tools.ts
+++ b/packages/core/src/models/Tools.ts
@@ -385,7 +385,7 @@ export class Tools<
*
* // Get a tool with schema modifications
* const tool = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
- * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
+ * modifySchema: (toolSlug, toolkitSlug, schema) => {
* // Customize the tool schema
* return {...schema, description: 'Custom description'};
* }
@@ -416,11 +416,11 @@ export class Tools<
const executeToolFn = this.createExecuteToolFn(userId, options as ExecuteToolModifiers);
// if the first argument is a string, get a single tool
if (typeof arg2 === 'string') {
- const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifyToolSchema);
+ const tool = await this.getRawComposioToolBySlug(userId, arg2, options?.modifySchema);
return this.provider.wrapTools([tool], executeToolFn) as TToolCollection;
} else {
// if the first argument is an object, get a list of tools
- const tools = await this.getRawComposioTools(userId, arg2, options?.modifyToolSchema);
+ const tools = await this.getRawComposioTools(userId, arg2, options?.modifySchema);
return this.provider.wrapTools(tools, executeToolFn) as TToolCollection;
}
}
@@ -460,13 +460,11 @@ export class Tools<
body: ToolExecuteParams,
modifiers?: ExecuteToolModifiers
): Promise<ToolExecuteResponse> {
- if (modifiers?.beforeToolExecute) {
- if (typeof modifiers.beforeToolExecute === 'function') {
- body = modifiers.beforeToolExecute(tool.slug, 'unkown', body);
+ if (modifiers?.beforeExecute) {
+ if (typeof modifiers.beforeExecute === 'function') {
+ body = modifiers.beforeExecute(tool.slug, 'unkown', body);
} else {
- throw new ComposioInvalidModifierError(
- 'Invalid beforeToolExecute modifier. Not a function.'
- );
+ throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
}
}
@@ -475,13 +473,11 @@ export class Tools<
connectedAccountId: body.connectedAccountId,
});
- if (modifiers?.afterToolExecute) {
- if (typeof modifiers.afterToolExecute === 'function') {
- result = modifiers.afterToolExecute(tool.slug, 'unkown', result);
+ if (modifiers?.afterExecute) {
+ if (typeof modifiers.afterExecute === 'function') {
+ result = modifiers.afterExecute(tool.slug, 'unkown', result);
} else {
- throw new ComposioInvalidModifierError(
- 'Invalid afterToolExecute modifier. Not a function.'
- );
+ throw new ComposioInvalidModifierError('Invalid afterExecute modifier. Not a function.');
}
}
@@ -501,13 +497,11 @@ export class Tools<
body: ToolExecuteParams,
modifiers?: ExecuteToolModifiers
): Promise<ToolExecuteResponse> {
- if (modifiers?.beforeToolExecute) {
- if (typeof modifiers.beforeToolExecute === 'function') {
- body = modifiers.beforeToolExecute(tool.slug, tool.toolkit?.slug || 'unkown', body);
+ if (modifiers?.beforeExecute) {
+ if (typeof modifiers.beforeExecute === 'function') {
+ body = modifiers.beforeExecute(tool.slug, tool.toolkit?.slug || 'unkown', body);
} else {
- throw new ComposioInvalidModifierError(
- 'Invalid beforeToolExecute modifier. Not a function.'
- );
+ throw new ComposioInvalidModifierError('Invalid beforeExecute modifier. Not a function.');
}
}
// fetch connected accounts if doesn't exist
@@ -530,13 +524,11 @@ export class Tools<
result = this.transformToolExecuteResponse(result);
// apply local modifiers if they are provided
- if (modifiers?.afterToolExecute) {
- if (typeof modifiers.afterToolExecute === 'function') {
- result = modifiers.afterToolExecute(tool.slug, tool.toolkit?.slug || 'unkown', result);
+ if (modifiers?.afterExecute) {
+ if (typeof modifiers.afterExecute === 'function') {
+ result = modifiers.afterExecute(tool.slug, tool.toolkit?.slug || 'unkown', result);
} else {
- throw new ComposioInvalidModifierError(
- 'Invalid afterToolExecute modifier. Not a function.'
- );
+ throw new ComposioInvalidModifierError('Invalid afterExecute modifier. Not a function.');
}
}
return result;
@@ -570,11 +562,11 @@ export class Tools<
* userId: 'default',
* arguments: { owner: 'composio', repo: 'sdk' }
* }, {
- * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ * beforeExecute: (toolSlug, toolkitSlug, params) => {
* // Modify params before execution
* return params;
* },
- * afterToolExecute: (toolSlug, toolkitSlug, result) => {
+ * afterExecute: (toolSlug, toolkitSlug, result) => {
* // Transform result after execution
* return result;
* }
diff --git a/packages/core/src/telemetry/Telemetry.ts b/packages/core/src/telemetry/Telemetry.ts
index a9ecfd55e..ea271ee90 100644
--- a/packages/core/src/telemetry/Telemetry.ts
+++ b/packages/core/src/telemetry/Telemetry.ts
@@ -121,6 +121,10 @@ export class TelemetryService {
* @returns
*/
async sendTelemetry(payload: TelemetryPayload[]) {
+ if (!this.transport) {
+ return;
+ }
+
const isTelemetryDisabled = getEnvVariable('TELEMETRY_DISABLED', 'false') === 'true';
if (isTelemetryDisabled) {
diff --git a/packages/core/src/types/modifiers.types.ts b/packages/core/src/types/modifiers.types.ts
index 9422e3705..dd1173d5b 100644
--- a/packages/core/src/types/modifiers.types.ts
+++ b/packages/core/src/types/modifiers.types.ts
@@ -19,7 +19,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
* @example
* ```typescript
* // Add authentication headers to all tool requests
- * const beforeToolExecute = (toolSlug, toolkitSlug, params) => {
+ * const beforeExecute = (toolSlug, toolkitSlug, params) => {
* return {
* ...params,
* customAuthParams: {
@@ -33,7 +33,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
* };
*
* // Transform input parameters for a specific tool
- * const beforeToolExecute = (toolSlug, toolkitSlug, params) => {
+ * const beforeExecute = (toolSlug, toolkitSlug, params) => {
* if (toolSlug === 'GITHUB_SEARCH_REPOS') {
* // Convert simple query to structured query format
* return {
@@ -48,7 +48,7 @@ import { ToolExecuteParams, ToolExecuteResponse, Tool } from './tool.types';
* };
* ```
*/
-export type BeforeToolExecuteModifier = (
+export type beforeExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
toolExecuteParams: ToolExecuteParams
@@ -72,7 +72,7 @@ export type BeforeToolExecuteModifier = (
* @example
* ```typescript
* // Transform the response data format
- * const afterToolExecute = (toolSlug, toolkitSlug, response) => {
+ * const afterExecute = (toolSlug, toolkitSlug, response) => {
* if (toolSlug === 'GITHUB_LIST_REPOS' && response.successful) {
* // Transform the returned repos into a simpler format
* return {
@@ -90,7 +90,7 @@ export type BeforeToolExecuteModifier = (
* };
*
* // Add error handling with custom messages
- * const afterToolExecute = (toolSlug, toolkitSlug, response) => {
+ * const afterExecute = (toolSlug, toolkitSlug, response) => {
* if (!response.successful) {
* return {
* ...response,
@@ -104,7 +104,7 @@ export type BeforeToolExecuteModifier = (
* };
* ```
*/
-export type AfterToolExecuteModifier = (
+export type afterExecuteModifier = (
toolSlug: string,
toolkitSlug: string,
toolExecuteResponse: ToolExecuteResponse
@@ -128,7 +128,7 @@ export type AfterToolExecuteModifier = (
* @example
* ```typescript
* // Modify the input parameters for a specific tool
- * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
+ * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
* if (toolSlug === 'HACKERNEWS_GET_USER') {
* return {
* ...toolSchema,
@@ -146,7 +146,7 @@ export type AfterToolExecuteModifier = (
* };
*
* // Add custom descriptions to all tools in a toolkit
- * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
+ * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
* if (toolkitSlug === 'github') {
* return {
* ...toolSchema,
@@ -158,7 +158,7 @@ export type AfterToolExecuteModifier = (
* };
*
* // Simplify tool schemas for a specific consumer
- * const modifyToolSchema = (toolSlug, toolkitSlug, toolSchema) => {
+ * const modifySchema = (toolSlug, toolkitSlug, toolSchema) => {
* // Remove advanced or complex parameters
* const { complexParam1, complexParam2, ...simpleInputParams } = toolSchema.inputParameters;
*
@@ -187,7 +187,7 @@ export type TransformToolSchemaModifier = (
* const tools = await composio.tools.get('default', {
* toolkits: ['github']
* }, {
- * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
+ * modifySchema: (toolSlug, toolkitSlug, schema) => {
* // Custom schema modifications
* return schema;
* }
@@ -199,7 +199,7 @@ export type ToolOptions = {
* Function to transform tool schemas before they're exposed to consumers.
* This allows customizing input/output parameters, descriptions, and other metadata.
*/
- modifyToolSchema?: TransformToolSchemaModifier;
+ modifySchema?: TransformToolSchemaModifier;
};
/**
@@ -216,11 +216,11 @@ export type ToolOptions = {
* userId: 'default',
* arguments: { owner: 'composio' }
* }, {
- * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ * beforeExecute: (toolSlug, toolkitSlug, params) => {
* console.log(`Executing ${toolSlug} from ${toolkitSlug}`);
* return params;
* },
- * afterToolExecute: (toolSlug, toolkitSlug, response) => {
+ * afterExecute: (toolSlug, toolkitSlug, response) => {
* if (response.successful) {
* console.log(`Successfully executed ${toolSlug}`);
* }
@@ -234,13 +234,13 @@ export type ExecuteToolModifiers = {
* Function to intercept and modify tool execution parameters before the tool is executed.
* This allows customizing the request based on tool-specific needs.
*/
- beforeToolExecute?: BeforeToolExecuteModifier;
+ beforeExecute?: beforeExecuteModifier;
/**
* Function to intercept and modify tool execution responses after the tool has executed.
* This allows transforming the response or implementing custom error handling.
*/
- afterToolExecute?: AfterToolExecuteModifier;
+ afterExecute?: afterExecuteModifier;
};
/**
@@ -254,7 +254,7 @@ export type ExecuteToolModifiers = {
* ```typescript
* // Configure agentic tools with schema and execution modifications
* const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
- * modifyToolSchema: (toolSlug, toolkitSlug, schema) => {
+ * modifySchema: (toolSlug, toolkitSlug, schema) => {
* return {
* ...schema,
* description: `Enhanced ${toolSlug} for better context`
@@ -262,14 +262,14 @@ export type ExecuteToolModifiers = {
* },
*
* // Intercept before execution
- * beforeToolExecute: (toolSlug, toolkitSlug, params) => {
+ * beforeExecute: (toolSlug, toolkitSlug, params) => {
* // Add analytics tracking
* trackToolUsage(toolSlug);
* return params;
* },
*
* // Transform after execution
- * afterToolExecute: (toolSlug, toolkitSlug, response) => {
+ * afterExecute: (toolSlug, toolkitSlug, response) => {
* // Log results and handle errors
* if (!response.successful) {
* logToolError(toolSlug, response.error);
@@ -293,7 +293,7 @@ export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
* ```typescript
* // With standard provider (non-agentic)
* const tools = await composio.tools.get('default', 'GITHUB_GET_REPOS', {
- * modifyToolSchema: (toolSlug, toolkitSlug, schema) => schema
+ * modifySchema: (toolSlug, toolkitSlug, schema) => schema
* });
*
* // With agentic provider (e.g., VercelProvider)
@@ -303,9 +303,9 @@ export type AgenticToolOptions = ToolOptions & ExecuteToolModifiers;
* });
*
* const agenticTools = await vercel.tools.get('default', 'GITHUB_GET_REPOS', {
- * modifyToolSchema: (toolSlug, toolkitSlug, schema) => schema,
- * beforeToolExecute: (toolSlug, toolkitSlug, params) => params,
- * afterToolExecute: (toolSlug, toolkitSlug, response) => response
+ * modifySchema: (toolSlug, toolkitSlug, schema) => schema,
+ * beforeExecute: (toolSlug, toolkitSlug, params) => params,
+ * afterExecute: (toolSlug, toolkitSlug, response) => response
* });
* ```
*/
diff --git a/packages/core/test/provider/openai-provider.test.ts b/packages/core/test/provider/openai-provider.test.ts
index 4e15dc110..e13f5385a 100644
--- a/packages/core/test/provider/openai-provider.test.ts
+++ b/packages/core/test/provider/openai-provider.test.ts
@@ -124,15 +124,15 @@ describe('OpenAIProvider', () => {
},
};
- // Create a valid ExecuteToolModifiers object with beforeToolExecute and afterToolExecute functions
+ // Create a valid ExecuteToolModifiers object with beforeExecute and afterExecute functions
const modifiers: ExecuteToolModifiers = {
- beforeToolExecute: vi.fn((toolSlug, toolkitSlug, params) => {
+ beforeExecute: vi.fn((toolSlug, toolkitSlug, params) => {
return {
...params,
allowTracing: true,
};
}),
- afterToolExecute: vi.fn((toolSlug, toolkitSlug, response) => {
+ afterExecute: vi.fn((toolSlug, toolkitSlug, response) => {
return response;
}),
};
diff --git a/packages/core/test/provider/provider.test.ts b/packages/core/test/provider/provider.test.ts
index acbbbf4e9..c291b4929 100644
--- a/packages/core/test/provider/provider.test.ts
+++ b/packages/core/test/provider/provider.test.ts
@@ -110,8 +110,8 @@ describe('BaseProvider', () => {
arguments: { query: 'test' },
};
const modifiers = {
- beforeToolExecute: vi.fn(x => x),
- afterToolExecute: vi.fn(x => x),
+ beforeExecute: vi.fn(x => x),
+ afterExecute: vi.fn(x => x),
};
const result = await nonAgenticProvider.executeTool(toolSlug, toolParams, modifiers);
@@ -209,8 +209,8 @@ describe('BaseProvider', () => {
arguments: { query: 'test' },
};
const modifiers = {
- beforeToolExecute: vi.fn(x => x),
- afterToolExecute: vi.fn(x => x),
+ beforeExecute: vi.fn(x => x),
+ afterExecute: vi.fn(x => x),
};
const result = await agenticProvider.executeTool(toolSlug, toolParams, modifiers);
diff --git a/packages/core/test/tools/modifiers.test.ts b/packages/core/test/tools/modifiers.test.ts
index 659da7511..91b81345d 100644
--- a/packages/core/test/tools/modifiers.test.ts
+++ b/packages/core/test/tools/modifiers.test.ts
@@ -62,24 +62,24 @@ describe('Tools Modifiers', () => {
});
describe('Execution Modifiers', () => {
- it('should apply beforeToolExecute modifier before executing a tool', async () => {
+ it('should apply beforeExecute modifier before executing a tool', async () => {
const slug = 'COMPOSIO_TOOL';
const body = {
userId: 'test-user',
arguments: { limit: 5 },
};
- const { beforeToolExecute } = createExecutionModifiers({
+ const { beforeExecute } = createExecutionModifiers({
beforeModifications: {
arguments: { limit: 10 },
},
});
await mockToolExecution(context.tools);
- await context.tools.execute(slug, body, { beforeToolExecute });
+ await context.tools.execute(slug, body, { beforeExecute });
- expect(beforeToolExecute).toHaveBeenCalledTimes(1);
- expect(beforeToolExecute).toHaveBeenCalledWith(slug, expect.any(String), body);
+ expect(beforeExecute).toHaveBeenCalledTimes(1);
+ expect(beforeExecute).toHaveBeenCalledWith(slug, expect.any(String), body);
expect(mockClient.tools.execute).toHaveBeenCalledWith(
slug,
expect.objectContaining({
@@ -88,21 +88,21 @@ describe('Tools Modifiers', () => {
);
});
- it('should apply afterToolExecute modifier after executing a tool', async () => {
+ it('should apply afterExecute modifier after executing a tool', async () => {
const slug = 'COMPOSIO_TOOL';
const body = { userId: 'test-user', arguments: {} };
- const { afterToolExecute } = createExecutionModifiers({
+ const { afterExecute } = createExecutionModifiers({
afterModifications: {
data: { enhanced: true },
},
});
await mockToolExecution(context.tools);
- const result = await context.tools.execute(slug, body, { afterToolExecute });
+ const result = await context.tools.execute(slug, body, { afterExecute });
- expect(afterToolExecute).toHaveBeenCalledTimes(1);
- expect(afterToolExecute).toHaveBeenCalledWith(
+ expect(afterExecute).toHaveBeenCalledTimes(1);
+ expect(afterExecute).toHaveBeenCalledWith(
slug,
expect.any(String),
expect.objectContaining({
@@ -134,7 +134,7 @@ describe('Tools Modifiers', () => {
const createExecuteToolFnSpy = vi.spyOn(context.tools as any, 'createExecuteToolFn');
await context.tools.get(userId, slug, {
- modifyToolSchema: schemaModifier,
+ modifySchema: schemaModifier,
...executionModifiers,
});
diff --git a/packages/core/test/tools/tools.test.ts b/packages/core/test/tools/tools.test.ts
index 4d765408c..3afc1be12 100644
--- a/packages/core/test/tools/tools.test.ts
+++ b/packages/core/test/tools/tools.test.ts
@@ -243,7 +243,7 @@ describe('Tools', () => {
toolMocks.transformedTool as unknown as Tool
);
- await context.tools.get(userId, slug, { modifyToolSchema: schemaModifier });
+ await context.tools.get(userId, slug, { modifySchema: schemaModifier });
expect(getRawComposioToolBySlugSpy).toHaveBeenCalledWith(userId, slug, schemaModifier);
});
diff --git a/packages/core/test/utils/toolExecuteUtils.ts b/packages/core/test/utils/toolExecuteUtils.ts
index 375c05490..fda940194 100644
--- a/packages/core/test/utils/toolExecuteUtils.ts
+++ b/packages/core/test/utils/toolExecuteUtils.ts
@@ -84,11 +84,11 @@ export const createExecutionModifiers = ({
afterModifications = {},
} = {}) => {
return {
- beforeToolExecute: vi.fn((toolSlug: string, toolkitSlug: string, params: any) => ({
+ beforeExecute: vi.fn((toolSlug: string, toolkitSlug: string, params: any) => ({
...params,
...beforeModifications,
})),
- afterToolExecute: vi.fn((toolSlug: string, toolkitSlug: string, response: any) => ({
+ afterExecute: vi.fn((toolSlug: string, toolkitSlug: string, response: any) => ({
...response,
...afterModifications,
})),
diff --git a/packages/providers/README.md b/packages/providers/README.md
index 56158be15..69ef3ddb9 100644
--- a/packages/providers/README.md
+++ b/packages/providers/README.md
@@ -46,11 +46,11 @@ These providers support full modifier capabilities, making them suitable for com
1. **Schema Modifiers**: Transform tool schemas using `TransformToolSchemaModifier`
2. **Execution Modifiers**: Transform tool execution behavior
- - `beforeToolExecute`: Transform input parameters before execution
- - `afterToolExecute`: Transform output after execution
+ - `beforeExecute`: Transform input parameters before execution
+ - `afterExecute`: Transform output after execution
3. **Execute Modifiers**: Used during tool execution
- - `beforeToolExecute`: Transform input parameters
- - `afterToolExecute`: Transform output
+ - `beforeExecute`: Transform input parameters
+ - `afterExecute`: Transform output
Example implementation:
@@ -91,17 +91,17 @@ export class AgenticProvider extends BaseAgenticProvider {
): Promise<ToolExecuteResponse> {
let executeParams = params;
- // Apply beforeToolExecute modifier if provided
- if (modifiers?.beforeToolExecute) {
- executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
+ // Apply beforeExecute modifier if provided
+ if (modifiers?.beforeExecute) {
+ executeParams = modifiers.beforeExecute(tool.slug, executeParams);
}
// Execute the tool
const response = await this.client.executeTool(tool.slug, executeParams);
- // Apply afterToolExecute modifier if provided
- if (modifiers?.afterToolExecute) {
- return modifiers.afterToolExecute(tool.slug, response.data);
+ // Apply afterExecute modifier if provided
+ if (modifiers?.afterExecute) {
+ return modifiers.afterExecute(tool.slug, response.data);
}
return response.data;
@@ -191,12 +191,12 @@ type TransformToolSchemaModifier = (toolSlug: string, tool: Tool) => Tool;
```typescript
type ModifiersParams = {
schema?: TransformToolSchemaModifier;
- beforeToolExecute?: BeforeToolExecuteModifier;
- afterToolExecute?: AfterToolExecuteModifier;
+ beforeExecute?: beforeExecuteModifier;
+ afterExecute?: afterExecuteModifier;
};
-type BeforeToolExecuteModifier = (toolSlug: string, params: ToolExecuteParams) => ToolExecuteParams;
-type AfterToolExecuteModifier = (
+type beforeExecuteModifier = (toolSlug: string, params: ToolExecuteParams) => ToolExecuteParams;
+type afterExecuteModifier = (
toolSlug: string,
response: ToolExecuteResponse
) => ToolExecuteResponse;
@@ -284,17 +284,17 @@ export class VercelProvider extends BaseAgenticProvider {
): Promise<ToolExecuteResponse> {
let executeParams = params;
- // Apply beforeToolExecute modifier if provided
- if (modifiers?.beforeToolExecute) {
- executeParams = modifiers.beforeToolExecute(tool.slug, executeParams);
+ // Apply beforeExecute modifier if provided
+ if (modifiers?.beforeExecute) {
+ executeParams = modifiers.beforeExecute(tool.slug, executeParams);
}
// Execute the tool
const response = await this.client.executeTool(tool.slug, executeParams);
- // Apply afterToolExecute modifier if provided
- if (modifiers?.afterToolExecute) {
- return modifiers.afterToolExecute(tool.slug, response.data);
+ // Apply afterExecute modifier if provided
+ if (modifiers?.afterExecute) {
+ return modifiers.afterExecute(tool.slug, response.data);
}
return response.data;
@@ -359,14 +359,14 @@ const tool = await composio.getToolBySlug('HACKERNEWS_SEARCH_POSTS', {
},
}),
// Execution modifiers
- beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
+ beforeExecute: (toolSlug: string, params: ToolExecuteParams) => ({
...params,
arguments: {
...params.arguments,
limit: Math.min((params.arguments?.limit as number) || 10, 100),
},
}),
- afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
+ afterExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
...response,
data: {
...response.data,
@@ -385,14 +385,14 @@ const result = await composio.provider.executeTool(
arguments: { query: 'AI', limit: 20 },
},
{
- beforeToolExecute: (toolSlug: string, params: ToolExecuteParams) => ({
+ beforeExecute: (toolSlug: string, params: ToolExecuteParams) => ({
...params,
arguments: {
...params.arguments,
limit: Math.min((params.arguments?.limit as number) || 10, 100),
},
}),
- afterToolExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
+ afterExecute: (toolSlug: string, response: ToolExecuteResponse) => ({
...response,
data: {
...response.data,
diff --git a/packages/providers/cloudflare/test/cloudflare.test.ts b/packages/providers/cloudflare/test/cloudflare.test.ts
index 813dc15a4..0aa13cdec 100644
--- a/packages/providers/cloudflare/test/cloudflare.test.ts
+++ b/packages/providers/cloudflare/test/cloudflare.test.ts
@@ -240,8 +240,8 @@ describe('CloudflareProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeToolCall(userId, toolCall, options, modifiers);
@@ -285,8 +285,8 @@ describe('CloudflareProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeTool(toolSlug, toolParams, modifiers);
diff --git a/packages/providers/langchain/test/langchain.test.ts b/packages/providers/langchain/test/langchain.test.ts
index f9352fd63..30625367f 100644
--- a/packages/providers/langchain/test/langchain.test.ts
+++ b/packages/providers/langchain/test/langchain.test.ts
@@ -212,8 +212,8 @@ describe('LangchainProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeTool(toolSlug, toolParams, modifiers);
diff --git a/packages/providers/openai/test/openai.test.ts b/packages/providers/openai/test/openai.test.ts
index d8de60eb4..36d83ae99 100644
--- a/packages/providers/openai/test/openai.test.ts
+++ b/packages/providers/openai/test/openai.test.ts
@@ -214,8 +214,8 @@ describe('OpenAIProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeToolCall(userId, toolCall, options, modifiers);
@@ -445,8 +445,8 @@ describe('OpenAIProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeTool(toolSlug, toolParams, modifiers);
diff --git a/packages/providers/vercel/test/vercel.test.ts b/packages/providers/vercel/test/vercel.test.ts
index 9456e6b35..5fd63ded5 100644
--- a/packages/providers/vercel/test/vercel.test.ts
+++ b/packages/providers/vercel/test/vercel.test.ts
@@ -187,8 +187,8 @@ describe('VercelProvider', () => {
};
const modifiers = {
- beforeToolExecute: vi.fn(params => params),
- afterToolExecute: vi.fn(response => response),
+ beforeExecute: vi.fn(params => params),
+ afterExecute: vi.fn(response => response),
};
await provider.executeTool(toolSlug, toolParams, modifiers);