adk-typescript
Version:
TypeScript port of Google's Agent Development Kit (ADK)
68 lines (67 loc) • 1.91 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.FunctionTool = void 0;
const BaseTool_1 = require("./BaseTool");
/**
* A tool that executes a provided function
*/
class FunctionTool extends BaseTool_1.BaseTool {
/**
* Create a new function tool
* @param options Options for the function tool
*/
constructor(options) {
super(options);
this.fn = options.fn;
this.functionDeclaration = options.functionDeclaration;
}
/**
* Internal method to get the function declaration
* This overrides the protected method from BaseTool
*
* @returns The function declaration
*/
_getDeclaration() {
if (this.functionDeclaration) {
return this.functionDeclaration;
}
// Default minimal function declaration
return {
name: this.name,
description: this.description,
parameters: {
type: 'object',
properties: {},
required: []
}
};
}
/**
* Get the function declaration for the tool
*
* @returns The function declaration
*/
getFunctionDeclaration() {
const declaration = this._getDeclaration();
return declaration || {
name: this.name,
description: this.description,
parameters: {
type: 'object',
properties: {},
required: []
}
};
}
/**
* Execute the tool by calling the provided function
*
* @param params The parameters for the tool execution
* @param context The context for the tool execution
* @returns The result of the function execution
*/
async execute(params, context) {
return await this.fn(params, context);
}
}
exports.FunctionTool = FunctionTool;