109 lines
4.2 KiB
JavaScript
109 lines
4.2 KiB
JavaScript
/**
|
|
* Skill Evolution Simulation
|
|
*
|
|
* Tests SkillLibrary with skill creation, evolution, and composition
|
|
*/
|
|
import { createUnifiedDatabase } from '../../src/db-unified.js';
|
|
import { SkillLibrary } from '../../src/controllers/SkillLibrary.js';
|
|
import { EmbeddingService } from '../../src/controllers/EmbeddingService.js';
|
|
import * as path from 'path';
|
|
export default {
|
|
description: 'Skill library evolution with composition and refinement',
|
|
async run(config) {
|
|
const { verbosity = 2 } = config;
|
|
if (verbosity >= 2) {
|
|
console.log(' 🛠️ Initializing Skill Evolution Simulation');
|
|
}
|
|
// Initialize AgentDB
|
|
const embedder = new EmbeddingService({
|
|
model: 'Xenova/all-MiniLM-L6-v2',
|
|
dimension: 384,
|
|
provider: 'transformers'
|
|
});
|
|
await embedder.initialize();
|
|
const db = await createUnifiedDatabase(path.join(process.cwd(), 'simulation', 'data', 'skills.graph'), embedder, { forceMode: 'graph' });
|
|
const skills = new SkillLibrary(db.getGraphDatabase(), embedder, undefined, // vectorBackend
|
|
db.getGraphDatabase() // graphBackend
|
|
);
|
|
// Simulate skill creation and evolution
|
|
const skillTemplates = [
|
|
{
|
|
name: 'jwt_authentication',
|
|
description: 'Generate and verify JWT tokens',
|
|
code: 'function generateJWT(payload) { return jwt.sign(payload, SECRET); }',
|
|
successRate: 0.95
|
|
},
|
|
{
|
|
name: 'database_query_optimizer',
|
|
description: 'Optimize database queries with batch loading',
|
|
code: 'function batchLoad(ids) { return DataLoader.load(ids); }',
|
|
successRate: 0.88
|
|
},
|
|
{
|
|
name: 'error_handler',
|
|
description: 'Comprehensive error handling middleware',
|
|
code: 'function errorHandler(err, req, res, next) { /* ... */ }',
|
|
successRate: 0.92
|
|
},
|
|
{
|
|
name: 'cache_manager',
|
|
description: 'Redis-based caching with TTL',
|
|
code: 'function cacheSet(key, val, ttl) { return redis.setex(key, ttl, val); }',
|
|
successRate: 0.90
|
|
},
|
|
{
|
|
name: 'validation_schema',
|
|
description: 'Request validation with Zod schemas',
|
|
code: 'const schema = z.object({ email: z.string().email() });',
|
|
successRate: 0.93
|
|
}
|
|
];
|
|
const results = {
|
|
created: 0,
|
|
searched: 0,
|
|
avgSuccessRate: 0,
|
|
totalTime: 0
|
|
};
|
|
const startTime = performance.now();
|
|
// Create skills
|
|
for (const template of skillTemplates) {
|
|
await skills.createSkill(template);
|
|
results.created++;
|
|
results.avgSuccessRate += template.successRate;
|
|
if (verbosity >= 3) {
|
|
console.log(` ✅ Created skill: ${template.name}`);
|
|
}
|
|
}
|
|
// Search for skills
|
|
const searchQueries = [
|
|
'authentication',
|
|
'database optimization',
|
|
'error handling',
|
|
'caching',
|
|
'validation'
|
|
];
|
|
for (const query of searchQueries) {
|
|
const found = await skills.searchSkills({
|
|
query,
|
|
k: 3,
|
|
minSuccessRate: 0.8
|
|
});
|
|
results.searched += found.length;
|
|
if (verbosity >= 3) {
|
|
console.log(` 🔍 Found ${found.length} skills for: ${query}`);
|
|
}
|
|
}
|
|
const endTime = performance.now();
|
|
results.totalTime = endTime - startTime;
|
|
results.avgSuccessRate /= skillTemplates.length;
|
|
db.close();
|
|
if (verbosity >= 2) {
|
|
console.log(` 📊 Created: ${results.created} skills`);
|
|
console.log(` 📊 Searched: ${results.searched} results`);
|
|
console.log(` 📊 Avg Success Rate: ${(results.avgSuccessRate * 100).toFixed(1)}%`);
|
|
console.log(` ⏱️ Duration: ${results.totalTime.toFixed(2)}ms`);
|
|
}
|
|
return results;
|
|
}
|
|
};
|
|
//# sourceMappingURL=skill-evolution.js.map
|