contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
62 lines (61 loc) • 2.49 kB
JavaScript
export class BaseTool {
/**
* Optional method for tools to provide specific usage guidance for agents
* This guidance will be included in the system prompt to help agents use the tool effectively
*/
getAgentGuidance() {
return null; // Default: no specific guidance
}
getDefinition() {
return {
name: this.getName(),
description: this.getDescription(),
parameters: this.getParameters()
};
}
validateParameters(parameters) {
const toolParams = this.getParameters();
for (const param of toolParams) {
if (param.required && !(param.name in parameters)) {
return {
success: false,
error: `Missing required parameter: ${param.name}`
};
}
if (param.name in parameters) {
const value = parameters[param.name];
const expectedType = param.type;
if (expectedType === 'string' && typeof value !== 'string') {
return {
success: false,
error: `Parameter ${param.name} must be a string`
};
}
if (expectedType === 'number' && typeof value !== 'number') {
// Allow string numbers for time-related parameters
if (typeof value === 'string' && (param.name === 'duration' || param.name === 'start_time' || param.name === 'end_time' || param.name === 'font_size')) {
// These can be strings like "00:01:23" or "24"
continue;
}
return {
success: false,
error: `Parameter ${param.name} must be a number`
};
}
if (expectedType === 'boolean' && typeof value !== 'boolean') {
return {
success: false,
error: `Parameter ${param.name} must be a boolean`
};
}
if (expectedType === 'array' && !Array.isArray(value)) {
return {
success: false,
error: `Parameter ${param.name} must be an array`
};
}
}
}
return null; // No validation errors
}
}