crewai-ts
Version:
TypeScript port of crewAI for agent-based workflows
123 lines • 3.63 kB
TypeScript
/**
* Tools Handler
* Manages agent tools with efficient access patterns and caching capabilities
* Optimized for memory efficiency and performance
*/
import { BaseTool } from '../../../tools/BaseTool.js';
import { CacheHandler } from '../cache/CacheHandler.js';
/**
* Tool category enum for organizing tools
*/
export declare enum ToolCategory {
GENERAL = "general",
DELEGATION = "delegation",
KNOWLEDGE = "knowledge",
CUSTOM = "custom"
}
/**
* Tool metadata for additional tool information
*/
export interface ToolMetadata {
category?: ToolCategory;
isAsync?: boolean;
requiresAuth?: boolean;
[key: string]: any;
}
/**
* Enhanced tool type with additional metadata
*/
export interface EnhancedTool extends BaseTool {
metadata?: ToolMetadata;
}
/**
* Cache key generator function type
*/
export type CacheKeyGenerator = (tool: BaseTool, args: unknown[]) => string;
/**
* Tool execution parameters type with memory-optimized structure
*/
export type ToolParameters = Record<string, unknown>;
/**
* Tools Handler for managing agent tools with efficient access patterns
* and optional caching capabilities
*
* Optimized with:
* - Fast tool lookup with Map
* - Category-based filtering
* - Tool result caching
* - Memory efficient tool storage
*/
export declare class ToolsHandler {
private tools;
private cache?;
private defaultKeyGenerator;
/**
* Create a new ToolsHandler
* Optimized for memory efficiency and type safety
*/
constructor();
/**
* Set the cache handler for tool results
* @param cache Cache handler instance
*/
setCache(cache: CacheHandler): void;
/**
* Add a tool to the handler
* @param tool Tool to add
* @param metadata Optional metadata for the tool
*/
addTool(tool: BaseTool, metadata?: ToolMetadata): void;
/**
* Add multiple tools to the handler
* @param tools Array of tools to add
* @param metadata Optional metadata to apply to all tools
*/
addTools(tools: BaseTool[], metadata?: ToolMetadata): void;
/**
* Get a tool by name
* @param name Name of the tool
* @returns The tool or undefined if not found
*/
getTool(name: string): EnhancedTool | undefined;
/**
* Get all tools
* @returns Array of all tools
*/
getAllTools(): EnhancedTool[];
/**
* Get tools by category
* @param category Category to filter by
* @returns Array of tools in the category
*/
getToolsByCategory(category: ToolCategory): EnhancedTool[];
/**
* Remove a tool by name
* @param name Name of the tool to remove
* @returns True if the tool was removed, false otherwise
*/
removeTool(name: string): boolean;
/**
* Remove all tools
*/
clearTools(): void;
/**
* Check if a tool exists
* @param name Name of the tool
* @returns True if the tool exists, false otherwise
*/
hasTool(name: string): boolean;
/**
* Execute a tool with caching if enabled
* @param name Name of the tool to execute
* @param args Arguments to pass to the tool
* @param keyGenerator Optional custom cache key generator
* @returns The result of the tool execution
*/
executeTool<T = unknown>(name: string, args: unknown[], keyGenerator?: CacheKeyGenerator): Promise<T>;
/**
* Create a categorized string representation of tools for agent prompts
* @returns Formatted string of tools grouped by category
*/
formatToolsForPrompt(): string;
}
//# sourceMappingURL=ToolsHandler.d.ts.map