@cogitator-ai/swarms 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +90 -0
- package/dist/communication/blackboard.d.ts +24 -0
- package/dist/communication/blackboard.d.ts.map +1 -0
- package/dist/communication/blackboard.js +135 -0
- package/dist/communication/blackboard.js.map +1 -0
- package/dist/communication/event-emitter.d.ts +20 -0
- package/dist/communication/event-emitter.d.ts.map +1 -0
- package/dist/communication/event-emitter.js +87 -0
- package/dist/communication/event-emitter.js.map +1 -0
- package/dist/communication/index.d.ts +7 -0
- package/dist/communication/index.d.ts.map +1 -0
- package/dist/communication/index.js +7 -0
- package/dist/communication/index.js.map +1 -0
- package/dist/communication/message-bus.d.ts +23 -0
- package/dist/communication/message-bus.d.ts.map +1 -0
- package/dist/communication/message-bus.js +128 -0
- package/dist/communication/message-bus.js.map +1 -0
- package/dist/coordinator.d.ts +44 -0
- package/dist/coordinator.d.ts.map +1 -0
- package/dist/coordinator.js +283 -0
- package/dist/coordinator.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -0
- package/dist/index.js.map +1 -0
- package/dist/resources/circuit-breaker.d.ts +29 -0
- package/dist/resources/circuit-breaker.d.ts.map +1 -0
- package/dist/resources/circuit-breaker.js +82 -0
- package/dist/resources/circuit-breaker.js.map +1 -0
- package/dist/resources/index.d.ts +7 -0
- package/dist/resources/index.d.ts.map +1 -0
- package/dist/resources/index.js +6 -0
- package/dist/resources/index.js.map +1 -0
- package/dist/resources/tracker.d.ts +30 -0
- package/dist/resources/tracker.d.ts.map +1 -0
- package/dist/resources/tracker.js +84 -0
- package/dist/resources/tracker.js.map +1 -0
- package/dist/strategies/auction.d.ts +17 -0
- package/dist/strategies/auction.d.ts.map +1 -0
- package/dist/strategies/auction.js +204 -0
- package/dist/strategies/auction.js.map +1 -0
- package/dist/strategies/base.d.ts +34 -0
- package/dist/strategies/base.d.ts.map +1 -0
- package/dist/strategies/base.js +74 -0
- package/dist/strategies/base.js.map +1 -0
- package/dist/strategies/consensus.d.ts +20 -0
- package/dist/strategies/consensus.d.ts.map +1 -0
- package/dist/strategies/consensus.js +328 -0
- package/dist/strategies/consensus.js.map +1 -0
- package/dist/strategies/debate.d.ts +15 -0
- package/dist/strategies/debate.d.ts.map +1 -0
- package/dist/strategies/debate.js +171 -0
- package/dist/strategies/debate.js.map +1 -0
- package/dist/strategies/hierarchical.d.ts +13 -0
- package/dist/strategies/hierarchical.d.ts.map +1 -0
- package/dist/strategies/hierarchical.js +86 -0
- package/dist/strategies/hierarchical.js.map +1 -0
- package/dist/strategies/index.d.ts +28 -0
- package/dist/strategies/index.d.ts.map +1 -0
- package/dist/strategies/index.js +106 -0
- package/dist/strategies/index.js.map +1 -0
- package/dist/strategies/pipeline.d.ts +16 -0
- package/dist/strategies/pipeline.d.ts.map +1 -0
- package/dist/strategies/pipeline.js +180 -0
- package/dist/strategies/pipeline.js.map +1 -0
- package/dist/strategies/round-robin.d.ts +27 -0
- package/dist/strategies/round-robin.d.ts.map +1 -0
- package/dist/strategies/round-robin.js +98 -0
- package/dist/strategies/round-robin.js.map +1 -0
- package/dist/swarm.d.ts +113 -0
- package/dist/swarm.d.ts.map +1 -0
- package/dist/swarm.js +280 -0
- package/dist/swarm.js.map +1 -0
- package/dist/tools/blackboard.d.ts +71 -0
- package/dist/tools/blackboard.d.ts.map +1 -0
- package/dist/tools/blackboard.js +149 -0
- package/dist/tools/blackboard.js.map +1 -0
- package/dist/tools/delegation.d.ts +120 -0
- package/dist/tools/delegation.d.ts.map +1 -0
- package/dist/tools/delegation.js +257 -0
- package/dist/tools/delegation.js.map +1 -0
- package/dist/tools/index.d.ts +26 -0
- package/dist/tools/index.d.ts.map +1 -0
- package/dist/tools/index.js +65 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/messaging.d.ts +73 -0
- package/dist/tools/messaging.d.ts.map +1 -0
- package/dist/tools/messaging.js +146 -0
- package/dist/tools/messaging.js.map +1 -0
- package/dist/tools/voting.d.ts +110 -0
- package/dist/tools/voting.d.ts.map +1 -0
- package/dist/tools/voting.js +201 -0
- package/dist/tools/voting.js.map +1 -0
- package/dist/workflow/swarm-node.d.ts +43 -0
- package/dist/workflow/swarm-node.d.ts.map +1 -0
- package/dist/workflow/swarm-node.js +111 -0
- package/dist/workflow/swarm-node.js.map +1 -0
- package/package.json +45 -0
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Consensus strategy - Agents vote and reach agreement
|
|
3
|
+
*/
|
|
4
|
+
import { BaseStrategy } from './base';
|
|
5
|
+
export class ConsensusStrategy extends BaseStrategy {
|
|
6
|
+
config;
|
|
7
|
+
constructor(coordinator, config) {
|
|
8
|
+
super(coordinator);
|
|
9
|
+
this.config = config;
|
|
10
|
+
}
|
|
11
|
+
async execute(options) {
|
|
12
|
+
const agentResults = new Map();
|
|
13
|
+
const allVotes = [];
|
|
14
|
+
const discussionTranscript = [];
|
|
15
|
+
const agents = this.coordinator.getAgents();
|
|
16
|
+
if (agents.length < 2) {
|
|
17
|
+
throw new Error('Consensus strategy requires at least 2 agents');
|
|
18
|
+
}
|
|
19
|
+
const supervisors = this.coordinator.getAgentsByRole('supervisor');
|
|
20
|
+
const supervisor = supervisors.length > 0 ? supervisors[0] : null;
|
|
21
|
+
this.coordinator.blackboard.write('consensus', {
|
|
22
|
+
topic: options.input,
|
|
23
|
+
maxRounds: this.config.maxRounds,
|
|
24
|
+
currentRound: 0,
|
|
25
|
+
votes: [],
|
|
26
|
+
resolution: this.config.resolution,
|
|
27
|
+
threshold: this.config.threshold,
|
|
28
|
+
}, 'system');
|
|
29
|
+
let consensusReached = false;
|
|
30
|
+
let winningDecision = null;
|
|
31
|
+
let finalRound = 0;
|
|
32
|
+
for (let round = 1; round <= this.config.maxRounds && !consensusReached; round++) {
|
|
33
|
+
finalRound = round;
|
|
34
|
+
this.coordinator.events.emit('consensus:round', { round, total: this.config.maxRounds });
|
|
35
|
+
const consensusState = this.coordinator.blackboard.read('consensus');
|
|
36
|
+
this.coordinator.blackboard.write('consensus', {
|
|
37
|
+
...consensusState,
|
|
38
|
+
currentRound: round,
|
|
39
|
+
}, 'system');
|
|
40
|
+
const roundVotes = [];
|
|
41
|
+
const previousDiscussion = this.getPreviousDiscussion(discussionTranscript, round);
|
|
42
|
+
for (const swarmAgent of agents) {
|
|
43
|
+
if (swarmAgent.metadata.role === 'supervisor')
|
|
44
|
+
continue;
|
|
45
|
+
const agentContext = {
|
|
46
|
+
...options.context,
|
|
47
|
+
consensusContext: {
|
|
48
|
+
round,
|
|
49
|
+
totalRounds: this.config.maxRounds,
|
|
50
|
+
resolution: this.config.resolution,
|
|
51
|
+
threshold: this.config.threshold,
|
|
52
|
+
previousVotes: this.summarizeVotes(allVotes.filter(v => v.round < round)),
|
|
53
|
+
previousDiscussion,
|
|
54
|
+
},
|
|
55
|
+
consensusInstructions: this.buildConsensusInstructions(swarmAgent, round),
|
|
56
|
+
};
|
|
57
|
+
const input = round === 1
|
|
58
|
+
? `Consider the following and provide your decision:\n\n${options.input}\n\nProvide your vote as: VOTE: [your decision]\nFollowed by your reasoning.`
|
|
59
|
+
: `Continue the consensus discussion on: ${options.input}\n\nPrevious votes and discussion:\n${previousDiscussion}\n\nProvide your updated vote as: VOTE: [your decision]\nFollowed by your reasoning.`;
|
|
60
|
+
this.coordinator.events.emit('consensus:turn', {
|
|
61
|
+
round,
|
|
62
|
+
agent: swarmAgent.agent.name,
|
|
63
|
+
}, swarmAgent.agent.name);
|
|
64
|
+
const result = await this.coordinator.runAgent(swarmAgent.agent.name, input, agentContext);
|
|
65
|
+
agentResults.set(`${swarmAgent.agent.name}_round${round}`, result);
|
|
66
|
+
const vote = this.extractVote(result.output, swarmAgent, round);
|
|
67
|
+
if (vote) {
|
|
68
|
+
roundVotes.push(vote);
|
|
69
|
+
allVotes.push(vote);
|
|
70
|
+
}
|
|
71
|
+
const message = {
|
|
72
|
+
id: `consensus_${round}_${swarmAgent.agent.name}`,
|
|
73
|
+
swarmId: '',
|
|
74
|
+
from: swarmAgent.agent.name,
|
|
75
|
+
to: 'broadcast',
|
|
76
|
+
type: 'notification',
|
|
77
|
+
content: result.output,
|
|
78
|
+
channel: 'consensus',
|
|
79
|
+
timestamp: Date.now(),
|
|
80
|
+
metadata: { round, vote: vote?.decision },
|
|
81
|
+
};
|
|
82
|
+
discussionTranscript.push(message);
|
|
83
|
+
}
|
|
84
|
+
const updatedState = this.coordinator.blackboard.read('consensus');
|
|
85
|
+
updatedState.votes = allVotes;
|
|
86
|
+
this.coordinator.blackboard.write('consensus', updatedState, 'system');
|
|
87
|
+
const consensusResult = this.checkConsensus(roundVotes, agents.filter(a => a.metadata.role !== 'supervisor'));
|
|
88
|
+
if (consensusResult.reached) {
|
|
89
|
+
consensusReached = true;
|
|
90
|
+
winningDecision = consensusResult.decision;
|
|
91
|
+
this.coordinator.events.emit('consensus:reached', {
|
|
92
|
+
round,
|
|
93
|
+
decision: winningDecision,
|
|
94
|
+
votes: consensusResult.voteCounts,
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
let finalOutput;
|
|
99
|
+
if (consensusReached && winningDecision) {
|
|
100
|
+
finalOutput = this.buildConsensusOutput(winningDecision, allVotes, finalRound, true);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
switch (this.config.onNoConsensus) {
|
|
104
|
+
case 'supervisor-decides':
|
|
105
|
+
if (supervisor) {
|
|
106
|
+
const supervisorResult = await this.runSupervisorDecision(supervisor, options, allVotes, discussionTranscript);
|
|
107
|
+
agentResults.set(supervisor.agent.name, supervisorResult);
|
|
108
|
+
finalOutput = supervisorResult.output;
|
|
109
|
+
}
|
|
110
|
+
else {
|
|
111
|
+
finalOutput = this.buildConsensusOutput(null, allVotes, finalRound, false);
|
|
112
|
+
}
|
|
113
|
+
break;
|
|
114
|
+
case 'escalate':
|
|
115
|
+
finalOutput = `ESCALATION REQUIRED\n\n${this.buildConsensusOutput(null, allVotes, finalRound, false)}\n\nNo consensus reached after ${this.config.maxRounds} rounds. Please escalate to human decision-maker.`;
|
|
116
|
+
break;
|
|
117
|
+
case 'fail':
|
|
118
|
+
default:
|
|
119
|
+
throw new Error(`Consensus not reached after ${this.config.maxRounds} rounds`);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
const votesMap = new Map();
|
|
123
|
+
for (const vote of allVotes) {
|
|
124
|
+
votesMap.set(`${vote.agentName}_round${vote.round}`, {
|
|
125
|
+
decision: vote.decision,
|
|
126
|
+
reasoning: vote.reasoning,
|
|
127
|
+
weight: vote.weight,
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
return {
|
|
131
|
+
output: finalOutput,
|
|
132
|
+
agentResults,
|
|
133
|
+
votes: votesMap,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
extractVote(output, agent, round) {
|
|
137
|
+
const voteMatch = /VOTE:\s*([^\n]+)/i.exec(output);
|
|
138
|
+
if (!voteMatch) {
|
|
139
|
+
const decisionMatch = /(?:decision|vote|choose|select):\s*([^\n]+)/i.exec(output);
|
|
140
|
+
if (!decisionMatch)
|
|
141
|
+
return null;
|
|
142
|
+
return {
|
|
143
|
+
agentName: agent.agent.name,
|
|
144
|
+
decision: decisionMatch[1].trim(),
|
|
145
|
+
reasoning: output,
|
|
146
|
+
weight: this.getAgentWeight(agent),
|
|
147
|
+
round,
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
return {
|
|
151
|
+
agentName: agent.agent.name,
|
|
152
|
+
decision: voteMatch[1].trim(),
|
|
153
|
+
reasoning: output.replace(voteMatch[0], '').trim(),
|
|
154
|
+
weight: this.getAgentWeight(agent),
|
|
155
|
+
round,
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
getAgentWeight(agent) {
|
|
159
|
+
if (this.config.weights?.[agent.agent.name] !== undefined) {
|
|
160
|
+
return this.config.weights[agent.agent.name];
|
|
161
|
+
}
|
|
162
|
+
if (agent.metadata.weight !== undefined) {
|
|
163
|
+
return agent.metadata.weight;
|
|
164
|
+
}
|
|
165
|
+
return 1;
|
|
166
|
+
}
|
|
167
|
+
checkConsensus(votes, agents) {
|
|
168
|
+
if (votes.length === 0) {
|
|
169
|
+
return { reached: false, decision: null, voteCounts: [] };
|
|
170
|
+
}
|
|
171
|
+
const voteCounts = new Map();
|
|
172
|
+
for (const vote of votes) {
|
|
173
|
+
const normalized = vote.decision.toLowerCase().trim();
|
|
174
|
+
const existing = voteCounts.get(normalized);
|
|
175
|
+
if (existing) {
|
|
176
|
+
existing.count++;
|
|
177
|
+
existing.weightedCount += vote.weight;
|
|
178
|
+
existing.voters.push(vote.agentName);
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
voteCounts.set(normalized, {
|
|
182
|
+
decision: vote.decision,
|
|
183
|
+
count: 1,
|
|
184
|
+
weightedCount: vote.weight,
|
|
185
|
+
voters: [vote.agentName],
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
const countsArray = Array.from(voteCounts.values());
|
|
190
|
+
const totalVotes = votes.length;
|
|
191
|
+
const totalWeight = votes.reduce((sum, v) => sum + v.weight, 0);
|
|
192
|
+
switch (this.config.resolution) {
|
|
193
|
+
case 'unanimous': {
|
|
194
|
+
if (countsArray.length === 1 && countsArray[0].count === agents.length) {
|
|
195
|
+
return { reached: true, decision: countsArray[0].decision, voteCounts: countsArray };
|
|
196
|
+
}
|
|
197
|
+
return { reached: false, decision: null, voteCounts: countsArray };
|
|
198
|
+
}
|
|
199
|
+
case 'weighted': {
|
|
200
|
+
const sorted = countsArray.sort((a, b) => b.weightedCount - a.weightedCount);
|
|
201
|
+
const topOption = sorted[0];
|
|
202
|
+
const weightRatio = topOption.weightedCount / totalWeight;
|
|
203
|
+
if (weightRatio >= this.config.threshold) {
|
|
204
|
+
return { reached: true, decision: topOption.decision, voteCounts: countsArray };
|
|
205
|
+
}
|
|
206
|
+
return { reached: false, decision: null, voteCounts: countsArray };
|
|
207
|
+
}
|
|
208
|
+
case 'majority':
|
|
209
|
+
default: {
|
|
210
|
+
const sorted = countsArray.sort((a, b) => b.count - a.count);
|
|
211
|
+
const topOption = sorted[0];
|
|
212
|
+
const voteRatio = topOption.count / totalVotes;
|
|
213
|
+
if (voteRatio >= this.config.threshold) {
|
|
214
|
+
return { reached: true, decision: topOption.decision, voteCounts: countsArray };
|
|
215
|
+
}
|
|
216
|
+
return { reached: false, decision: null, voteCounts: countsArray };
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
summarizeVotes(votes) {
|
|
221
|
+
if (votes.length === 0)
|
|
222
|
+
return 'No previous votes.';
|
|
223
|
+
const byAgent = new Map();
|
|
224
|
+
for (const vote of votes) {
|
|
225
|
+
const existing = byAgent.get(vote.agentName) ?? [];
|
|
226
|
+
existing.push(vote);
|
|
227
|
+
byAgent.set(vote.agentName, existing);
|
|
228
|
+
}
|
|
229
|
+
return Array.from(byAgent.entries())
|
|
230
|
+
.map(([agent, agentVotes]) => {
|
|
231
|
+
const lastVote = agentVotes[agentVotes.length - 1];
|
|
232
|
+
return `${agent}: ${lastVote.decision}`;
|
|
233
|
+
})
|
|
234
|
+
.join('\n');
|
|
235
|
+
}
|
|
236
|
+
getPreviousDiscussion(transcript, currentRound) {
|
|
237
|
+
const previousMessages = transcript.filter((m) => m.metadata?.round < currentRound);
|
|
238
|
+
if (previousMessages.length === 0)
|
|
239
|
+
return '';
|
|
240
|
+
return previousMessages
|
|
241
|
+
.map((m) => `[${m.from}]: ${m.content}`)
|
|
242
|
+
.join('\n\n');
|
|
243
|
+
}
|
|
244
|
+
buildConsensusInstructions(agent, round) {
|
|
245
|
+
const resolutionDesc = {
|
|
246
|
+
majority: `A decision wins if it receives ${Math.round(this.config.threshold * 100)}% or more of the votes.`,
|
|
247
|
+
unanimous: 'All agents must agree on the same decision.',
|
|
248
|
+
weighted: `A decision wins if its weighted vote reaches ${Math.round(this.config.threshold * 100)}% of total weight.`,
|
|
249
|
+
};
|
|
250
|
+
return `
|
|
251
|
+
You are participating in a consensus decision-making process.
|
|
252
|
+
|
|
253
|
+
Round ${round} of ${this.config.maxRounds}
|
|
254
|
+
Resolution: ${this.config.resolution} - ${resolutionDesc[this.config.resolution]}
|
|
255
|
+
|
|
256
|
+
Your weight in this vote: ${this.getAgentWeight(agent)}
|
|
257
|
+
|
|
258
|
+
Instructions:
|
|
259
|
+
1. Consider the topic carefully
|
|
260
|
+
2. Review previous votes and reasoning if available
|
|
261
|
+
3. Provide your vote in the format: VOTE: [your decision]
|
|
262
|
+
4. Explain your reasoning
|
|
263
|
+
5. If you're changing your vote from a previous round, explain why
|
|
264
|
+
|
|
265
|
+
Be constructive and aim for consensus while maintaining your expert judgment.
|
|
266
|
+
`.trim();
|
|
267
|
+
}
|
|
268
|
+
async runSupervisorDecision(supervisor, options, votes, transcript) {
|
|
269
|
+
const voteSummary = this.summarizeVotes(votes);
|
|
270
|
+
const discussionSummary = transcript
|
|
271
|
+
.map((m) => `[${m.from}]: ${m.content.slice(0, 300)}...`)
|
|
272
|
+
.join('\n\n');
|
|
273
|
+
const input = `
|
|
274
|
+
As the supervisor, the team has not reached consensus after ${this.config.maxRounds} rounds.
|
|
275
|
+
|
|
276
|
+
Original topic: ${options.input}
|
|
277
|
+
|
|
278
|
+
Vote summary:
|
|
279
|
+
${voteSummary}
|
|
280
|
+
|
|
281
|
+
Discussion highlights:
|
|
282
|
+
${discussionSummary}
|
|
283
|
+
|
|
284
|
+
Please make the final decision and explain your reasoning.
|
|
285
|
+
Provide your decision as: FINAL DECISION: [your decision]
|
|
286
|
+
`.trim();
|
|
287
|
+
return this.coordinator.runAgent(supervisor.agent.name, input, {
|
|
288
|
+
...options.context,
|
|
289
|
+
supervisorContext: {
|
|
290
|
+
noConsensusEscalation: true,
|
|
291
|
+
rounds: this.config.maxRounds,
|
|
292
|
+
totalVotes: votes.length,
|
|
293
|
+
},
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
buildConsensusOutput(decision, votes, rounds, reached) {
|
|
297
|
+
const votesByRound = new Map();
|
|
298
|
+
for (const vote of votes) {
|
|
299
|
+
const existing = votesByRound.get(vote.round) ?? [];
|
|
300
|
+
existing.push(vote);
|
|
301
|
+
votesByRound.set(vote.round, existing);
|
|
302
|
+
}
|
|
303
|
+
let output = reached
|
|
304
|
+
? `CONSENSUS REACHED\n\nDecision: ${decision}\n\n`
|
|
305
|
+
: `NO CONSENSUS\n\n`;
|
|
306
|
+
output += `Rounds: ${rounds}\nResolution method: ${this.config.resolution}\nThreshold: ${Math.round(this.config.threshold * 100)}%\n\n`;
|
|
307
|
+
output += '=== Vote History ===\n\n';
|
|
308
|
+
for (const [round, roundVotes] of votesByRound) {
|
|
309
|
+
output += `Round ${round}:\n`;
|
|
310
|
+
for (const vote of roundVotes) {
|
|
311
|
+
output += ` ${vote.agentName}: ${vote.decision}${vote.weight !== 1 ? ` (weight: ${vote.weight})` : ''}\n`;
|
|
312
|
+
}
|
|
313
|
+
output += '\n';
|
|
314
|
+
}
|
|
315
|
+
const finalVotes = votes.filter(v => v.round === rounds);
|
|
316
|
+
const voteCounts = new Map();
|
|
317
|
+
for (const vote of finalVotes) {
|
|
318
|
+
const key = vote.decision.toLowerCase().trim();
|
|
319
|
+
voteCounts.set(key, (voteCounts.get(key) ?? 0) + 1);
|
|
320
|
+
}
|
|
321
|
+
output += '=== Final Vote Tally ===\n';
|
|
322
|
+
for (const [decision, count] of voteCounts) {
|
|
323
|
+
output += ` ${decision}: ${count} votes\n`;
|
|
324
|
+
}
|
|
325
|
+
return output;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
//# sourceMappingURL=consensus.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"consensus.js","sourceRoot":"","sources":["../../src/strategies/consensus.ts"],"names":[],"mappings":"AAAA;;GAEG;AAUH,OAAO,EAA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AAC;gBAC9B,MAAM,IAAI,KAAK,IAAI,CAAC,SAAS,KAAK,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC,MAAM,KAAK,CAAC,CAAC,CAAC,CAAC,aAAa,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC;YAC7G,CAAC;YACD,MAAM,IAAI,IAAI,CAAC;QACjB,CAAC;QAED,MAAM,UAAU,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,KAAK,KAAK,MAAM,CAAC,CAAC;QACzD,MAAM,UAAU,GAAG,IAAI,GAAG,EAAkB,CAAC;QAC7C,KAAK,MAAM,IAAI,IAAI,UAAU,EAAE,CAAC;YAC9B,MAAM,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE,CAAC;YAC/C,UAAU,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC;QACtD,CAAC;QAED,MAAM,IAAI,4BAA4B,CAAC;QACvC,KAAK,MAAM,CAAC,QAAQ,EAAE,KAAK,CAAC,IAAI,UAAU,EAAE,CAAC;YAC3C,MAAM,IAAI,KAAK,QAAQ,KAAK,KAAK,UAAU,CAAC;QAC9C,CAAC;QAED,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debate strategy - Agents argue positions, moderator synthesizes
|
|
3
|
+
*/
|
|
4
|
+
import type { SwarmRunOptions, StrategyResult, DebateConfig } from '@cogitator-ai/types';
|
|
5
|
+
import { BaseStrategy } from './base';
|
|
6
|
+
import type { SwarmCoordinator } from '../coordinator';
|
|
7
|
+
export declare class DebateStrategy extends BaseStrategy {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(coordinator: SwarmCoordinator, config: DebateConfig);
|
|
10
|
+
execute(options: SwarmRunOptions): Promise<StrategyResult>;
|
|
11
|
+
private getPreviousArguments;
|
|
12
|
+
private buildDebateInstructions;
|
|
13
|
+
private synthesizeDebate;
|
|
14
|
+
}
|
|
15
|
+
//# sourceMappingURL=debate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debate.d.ts","sourceRoot":"","sources":["../../src/strategies/debate.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,YAAY,EAGb,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,qBAAa,cAAe,SAAQ,YAAY;IAC9C,OAAO,CAAC,MAAM,CAAe;gBAEjB,WAAW,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY;IAQzD,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAmJhE,OAAO,CAAC,oBAAoB;IAe5B,OAAO,CAAC,uBAAuB;IA6B/B,OAAO,CAAC,gBAAgB;CAuBzB"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Debate strategy - Agents argue positions, moderator synthesizes
|
|
3
|
+
*/
|
|
4
|
+
import { BaseStrategy } from './base';
|
|
5
|
+
export class DebateStrategy extends BaseStrategy {
|
|
6
|
+
config;
|
|
7
|
+
constructor(coordinator, config) {
|
|
8
|
+
super(coordinator);
|
|
9
|
+
this.config = {
|
|
10
|
+
format: 'structured',
|
|
11
|
+
...config,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
async execute(options) {
|
|
15
|
+
const agentResults = new Map();
|
|
16
|
+
const debateTranscript = [];
|
|
17
|
+
const advocates = this.coordinator.getAgents().filter((a) => a.metadata.role === 'advocate');
|
|
18
|
+
const critics = this.coordinator.getAgents().filter((a) => a.metadata.role === 'critic');
|
|
19
|
+
const moderators = this.coordinator.getAgents().filter((a) => a.metadata.role === 'moderator');
|
|
20
|
+
let debaters = [...advocates, ...critics];
|
|
21
|
+
if (debaters.length === 0) {
|
|
22
|
+
debaters = this.coordinator.getAgents().filter((a) => a.metadata.role !== 'moderator');
|
|
23
|
+
}
|
|
24
|
+
if (debaters.length < 2) {
|
|
25
|
+
throw new Error('Debate strategy requires at least 2 debating agents');
|
|
26
|
+
}
|
|
27
|
+
const moderator = moderators.length > 0 ? moderators[0] : null;
|
|
28
|
+
this.coordinator.blackboard.write('debate', {
|
|
29
|
+
topic: options.input,
|
|
30
|
+
rounds: this.config.rounds,
|
|
31
|
+
currentRound: 0,
|
|
32
|
+
arguments: [],
|
|
33
|
+
}, 'system');
|
|
34
|
+
for (let round = 1; round <= this.config.rounds; round++) {
|
|
35
|
+
this.coordinator.events.emit('debate:round', { round, total: this.config.rounds });
|
|
36
|
+
const debateState = this.coordinator.blackboard.read('debate');
|
|
37
|
+
this.coordinator.blackboard.write('debate', {
|
|
38
|
+
...debateState,
|
|
39
|
+
currentRound: round,
|
|
40
|
+
}, 'system');
|
|
41
|
+
for (const debater of debaters) {
|
|
42
|
+
const previousArguments = this.getPreviousArguments(debateTranscript, round);
|
|
43
|
+
const debaterContext = {
|
|
44
|
+
...options.context,
|
|
45
|
+
debateContext: {
|
|
46
|
+
round,
|
|
47
|
+
totalRounds: this.config.rounds,
|
|
48
|
+
role: debater.metadata.role ?? 'debater',
|
|
49
|
+
previousArguments,
|
|
50
|
+
format: this.config.format,
|
|
51
|
+
},
|
|
52
|
+
debateInstructions: this.buildDebateInstructions(debater.metadata.role ?? 'debater', round, this.config.rounds, previousArguments),
|
|
53
|
+
};
|
|
54
|
+
const input = round === 1
|
|
55
|
+
? options.input
|
|
56
|
+
: `Continue the debate on: ${options.input}\n\nPrevious arguments:\n${previousArguments}`;
|
|
57
|
+
this.coordinator.events.emit('debate:turn', {
|
|
58
|
+
round,
|
|
59
|
+
agent: debater.agent.name,
|
|
60
|
+
role: debater.metadata.role,
|
|
61
|
+
}, debater.agent.name);
|
|
62
|
+
const result = await this.coordinator.runAgent(debater.agent.name, input, debaterContext);
|
|
63
|
+
agentResults.set(`${debater.agent.name}_round${round}`, result);
|
|
64
|
+
const message = {
|
|
65
|
+
id: `debate_${round}_${debater.agent.name}`,
|
|
66
|
+
swarmId: '',
|
|
67
|
+
from: debater.agent.name,
|
|
68
|
+
to: 'broadcast',
|
|
69
|
+
type: 'notification',
|
|
70
|
+
content: result.output,
|
|
71
|
+
channel: 'debate',
|
|
72
|
+
timestamp: Date.now(),
|
|
73
|
+
metadata: { round, role: debater.metadata.role },
|
|
74
|
+
};
|
|
75
|
+
debateTranscript.push(message);
|
|
76
|
+
const currentDebate = this.coordinator.blackboard.read('debate');
|
|
77
|
+
currentDebate.arguments.push({
|
|
78
|
+
agent: debater.agent.name,
|
|
79
|
+
role: debater.metadata.role,
|
|
80
|
+
round,
|
|
81
|
+
argument: result.output,
|
|
82
|
+
});
|
|
83
|
+
this.coordinator.blackboard.write('debate', currentDebate, debater.agent.name);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
let finalOutput;
|
|
87
|
+
let moderatorResult;
|
|
88
|
+
if (moderator) {
|
|
89
|
+
const synthesisInput = `
|
|
90
|
+
Synthesize the following debate on the topic: "${options.input}"
|
|
91
|
+
|
|
92
|
+
Debate transcript:
|
|
93
|
+
${debateTranscript.map((m) => `[${m.metadata?.role ?? m.from}]: ${m.content}`).join('\n\n')}
|
|
94
|
+
|
|
95
|
+
Please provide:
|
|
96
|
+
1. A balanced summary of the key arguments from each side
|
|
97
|
+
2. Points of agreement and disagreement
|
|
98
|
+
3. Your assessment of the strongest arguments
|
|
99
|
+
4. A final recommendation or conclusion
|
|
100
|
+
`.trim();
|
|
101
|
+
moderatorResult = await this.coordinator.runAgent(moderator.agent.name, synthesisInput, {
|
|
102
|
+
...options.context,
|
|
103
|
+
moderatorContext: {
|
|
104
|
+
debateRounds: this.config.rounds,
|
|
105
|
+
participantCount: debaters.length,
|
|
106
|
+
format: this.config.format,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
agentResults.set(moderator.agent.name, moderatorResult);
|
|
110
|
+
finalOutput = moderatorResult.output;
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
finalOutput = this.synthesizeDebate(debateTranscript, options.input);
|
|
114
|
+
}
|
|
115
|
+
return {
|
|
116
|
+
output: finalOutput,
|
|
117
|
+
structured: moderatorResult?.structured,
|
|
118
|
+
agentResults,
|
|
119
|
+
debateTranscript,
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
getPreviousArguments(transcript, currentRound) {
|
|
123
|
+
const previousMessages = transcript.filter((m) => m.metadata?.round < currentRound);
|
|
124
|
+
if (previousMessages.length === 0)
|
|
125
|
+
return '';
|
|
126
|
+
return previousMessages
|
|
127
|
+
.map((m) => `[${m.metadata?.role ?? m.from}]: ${m.content}`)
|
|
128
|
+
.join('\n\n');
|
|
129
|
+
}
|
|
130
|
+
buildDebateInstructions(role, round, totalRounds, previousArguments) {
|
|
131
|
+
const roleInstructions = {
|
|
132
|
+
advocate: 'You are arguing IN FAVOR of the proposition. Find compelling reasons to support it.',
|
|
133
|
+
critic: 'You are arguing AGAINST the proposition. Find weaknesses and raise objections.',
|
|
134
|
+
debater: 'Present your perspective on the topic with well-reasoned arguments.',
|
|
135
|
+
};
|
|
136
|
+
const instruction = roleInstructions[role] ?? roleInstructions.debater;
|
|
137
|
+
return `
|
|
138
|
+
${instruction}
|
|
139
|
+
|
|
140
|
+
This is round ${round} of ${totalRounds}.
|
|
141
|
+
${previousArguments ? '\nConsider and respond to the previous arguments when formulating your position.' : ''}
|
|
142
|
+
|
|
143
|
+
Guidelines:
|
|
144
|
+
- Be concise but thorough
|
|
145
|
+
- Support your claims with reasoning
|
|
146
|
+
- Address counterarguments if applicable
|
|
147
|
+
- Maintain a professional and constructive tone
|
|
148
|
+
${this.config.format === 'structured' ? '- Structure your argument with clear points' : ''}
|
|
149
|
+
`.trim();
|
|
150
|
+
}
|
|
151
|
+
synthesizeDebate(transcript, topic) {
|
|
152
|
+
const argumentsByAgent = {};
|
|
153
|
+
for (const msg of transcript) {
|
|
154
|
+
const agent = msg.from;
|
|
155
|
+
if (!argumentsByAgent[agent]) {
|
|
156
|
+
argumentsByAgent[agent] = [];
|
|
157
|
+
}
|
|
158
|
+
argumentsByAgent[agent].push(msg.content);
|
|
159
|
+
}
|
|
160
|
+
let summary = `Debate Summary on: "${topic}"\n\n`;
|
|
161
|
+
for (const [agent, args] of Object.entries(argumentsByAgent)) {
|
|
162
|
+
summary += `=== ${agent} ===\n`;
|
|
163
|
+
args.forEach((arg, i) => {
|
|
164
|
+
summary += `Round ${i + 1}: ${arg.slice(0, 200)}...\n`;
|
|
165
|
+
});
|
|
166
|
+
summary += '\n';
|
|
167
|
+
}
|
|
168
|
+
return summary;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
//# sourceMappingURL=debate.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"debate.js","sourceRoot":"","sources":["../../src/strategies/debate.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAGtC,MAAM,OAAO,cAAe,SAAQ,YAAY;IACtC,MAAM,CAAe;IAE7B,YAAY,WAA6B,EAAE,MAAoB;QAC7D,KAAK,CAAC,WAAW,CAAC,CAAC;QACnB,IAAI,CAAC,MAAM,GAAG;YACZ,MAAM,EAAE,YAAY;YACpB,GAAG,MAAM;SACV,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,OAAwB;QACpC,MAAM,YAAY,GAAG,IAAI,GAAG,EAAqB,CAAC;QAClD,MAAM,gBAAgB,GAAmB,EAAE,CAAC;QAE5C,MAAM,SAAS,GAAG,IAAI,CAAC,WAAW,CAAC,SAAS,EAAE,CAA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AAgB,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;YAC/B,CAAC;YACD,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;QAC5C,CAAC;QAED,IAAI,OAAO,GAAG,uBAAuB,KAAK,OAAO,CAAC;QAElD,KAAK,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,EAAE,CAAC;YAC7D,OAAO,IAAI,OAAO,KAAK,QAAQ,CAAC;YAChC,IAAI,CAAC,OAAO,CAAC,CAAC,GAAG,EAAE,CAAC,EAAE,EAAE;gBACtB,OAAO,IAAI,SAAS,CAAC,GAAG,CAAC,KAAK,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC;YACzD,CAAC,CAAC,CAAC;YACH,OAAO,IAAI,IAAI,CAAC;QAClB,CAAC;QAED,OAAO,OAAO,CAAC;IACjB,CAAC;CACF"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hierarchical strategy - Supervisor delegates to workers
|
|
3
|
+
*/
|
|
4
|
+
import type { SwarmRunOptions, StrategyResult, HierarchicalConfig } from '@cogitator-ai/types';
|
|
5
|
+
import { BaseStrategy } from './base';
|
|
6
|
+
import type { SwarmCoordinator } from '../coordinator';
|
|
7
|
+
export declare class HierarchicalStrategy extends BaseStrategy {
|
|
8
|
+
private config;
|
|
9
|
+
constructor(coordinator: SwarmCoordinator, config?: HierarchicalConfig);
|
|
10
|
+
execute(options: SwarmRunOptions): Promise<StrategyResult>;
|
|
11
|
+
private buildDelegationInstructions;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=hierarchical.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hierarchical.d.ts","sourceRoot":"","sources":["../../src/strategies/hierarchical.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,KAAK,EACV,eAAe,EACf,cAAc,EACd,kBAAkB,EAEnB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AACtC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAEvD,qBAAa,oBAAqB,SAAQ,YAAY;IACpD,OAAO,CAAC,MAAM,CAAqB;gBAEvB,WAAW,EAAE,gBAAgB,EAAE,MAAM,CAAC,EAAE,kBAAkB;IAWhE,OAAO,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,cAAc,CAAC;IAsDhE,OAAO,CAAC,2BAA2B;CAkCpC"}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hierarchical strategy - Supervisor delegates to workers
|
|
3
|
+
*/
|
|
4
|
+
import { BaseStrategy } from './base';
|
|
5
|
+
export class HierarchicalStrategy extends BaseStrategy {
|
|
6
|
+
config;
|
|
7
|
+
constructor(coordinator, config) {
|
|
8
|
+
super(coordinator);
|
|
9
|
+
this.config = {
|
|
10
|
+
maxDelegationDepth: 3,
|
|
11
|
+
workerCommunication: false,
|
|
12
|
+
routeThrough: 'supervisor',
|
|
13
|
+
visibility: 'full',
|
|
14
|
+
...config,
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
async execute(options) {
|
|
18
|
+
const agentResults = new Map();
|
|
19
|
+
const supervisors = this.coordinator.getAgents().filter((a) => a.metadata.role === 'supervisor');
|
|
20
|
+
if (supervisors.length === 0) {
|
|
21
|
+
throw new Error('Hierarchical strategy requires a supervisor agent');
|
|
22
|
+
}
|
|
23
|
+
const supervisor = supervisors[0];
|
|
24
|
+
const workers = this.coordinator.getAgents().filter((a) => a.metadata.role === 'worker');
|
|
25
|
+
const workerInfo = workers.map((w) => ({
|
|
26
|
+
name: w.agent.name,
|
|
27
|
+
description: w.agent.config.description ?? w.agent.config.instructions.slice(0, 200),
|
|
28
|
+
expertise: w.metadata.expertise ?? [],
|
|
29
|
+
}));
|
|
30
|
+
const supervisorContext = {
|
|
31
|
+
...options.context,
|
|
32
|
+
availableWorkers: workerInfo,
|
|
33
|
+
hierarchyConfig: {
|
|
34
|
+
maxDelegationDepth: this.config.maxDelegationDepth,
|
|
35
|
+
workerCommunication: this.config.workerCommunication,
|
|
36
|
+
},
|
|
37
|
+
delegationInstructions: this.buildDelegationInstructions(workerInfo),
|
|
38
|
+
};
|
|
39
|
+
this.coordinator.blackboard.write('tasks', [], 'system');
|
|
40
|
+
this.coordinator.blackboard.write('workerResults', {}, 'system');
|
|
41
|
+
const supervisorResult = await this.coordinator.runAgent(supervisor.agent.name, options.input, supervisorContext);
|
|
42
|
+
agentResults.set(supervisor.agent.name, supervisorResult);
|
|
43
|
+
for (const worker of workers) {
|
|
44
|
+
if (worker.lastResult) {
|
|
45
|
+
agentResults.set(worker.agent.name, worker.lastResult);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
return {
|
|
49
|
+
output: supervisorResult.output,
|
|
50
|
+
structured: supervisorResult.structured,
|
|
51
|
+
agentResults,
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
buildDelegationInstructions(workerInfo) {
|
|
55
|
+
const workerList = workerInfo
|
|
56
|
+
.map((w) => {
|
|
57
|
+
const expertise = w.expertise.length > 0 ? ` (expertise: ${w.expertise.join(', ')})` : '';
|
|
58
|
+
return `- ${w.name}: ${w.description}${expertise}`;
|
|
59
|
+
})
|
|
60
|
+
.join('\n');
|
|
61
|
+
return `
|
|
62
|
+
You are a supervisor managing a team of workers. You can delegate tasks to workers and coordinate their work.
|
|
63
|
+
|
|
64
|
+
Available workers:
|
|
65
|
+
${workerList}
|
|
66
|
+
|
|
67
|
+
You can use the following tools to manage your team:
|
|
68
|
+
- delegate_task(worker, task): Assign a task to a specific worker
|
|
69
|
+
- check_progress(worker): Check the status and last output of a worker
|
|
70
|
+
- request_revision(worker, feedback): Ask a worker to revise their work
|
|
71
|
+
|
|
72
|
+
Your job is to:
|
|
73
|
+
1. Analyze the incoming task
|
|
74
|
+
2. Break it down into subtasks suitable for your workers
|
|
75
|
+
3. Delegate subtasks to appropriate workers
|
|
76
|
+
4. Coordinate and synthesize their outputs
|
|
77
|
+
5. Provide a final response
|
|
78
|
+
|
|
79
|
+
Important:
|
|
80
|
+
- Workers cannot see each other's outputs unless you share them via your coordination
|
|
81
|
+
- You are responsible for quality control and final output
|
|
82
|
+
- If a worker's output is insufficient, request a revision
|
|
83
|
+
`.trim();
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
//# sourceMappingURL=hierarchical.js.map
|