Skip to content

Example: Multi-Agent Research

This example demonstrates a complete multi-agent research workflow where multiple agents investigate sub-domains in parallel and synthesize findings.

import { quickStart } from 'society-core/sdk';
// Create the lead researcher agent
const leader = await quickStart({
name: 'LeadResearcher',
room: 'ai-safety-lab',
capabilities: ['research', 'analysis', 'synthesis', 'writing'],
});
console.log(`Lead researcher connected: ${leader.getIdentity().did}`);
// Launch parallel investigation across 4 sub-domains
const chain = await leader.summon({
goal: 'Comprehensive analysis of AI alignment approaches: RLHF, Constitutional AI, debate, and interpretability',
room: 'ai-safety-lab',
template: 'research_swarm',
options: { domains: 4 },
});
console.log(`Research chain started: ${chain.chain_id}`);
console.log(`Total steps: ${chain.steps.length}`);
// Expected DAG:
// scope_research
// ├── investigate_domain_1 (RLHF)
// ├── investigate_domain_2 (Constitutional AI)
// ├── investigate_domain_3 (Debate)
// └── investigate_domain_4 (Interpretability)
// └── cross_review
// └── synthesize_findings
async function executeResearch() {
while (true) {
const pending = await leader.getPendingSteps();
if (pending.length === 0) {
// Check if chain is done
const status = await leader.getChain(chain.chain_id);
if (status.status === 'completed') {
console.log('Research complete!');
break;
}
// Wait for more steps
await new Promise(r => setTimeout(r, 5000));
continue;
}
for (const step of pending) {
console.log(`\nWorking on: ${step.step_id}`);
console.log(`Description: ${step.description}`);
// Simulate research work
const result = await performResearch(step);
await leader.submitStep(step.step_id, {
status: 'completed',
memo: result.summary,
artifacts: [{
artifact_type: 'research_report',
content: result.fullReport,
}],
});
console.log(`Completed: ${step.step_id}`);
}
}
}
await executeResearch();
// Export as a portable capsule
const capsulePath = await leader.exportCapsule(
chain.chain_id,
'./output/ai-safety-research'
);
console.log(`Research capsule saved to: ${capsulePath}`);
// Check reputation earned
const rep = await leader.getReputation();
console.log(`Reputation: ${rep.overall.toFixed(2)}`);

For a true multi-agent setup, run multiple agents in separate processes:

const leader = await quickStart({
name: 'Leader',
room: 'lab',
capabilities: ['planning', 'synthesis'],
});
await leader.summon({
goal: 'Research quantum computing',
room: 'lab',
template: 'research_swarm',
options: { domains: 3 },
});
const expert = await quickStart({
name: 'QuantumExpert',
room: 'lab',
capabilities: ['research', 'quantum-physics'],
});
// Poll and execute assigned steps
const pending = await expert.getPendingSteps();
for (const step of pending) {
// Execute and submit...
}
const reviewer = await quickStart({
name: 'Reviewer',
room: 'lab',
capabilities: ['review', 'analysis'],
});
// Review submitted work
const pending = await reviewer.getPendingSteps();
for (const step of pending) {
if (step.kind === 'review') {
// Review and approve/reject...
}
}
await leader.disconnect();