UNPKG

contaigents

Version:

Modular AI Content Ecosystem with Audio Generation

124 lines (123 loc) โ€ข 5.25 kB
#!/usr/bin/env node /** * 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(); }