crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
96 lines • 2.4 kB
TypeScript
/**
* Custom Tool Factory
* Provides a flexible framework for creating and extending tools
* with proper typing, validation, and performance optimizations
*/
import { z } from 'zod';
import { BaseTool } from '../BaseTool.js';
/**
* Interface for custom tool options
*/
export interface CustomToolOptions<TInput = any, TOutput = any> {
/**
* Name of the tool
*/
name: string;
/**
* Description of the tool functionality
*/
description: string;
/**
* Input schema for validation
*/
inputSchema: z.ZodType<TInput>;
/**
* Function to execute when the tool is called
*/
execute: (input: TInput) => Promise<TOutput>;
/**
* Optional function to handle errors
*/
handleError?: (error: Error, input: TInput) => Promise<TOutput>;
/**
* Optional cache configuration
*/
cache?: {
/**
* Whether to enable caching
*/
enabled: boolean;
/**
* Maximum cache size
*/
maxSize?: number;
/**
* Cache TTL in milliseconds
*/
ttlMs?: number;
/**
* Function to create a cache key from input
*/
keyGenerator?: (input: TInput) => string;
};
/**
* Optional retry configuration
*/
retry?: {
/**
* Maximum number of retries
*/
maxRetries?: number;
/**
* Initial delay in milliseconds
*/
initialDelayMs?: number;
/**
* Maximum delay in milliseconds
*/
maxDelayMs?: number;
/**
* Function to determine if an error is retryable
*/
isRetryable?: (error: Error) => boolean;
};
/**
* Optional performance tracking
*/
tracking?: {
/**
* Whether to track performance metrics
*/
enabled: boolean;
/**
* What metrics to track
*/
metrics?: Array<'latency' | 'memory' | 'success_rate'>;
/**
* Function to process metrics
*/
processMetrics?: (metrics: Record<string, any>) => void;
};
}
/**
* Creates a custom tool with the provided options
*/
export declare function createCustomTool<TInput, TOutput>(options: CustomToolOptions<TInput, TOutput>): BaseTool;
//# sourceMappingURL=CustomToolFactory.d.ts.map