contaigents
Version:
Modular AI Content Ecosystem with Audio Generation
124 lines (123 loc) โข 5.25 kB
JavaScript
/**
* Test Generic Tool Guidance
*
* This script tests that the generic tool guidance system works
* and that tools can provide their own specific guidance
*/
import { ChatService } from '../services/chatService.js';
import fs from 'fs/promises';
import path from 'path';
import { fileURLToPath } from 'url';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
// Test configuration
const TEST_OUTPUT_DIR = path.join(__dirname, 'generic_guidance_test');
class GenericToolGuidanceTest {
constructor() {
this.chatService = new ChatService(TEST_OUTPUT_DIR);
}
async setup() {
console.log('๐ง Setting up Generic Tool Guidance Test');
console.log('='.repeat(45));
// Create test output directory
await fs.mkdir(TEST_OUTPUT_DIR, { recursive: true });
console.log(`๐ Test directory created: ${TEST_OUTPUT_DIR}`);
console.log('');
}
async testGenericGuidanceSystem() {
console.log('๐ฏ Test: Generic Tool Guidance System');
console.log('-'.repeat(40));
// Test that the agent still creates creative prompts with the new generic system
const userRequest = "Generate an image of a peaceful garden";
console.log('๐ค User request:', userRequest);
console.log('');
try {
// Create a chat session
const session = this.chatService.createSession({
provider: 'google',
model: 'gemini-2.5-flash'
});
// Send the request
const response = await this.chatService.sendMessage(session.id, userRequest);
console.log('๐ค Agent response:');
console.log(` ${response.content.slice(0, 300)}${response.content.length > 300 ? '...' : ''}`);
console.log('');
// Check if an image was generated
try {
const files = await fs.readdir(TEST_OUTPUT_DIR);
const imageFiles = files.filter(file => file.endsWith('.png') || file.endsWith('.jpg') || file.endsWith('.jpeg'));
if (imageFiles.length > 0) {
console.log('โ
Image generation successful!');
console.log(`๐ Generated file: ${imageFiles[imageFiles.length - 1]}`);
const filePath = path.join(TEST_OUTPUT_DIR, imageFiles[imageFiles.length - 1]);
const stats = await fs.stat(filePath);
console.log(`๐ File size: ${this.formatFileSize(stats.size)}`);
console.log('');
console.log('๐ Generic tool guidance system is working!');
console.log(' - Tool provided its own specific guidance');
console.log(' - Agent received and followed the guidance');
console.log(' - Creative prompt was generated and image created');
}
else {
console.log('โ No image files found');
}
}
catch (error) {
console.log('โ Could not check for generated files');
}
}
catch (error) {
console.log('โ Test failed:', error.message);
}
}
formatFileSize(bytes) {
if (bytes === 0)
return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(1)) + ' ' + sizes[i];
}
async cleanup() {
console.log('');
console.log('๐งน Test completed!');
console.log('');
console.log('๐ Architecture Benefits:');
console.log(' โ
Tool guidance is now modular and extensible');
console.log(' โ
Each tool can define its own specific guidance');
console.log(' โ
ToolManager generically collects all guidance');
console.log(' โ
No hardcoded tool-specific logic in ToolManager');
console.log(' โ
Easy to add guidance to new tools in the future');
console.log('');
}
async runTest() {
try {
await this.setup();
await this.testGenericGuidanceSystem();
await this.cleanup();
console.log('๐ Generic tool guidance test completed successfully!');
}
catch (error) {
console.error('โ Test failed:', error);
process.exit(1);
}
}
}
// Run the test
async function runGenericGuidanceTest() {
console.log('๐ Starting Generic Tool Guidance Test');
console.log('');
console.log('This test verifies that:');
console.log(' - Tools can provide their own specific guidance');
console.log(' - ToolManager generically collects guidance from all tools');
console.log(' - Agent receives and follows tool-specific guidance');
console.log(' - The system is modular and extensible');
console.log('');
const test = new GenericToolGuidanceTest();
await test.runTest();
}
// Run if called directly
if (import.meta.url === `file://${process.argv[1]}`) {
runGenericGuidanceTest();
}