tasq/node_modules/agentdb/dist/simulation/scenarios/research-swarm.js

146 lines
6.2 KiB
JavaScript

/**
* Research-Swarm Integration
*
* Distributed research graph DB
* Integration with research-swarm package
*
* Features:
* - Collaborative research agents
* - Literature review aggregation
* - Hypothesis generation and testing
* - Knowledge synthesis
*/
import { createUnifiedDatabase } from '../../src/db-unified.js';
import { ReflexionMemory } from '../../src/controllers/ReflexionMemory.js';
import { CausalMemoryGraph } from '../../src/controllers/CausalMemoryGraph.js';
import { SkillLibrary } from '../../src/controllers/SkillLibrary.js';
import { EmbeddingService } from '../../src/controllers/EmbeddingService.js';
import * as path from 'path';
export default {
description: 'Research-swarm distributed research with collaborative agents',
async run(config) {
const { verbosity = 2, researchers = 5 } = config;
if (verbosity >= 2) {
console.log(` 🔬 Initializing Research-Swarm (${researchers} researchers)`);
}
// Initialize distributed research graph database
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', 'advanced', 'research-swarm.graph'), embedder, { forceMode: 'graph' });
const reflexion = new ReflexionMemory(db.getGraphDatabase(), embedder, undefined, undefined, db.getGraphDatabase());
const causal = new CausalMemoryGraph(db.getGraphDatabase(), db.getGraphDatabase());
const skills = new SkillLibrary(db.getGraphDatabase(), embedder, undefined, db.getGraphDatabase());
const results = {
papers: 0,
hypotheses: 0,
experiments: 0,
synthesizedKnowledge: 0,
totalTime: 0
};
const startTime = performance.now();
// Literature Review (each researcher finds papers)
const papers = [
'neural_architecture_search_techniques',
'few_shot_learning_methods',
'transfer_learning_strategies',
'meta_learning_algorithms',
'continual_learning_approaches'
];
const paperIds = [];
for (let i = 0; i < papers.length; i++) {
const id = await reflexion.storeEpisode({
sessionId: `researcher-${i % researchers}`,
task: `literature_review: ${papers[i]}`,
reward: 0.80 + Math.random() * 0.15, // Quality varies
success: true,
input: 'academic_search',
output: `paper_summary_${papers[i]}`
});
paperIds.push(id);
results.papers++;
}
// Hypothesis Generation (synthesizing from papers)
const hypotheses = [
'combining_meta_learning_with_architecture_search_improves_few_shot',
'transfer_learning_enables_faster_continual_learning',
'meta_architecture_search_reduces_hyperparameter_tuning'
];
const hypothesisIds = [];
for (const hypothesis of hypotheses) {
const id = await reflexion.storeEpisode({
sessionId: 'research-synthesis',
task: `hypothesis: ${hypothesis}`,
reward: 0.70, // Untested hypothesis
success: false, // Not yet validated
input: 'literature_synthesis',
output: `hypothesis_${hypothesis}`,
critique: 'Requires experimental validation'
});
hypothesisIds.push(id);
results.hypotheses++;
// Link hypothesis to supporting papers
for (let i = 0; i < Math.min(2, paperIds.length); i++) {
await causal.addCausalEdge({
fromMemoryId: paperIds[i],
fromMemoryType: 'episode',
toMemoryId: id,
toMemoryType: 'episode',
similarity: 0.85,
uplift: 0.20,
confidence: 0.80,
sampleSize: 100,
mechanism: 'paper_supports_hypothesis'
});
}
}
// Experimental Validation
const experiments = [
{ hypothesis: 0, result: 'confirmed', confidence: 0.92 },
{ hypothesis: 1, result: 'confirmed', confidence: 0.88 },
{ hypothesis: 2, result: 'partially_confirmed', confidence: 0.75 }
];
for (const exp of experiments) {
await reflexion.storeEpisode({
sessionId: 'experimental-validation',
task: `experiment_validate_hypothesis_${exp.hypothesis}`,
reward: exp.confidence,
success: exp.result === 'confirmed',
input: `hypothesis_${exp.hypothesis}`,
output: exp.result,
critique: `Confidence: ${exp.confidence}`
});
results.experiments++;
}
// Knowledge Synthesis (create reusable research methods)
const researchMethods = [
'meta_architecture_search_protocol',
'few_shot_evaluation_framework',
'transfer_learning_pipeline'
];
for (const method of researchMethods) {
await skills.createSkill({
name: method,
description: 'Research methodology',
code: `// Reusable research method: ${method}`,
successRate: 0.85
});
results.synthesizedKnowledge++;
}
const endTime = performance.now();
results.totalTime = endTime - startTime;
db.close();
if (verbosity >= 2) {
console.log(` 📊 Papers Reviewed: ${results.papers}`);
console.log(` 📊 Hypotheses Generated: ${results.hypotheses}`);
console.log(` 📊 Experiments Conducted: ${results.experiments}`);
console.log(` 📊 Synthesized Knowledge: ${results.synthesizedKnowledge} methods`);
console.log(` ⏱️ Duration: ${results.totalTime.toFixed(2)}ms`);
}
return results;
}
};
//# sourceMappingURL=research-swarm.js.map