UNPKG

adk-typescript

Version:

TypeScript port of Google's Agent Development Kit (ADK)

76 lines (75 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CrewaiTool = void 0; const FunctionTool_1 = require("./FunctionTool"); /** * A wrapper for CrewAI tools to use them with ADK */ class CrewaiTool extends FunctionTool_1.FunctionTool { /** * Create a new CrewAI tool wrapper * * @param options Options for the CrewAI tool */ constructor(options) { // Format the name correctly (CrewAI often uses spaces, but we replace with underscores) const name = options.name || (options.tool.name ? options.tool.name.replace(/ /g, '_').toLowerCase() : 'crewai_tool'); // Use the description from the CrewAI tool or a default const description = options.description || options.tool.description || 'A tool from the CrewAI framework'; // Create a wrapper function that calls the CrewAI tool's run method const wrapperFn = async (params, context) => { try { // Call the CrewAI tool with the parameters return await options.tool.run(params); } catch (error) { console.error('Error calling CrewAI tool:', error); return { error: 'Failed to call CrewAI tool', details: error instanceof Error ? error.message : String(error) }; } }; // Get the JSON schema from the CrewAI tool let schema; try { schema = options.tool.args_schema.model_json_schema(); } catch (error) { console.warn('Could not get schema from CrewAI tool:', error); schema = { type: 'object', properties: {}, required: [] }; } // Create the function declaration const functionDeclaration = { name, description, parameters: schema }; // Initialize the FunctionTool with the wrapper function and declaration super({ name, description, fn: wrapperFn, functionDeclaration }); this.crewaiTool = options.tool; } /** * Get the wrapped CrewAI tool * * @returns The wrapped CrewAI tool */ getCrewaiTool() { return this.crewaiTool; } } exports.CrewaiTool = CrewaiTool;