Overview
In this example, you’ll learn how to:- Create custom tools with Zod schemas
- Integrate custom tools with existing toolkits
- Access authentication credentials in custom tools
- Execute HTTP requests within custom tool logic
- Use custom tools in your applications
Prerequisites
Complete Example
How It Works
Define Tool Schema
Use Zod to define the input parameters for your tool. Each parameter should have a description for better AI understanding.
Specify Toolkit Integration
By setting
toolkitSlug: 'github', the custom tool inherits GitHub’s authentication and can make authenticated API calls.Implement Execute Function
The execute function receives three parameters:
input: The validated input parametersconnectionConfig: Authentication credentials for the toolkitexecuteToolRequest: Helper function to make authenticated HTTP requests
Make API Requests
Use
executeToolRequest to make authenticated requests to the toolkit’s API. It automatically handles authentication headers.Execute Function Parameters
The validated input parameters matching your Zod schema
Authentication credentials and configuration for the associated toolkit
Helper function to make authenticated HTTP requests
Expected Output
Creating Standalone Custom Tools
You can also create custom tools without toolkit integration:Use Cases
Custom Business Logic
Wrap your internal APIs and business logic as tools for AI agents
API Extensions
Extend existing toolkit capabilities with custom endpoints
Data Transformations
Create tools that transform or aggregate data from multiple sources
Validation & Processing
Add custom validation or preprocessing before calling external APIs
Best Practices
Descriptive Schemas
Descriptive Schemas
Always add clear descriptions to your Zod schema fields. These descriptions help AI models understand how to use your tool correctly.
Error Handling
Error Handling
Always return a consistent result format with
successful, data, and error fields to make error handling predictable.Toolkit Integration
Toolkit Integration
Use
toolkitSlug when your tool needs to authenticate with an existing service. This provides automatic credential management.Next Steps
File Handling
Learn how to handle file uploads in tools
OpenAI Example
Use custom tools with OpenAI