Custom Tools
Custom tools allow you to extend the Composio SDK with your own implementations while maintaining a consistent interface with built-in tools. Create custom logic, wrap external APIs, or build specialized functionality tailored to your use case.Overview
TheCustomTools class manages user-created tools that can be registered, retrieved, and executed alongside Composio’s built-in tools. Custom tools are stored in an in-memory registry and support the same execution patterns as native tools.
Source: ts/packages/core/src/models/CustomTools.ts
Creating Custom Tools
Basic Custom Tool
Create a simple custom tool without external dependencies:Custom Tool with Optional Parameters
Custom Tools with Toolkit Integration
Create custom tools that leverage existing toolkit credentials:When a
toolkitSlug is provided, the custom tool can access authentication credentials from connected accounts and use executeToolRequest to make authenticated API calls.Execute Function Parameters
Theexecute function receives three parameters:
1. Input (parsed and validated)
The input parameters after Zod schema validation:2. Connection Config (nullable)
Authentication credentials when using a toolkit:3. Execute Tool Request (function)
Make authenticated API calls to the toolkit:executeToolRequest is only available when toolkitSlug is specified and is not ‘custom’. It provides a proxy to make authenticated requests using the connected account’s credentials.Retrieving Custom Tools
Get All Custom Tools
Get Specific Custom Tools
Get a Single Custom Tool
Executing Custom Tools
Custom tools can be executed using the same API as built-in tools:Integration with Provider Tools
Custom tools work seamlessly with Composio providers:Custom Tool Schema Generation
The SDK automatically generates JSON Schema from Zod schemas:Error Handling in Custom Tools
Complete Example: Custom Slack Tool
Custom Tool Properties
Registered custom tools have the same properties as built-in tools:slug- Unique identifiername- Human-readable namedescription- Tool descriptioninputParameters- JSON Schema for input (auto-generated from Zod)outputParameters- JSON Schema for outputtoolkit- Always set to{ name: 'custom', slug: 'custom' }unlesstoolkitSlugis specifiedtags- Empty array (can be customized in future versions)
Limitations and Considerations
In-Memory Registry: Custom tools are stored in memory and are not persisted. You need to re-register them when creating a new Composio instance.
- Custom tools are scoped to the Composio instance
- The
toolkitSlugin custom tools is used for authentication, not for categorization - When using
executeToolRequest, the toolkit must not be ‘custom’ - Input validation is automatic via Zod schemas
- Output schema is currently a placeholder (future enhancement)
Error Handling
Common errors when working with custom tools:ComposioToolNotFoundError- Custom tool not found in registryComposioInvalidExecuteFunctionError- Invalid or missing execute functionComposioConnectedAccountNotFoundError- No connected account for specified toolkitValidationError- Input parameters don’t match Zod schema
Best Practices
- Use descriptive slugs: Make tool slugs clear and unique (e.g.,
COMPANY_ACTION_OBJECT) - Provide detailed descriptions: Help AI models understand when to use your tool
- Validate inputs thoroughly: Use Zod’s rich validation features
- Handle errors gracefully: Return structured errors in the response
- Document parameters: Use
.describe()on all Zod fields - Keep tools focused: Each tool should do one thing well
- Reuse toolkit credentials: Leverage existing connections when possible
Related Resources
- Tools - Working with built-in tools
- Toolkits - Understanding toolkit integration
- Connected Accounts - Using credentials in custom tools
- Providers - Integrating custom tools with AI frameworks