elsabro 2.3.0 → 3.8.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/README.md +698 -20
- package/bin/install.js +0 -0
- package/flows/development-flow.json +452 -0
- package/flows/quick-flow.json +118 -0
- package/hooks/hooks-config-updated.json +285 -0
- package/hooks/skill-discovery.sh +539 -0
- package/package.json +3 -2
- package/references/SYSTEM_INDEX.md +400 -5
- package/references/agent-marketplace.md +2274 -0
- package/references/agent-protocol.md +1126 -0
- package/references/ai-code-suggestions.md +2413 -0
- package/references/checkpointing.md +595 -0
- package/references/collaboration-patterns.md +851 -0
- package/references/collaborative-sessions.md +1081 -0
- package/references/configuration-management.md +1810 -0
- package/references/cost-tracking.md +1095 -0
- package/references/enterprise-sso.md +2001 -0
- package/references/error-contracts-v2.md +968 -0
- package/references/event-driven.md +1031 -0
- package/references/flow-orchestration.md +940 -0
- package/references/flow-visualization.md +1557 -0
- package/references/ide-integrations.md +3513 -0
- package/references/interrupt-system.md +681 -0
- package/references/kubernetes-deployment.md +3099 -0
- package/references/memory-system.md +683 -0
- package/references/mobile-companion.md +3236 -0
- package/references/multi-llm-providers.md +2494 -0
- package/references/multi-project-memory.md +1182 -0
- package/references/observability.md +793 -0
- package/references/output-schemas.md +858 -0
- package/references/performance-profiler.md +955 -0
- package/references/plugin-system.md +1526 -0
- package/references/prompt-management.md +292 -0
- package/references/sandbox-execution.md +303 -0
- package/references/security-system.md +1253 -0
- package/references/skill-marketplace-integration.md +3901 -0
- package/references/streaming.md +696 -0
- package/references/testing-framework.md +1151 -0
- package/references/time-travel.md +802 -0
- package/references/tool-registry.md +886 -0
- package/references/voice-commands.md +3296 -0
- package/templates/agent-marketplace-config.json +220 -0
- package/templates/agent-protocol-config.json +136 -0
- package/templates/ai-suggestions-config.json +100 -0
- package/templates/checkpoint-state.json +61 -0
- package/templates/collaboration-config.json +157 -0
- package/templates/collaborative-sessions-config.json +153 -0
- package/templates/configuration-config.json +245 -0
- package/templates/cost-tracking-config.json +148 -0
- package/templates/enterprise-sso-config.json +438 -0
- package/templates/events-config.json +148 -0
- package/templates/flow-visualization-config.json +196 -0
- package/templates/ide-integrations-config.json +442 -0
- package/templates/kubernetes-config.json +764 -0
- package/templates/memory-state.json +84 -0
- package/templates/mobile-companion-config.json +600 -0
- package/templates/multi-llm-config.json +544 -0
- package/templates/multi-project-memory-config.json +145 -0
- package/templates/observability-config.json +109 -0
- package/templates/performance-profiler-config.json +125 -0
- package/templates/plugin-config.json +170 -0
- package/templates/prompt-management-config.json +86 -0
- package/templates/sandbox-config.json +185 -0
- package/templates/schemas-config.json +65 -0
- package/templates/security-config.json +120 -0
- package/templates/skill-marketplace-config.json +441 -0
- package/templates/streaming-config.json +72 -0
- package/templates/testing-config.json +81 -0
- package/templates/timetravel-config.json +62 -0
- package/templates/tool-registry-config.json +109 -0
- package/templates/voice-commands-config.json +658 -0
|
@@ -0,0 +1,851 @@
|
|
|
1
|
+
# Agent Collaboration Patterns (v3.3)
|
|
2
|
+
|
|
3
|
+
Patrones avanzados de colaboración entre agentes para orquestación de tareas complejas.
|
|
4
|
+
|
|
5
|
+
## Arquitectura
|
|
6
|
+
|
|
7
|
+
```
|
|
8
|
+
┌─────────────────────────────────────────────────────────────────────────┐
|
|
9
|
+
│ COLLABORATION PATTERNS │
|
|
10
|
+
├─────────────────────────────────────────────────────────────────────────┤
|
|
11
|
+
│ │
|
|
12
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
13
|
+
│ │ PATTERN LIBRARY │ │
|
|
14
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
15
|
+
│ │ │ Supervisor │ │ Hierarchical│ │ Consensus │ │ │
|
|
16
|
+
│ │ │ (1 coord) │ │ (tree) │ │ (voting) │ │ │
|
|
17
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
18
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
19
|
+
│ │ │ Debate │ │ Round-Robin │ │ Swarm │ │ │
|
|
20
|
+
│ │ │ (adversary) │ │ (rotation) │ │ (emergent) │ │ │
|
|
21
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
22
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
23
|
+
│ │ │
|
|
24
|
+
│ ▼ │
|
|
25
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
26
|
+
│ │ COLLABORATION MANAGER │ │
|
|
27
|
+
│ │ ┌─────────────────────────────────────────────────────────┐ │ │
|
|
28
|
+
│ │ │ Pattern Selection → Team Assembly → Execution │ │ │
|
|
29
|
+
│ │ └─────────────────────────────────────────────────────────┘ │ │
|
|
30
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
31
|
+
│ │ │
|
|
32
|
+
│ ▼ │
|
|
33
|
+
│ ┌─────────────────────────────────────────────────────────────────┐ │
|
|
34
|
+
│ │ COMMUNICATION LAYER │ │
|
|
35
|
+
│ │ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │ │
|
|
36
|
+
│ │ │ Messages │ │ Shared │ │ Blackboard │ │ │
|
|
37
|
+
│ │ │ (direct) │ │ Memory │ │ (broadcast)│ │ │
|
|
38
|
+
│ │ └─────────────┘ └─────────────┘ └─────────────┘ │ │
|
|
39
|
+
│ └─────────────────────────────────────────────────────────────────┘ │
|
|
40
|
+
│ │
|
|
41
|
+
└─────────────────────────────────────────────────────────────────────────┘
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
---
|
|
45
|
+
|
|
46
|
+
## Patrones Disponibles
|
|
47
|
+
|
|
48
|
+
### 1. Supervisor Pattern
|
|
49
|
+
|
|
50
|
+
Un agente supervisor coordina y delega a agentes workers.
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
┌─────────────┐
|
|
54
|
+
│ Supervisor │
|
|
55
|
+
│ (Opus) │
|
|
56
|
+
└──────┬──────┘
|
|
57
|
+
│
|
|
58
|
+
┌──────────┼──────────┐
|
|
59
|
+
│ │ │
|
|
60
|
+
▼ ▼ ▼
|
|
61
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
62
|
+
│ Worker1 │ │ Worker2 │ │ Worker3 │
|
|
63
|
+
│ (Haiku) │ │ (Haiku) │ │ (Haiku) │
|
|
64
|
+
└─────────┘ └─────────┘ └─────────┘
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
```typescript
|
|
68
|
+
interface SupervisorConfig {
|
|
69
|
+
supervisor: {
|
|
70
|
+
agentType: string;
|
|
71
|
+
model: 'opus' | 'sonnet';
|
|
72
|
+
maxDelegations: number;
|
|
73
|
+
};
|
|
74
|
+
workers: {
|
|
75
|
+
agentTypes: string[];
|
|
76
|
+
model: 'haiku' | 'sonnet';
|
|
77
|
+
maxConcurrent: number;
|
|
78
|
+
};
|
|
79
|
+
routing: 'round-robin' | 'capability' | 'load-balance';
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
class SupervisorPattern implements CollaborationPattern {
|
|
83
|
+
name = 'supervisor';
|
|
84
|
+
|
|
85
|
+
async execute(task: Task, config: SupervisorConfig): Promise<CollaborationResult> {
|
|
86
|
+
const supervisor = await this.createAgent(config.supervisor);
|
|
87
|
+
const workers = await this.createWorkerPool(config.workers);
|
|
88
|
+
|
|
89
|
+
// Supervisor analyzes task
|
|
90
|
+
const plan = await supervisor.analyze(task);
|
|
91
|
+
|
|
92
|
+
// Delegate subtasks to workers
|
|
93
|
+
const results: SubtaskResult[] = [];
|
|
94
|
+
|
|
95
|
+
for (const subtask of plan.subtasks) {
|
|
96
|
+
const worker = this.selectWorker(workers, subtask, config.routing);
|
|
97
|
+
const result = await worker.execute(subtask);
|
|
98
|
+
results.push(result);
|
|
99
|
+
|
|
100
|
+
// Supervisor can re-delegate on failure
|
|
101
|
+
if (!result.success && plan.allowRetry) {
|
|
102
|
+
const retryResult = await this.retryWithDifferentWorker(
|
|
103
|
+
workers, subtask, worker
|
|
104
|
+
);
|
|
105
|
+
results.push(retryResult);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Supervisor synthesizes results
|
|
110
|
+
const finalResult = await supervisor.synthesize(results);
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
pattern: 'supervisor',
|
|
114
|
+
success: finalResult.success,
|
|
115
|
+
result: finalResult,
|
|
116
|
+
metrics: {
|
|
117
|
+
delegations: plan.subtasks.length,
|
|
118
|
+
workerUtilization: this.calculateUtilization(workers)
|
|
119
|
+
}
|
|
120
|
+
};
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
**Uso ideal**: Tareas con subtareas claras e independientes.
|
|
126
|
+
|
|
127
|
+
---
|
|
128
|
+
|
|
129
|
+
### 2. Hierarchical Pattern
|
|
130
|
+
|
|
131
|
+
Estructura de árbol con múltiples niveles de supervisión.
|
|
132
|
+
|
|
133
|
+
```
|
|
134
|
+
┌─────────────┐
|
|
135
|
+
│ Leader │
|
|
136
|
+
│ (Opus) │
|
|
137
|
+
└──────┬──────┘
|
|
138
|
+
│
|
|
139
|
+
┌───────────┼───────────┐
|
|
140
|
+
│ │
|
|
141
|
+
▼ ▼
|
|
142
|
+
┌─────────────┐ ┌─────────────┐
|
|
143
|
+
│ Team Lead A │ │ Team Lead B │
|
|
144
|
+
│ (Sonnet) │ │ (Sonnet) │
|
|
145
|
+
└──────┬──────┘ └──────┬──────┘
|
|
146
|
+
│ │
|
|
147
|
+
┌─────┼─────┐ ┌─────┼─────┐
|
|
148
|
+
│ │ │ │ │ │
|
|
149
|
+
▼ ▼ ▼ ▼ ▼ ▼
|
|
150
|
+
W1 W2 W3 W4 W5 W6
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
```typescript
|
|
154
|
+
interface HierarchicalConfig {
|
|
155
|
+
levels: HierarchyLevel[];
|
|
156
|
+
communicationMode: 'strict' | 'skip-level-allowed';
|
|
157
|
+
escalationPolicy: EscalationPolicy;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
interface HierarchyLevel {
|
|
161
|
+
name: string;
|
|
162
|
+
agentType: string;
|
|
163
|
+
model: string;
|
|
164
|
+
maxChildren: number;
|
|
165
|
+
responsibilities: string[];
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class HierarchicalPattern implements CollaborationPattern {
|
|
169
|
+
name = 'hierarchical';
|
|
170
|
+
|
|
171
|
+
async execute(task: Task, config: HierarchicalConfig): Promise<CollaborationResult> {
|
|
172
|
+
// Build hierarchy tree
|
|
173
|
+
const root = await this.buildHierarchy(config.levels);
|
|
174
|
+
|
|
175
|
+
// Top-down task decomposition
|
|
176
|
+
const taskTree = await this.decomposeTask(task, root);
|
|
177
|
+
|
|
178
|
+
// Bottom-up execution
|
|
179
|
+
const result = await this.executeBottomUp(taskTree);
|
|
180
|
+
|
|
181
|
+
// Rollup results
|
|
182
|
+
return this.rollupResults(result);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
private async executeBottomUp(node: TaskNode): Promise<NodeResult> {
|
|
186
|
+
// Execute children first (if any)
|
|
187
|
+
if (node.children.length > 0) {
|
|
188
|
+
const childResults = await Promise.all(
|
|
189
|
+
node.children.map(child => this.executeBottomUp(child))
|
|
190
|
+
);
|
|
191
|
+
|
|
192
|
+
// Parent synthesizes child results
|
|
193
|
+
return node.agent.synthesize(childResults);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
// Leaf node executes directly
|
|
197
|
+
return node.agent.execute(node.task);
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
**Uso ideal**: Proyectos grandes con equipos especializados.
|
|
203
|
+
|
|
204
|
+
---
|
|
205
|
+
|
|
206
|
+
### 3. Consensus Pattern
|
|
207
|
+
|
|
208
|
+
Múltiples agentes votan para tomar decisiones.
|
|
209
|
+
|
|
210
|
+
```
|
|
211
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
212
|
+
│ Agent 1 │ │ Agent 2 │ │ Agent 3 │
|
|
213
|
+
│ (Opus) │ │ (Opus) │ │ (Opus) │
|
|
214
|
+
└────┬────┘ └────┬────┘ └────┬────┘
|
|
215
|
+
│ │ │
|
|
216
|
+
▼ ▼ ▼
|
|
217
|
+
└────────────┼────────────┘
|
|
218
|
+
│
|
|
219
|
+
┌──────▼──────┐
|
|
220
|
+
│ Voting │
|
|
221
|
+
│ System │
|
|
222
|
+
└──────┬──────┘
|
|
223
|
+
│
|
|
224
|
+
┌──────▼──────┐
|
|
225
|
+
│ Consensus │
|
|
226
|
+
│ Result │
|
|
227
|
+
└─────────────┘
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
```typescript
|
|
231
|
+
interface ConsensusConfig {
|
|
232
|
+
voters: {
|
|
233
|
+
count: number;
|
|
234
|
+
agentType: string;
|
|
235
|
+
model: string;
|
|
236
|
+
};
|
|
237
|
+
votingStrategy: 'majority' | 'unanimous' | 'weighted' | 'quorum';
|
|
238
|
+
quorumThreshold?: number; // For 'quorum' strategy
|
|
239
|
+
weights?: Record<string, number>; // For 'weighted' strategy
|
|
240
|
+
maxRounds: number;
|
|
241
|
+
tieBreaker: 'random' | 'first' | 'supervisor';
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
interface Vote {
|
|
245
|
+
agentId: string;
|
|
246
|
+
decision: string;
|
|
247
|
+
confidence: number;
|
|
248
|
+
reasoning: string;
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
class ConsensusPattern implements CollaborationPattern {
|
|
252
|
+
name = 'consensus';
|
|
253
|
+
|
|
254
|
+
async execute(task: Task, config: ConsensusConfig): Promise<CollaborationResult> {
|
|
255
|
+
const voters = await this.createVoters(config.voters);
|
|
256
|
+
|
|
257
|
+
let round = 0;
|
|
258
|
+
let consensus: string | null = null;
|
|
259
|
+
|
|
260
|
+
while (round < config.maxRounds && !consensus) {
|
|
261
|
+
round++;
|
|
262
|
+
|
|
263
|
+
// Each voter analyzes independently
|
|
264
|
+
const votes = await Promise.all(
|
|
265
|
+
voters.map(voter => voter.vote(task))
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// Count votes
|
|
269
|
+
consensus = this.countVotes(votes, config);
|
|
270
|
+
|
|
271
|
+
// If no consensus, share reasoning and re-vote
|
|
272
|
+
if (!consensus) {
|
|
273
|
+
await this.shareReasoning(voters, votes);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// Handle tie
|
|
278
|
+
if (!consensus) {
|
|
279
|
+
consensus = await this.breakTie(votes, config.tieBreaker);
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
return {
|
|
283
|
+
pattern: 'consensus',
|
|
284
|
+
success: true,
|
|
285
|
+
result: consensus,
|
|
286
|
+
metrics: {
|
|
287
|
+
rounds: round,
|
|
288
|
+
votes: votes,
|
|
289
|
+
consensusReached: round < config.maxRounds
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
private countVotes(votes: Vote[], config: ConsensusConfig): string | null {
|
|
295
|
+
const counts = new Map<string, number>();
|
|
296
|
+
|
|
297
|
+
for (const vote of votes) {
|
|
298
|
+
const weight = config.weights?.[vote.agentId] || 1;
|
|
299
|
+
const current = counts.get(vote.decision) || 0;
|
|
300
|
+
counts.set(vote.decision, current + weight);
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
const totalWeight = votes.reduce(
|
|
304
|
+
(sum, v) => sum + (config.weights?.[v.agentId] || 1), 0
|
|
305
|
+
);
|
|
306
|
+
|
|
307
|
+
for (const [decision, count] of counts) {
|
|
308
|
+
switch (config.votingStrategy) {
|
|
309
|
+
case 'majority':
|
|
310
|
+
if (count > totalWeight / 2) return decision;
|
|
311
|
+
break;
|
|
312
|
+
case 'unanimous':
|
|
313
|
+
if (count === totalWeight) return decision;
|
|
314
|
+
break;
|
|
315
|
+
case 'quorum':
|
|
316
|
+
if (count >= totalWeight * (config.quorumThreshold || 0.66)) return decision;
|
|
317
|
+
break;
|
|
318
|
+
case 'weighted':
|
|
319
|
+
if (count > totalWeight / 2) return decision;
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return null;
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
**Uso ideal**: Decisiones críticas, code reviews, evaluaciones.
|
|
330
|
+
|
|
331
|
+
---
|
|
332
|
+
|
|
333
|
+
### 4. Debate Pattern
|
|
334
|
+
|
|
335
|
+
Agentes argumentan posiciones opuestas para refinar decisiones.
|
|
336
|
+
|
|
337
|
+
```
|
|
338
|
+
┌─────────────┐ ┌─────────────┐
|
|
339
|
+
│ Advocate │ ◄──────► │ Critic │
|
|
340
|
+
│ (Pro) │ Debate │ (Con) │
|
|
341
|
+
└──────┬──────┘ └──────┬──────┘
|
|
342
|
+
│ │
|
|
343
|
+
└───────────┬─────────────┘
|
|
344
|
+
│
|
|
345
|
+
┌──────▼──────┐
|
|
346
|
+
│ Judge │
|
|
347
|
+
│ (Opus) │
|
|
348
|
+
└──────┬──────┘
|
|
349
|
+
│
|
|
350
|
+
┌──────▼──────┐
|
|
351
|
+
│ Refined │
|
|
352
|
+
│ Decision │
|
|
353
|
+
└─────────────┘
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
```typescript
|
|
357
|
+
interface DebateConfig {
|
|
358
|
+
advocate: {
|
|
359
|
+
agentType: string;
|
|
360
|
+
model: string;
|
|
361
|
+
position: 'pro' | 'assigned';
|
|
362
|
+
};
|
|
363
|
+
critic: {
|
|
364
|
+
agentType: string;
|
|
365
|
+
model: string;
|
|
366
|
+
position: 'con' | 'devils-advocate';
|
|
367
|
+
};
|
|
368
|
+
judge: {
|
|
369
|
+
agentType: string;
|
|
370
|
+
model: string;
|
|
371
|
+
};
|
|
372
|
+
rounds: number;
|
|
373
|
+
format: 'structured' | 'free-form';
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
interface DebateRound {
|
|
377
|
+
round: number;
|
|
378
|
+
advocateArgument: string;
|
|
379
|
+
criticArgument: string;
|
|
380
|
+
advocateRebuttal?: string;
|
|
381
|
+
criticRebuttal?: string;
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
class DebatePattern implements CollaborationPattern {
|
|
385
|
+
name = 'debate';
|
|
386
|
+
|
|
387
|
+
async execute(task: Task, config: DebateConfig): Promise<CollaborationResult> {
|
|
388
|
+
const advocate = await this.createAgent(config.advocate);
|
|
389
|
+
const critic = await this.createAgent(config.critic);
|
|
390
|
+
const judge = await this.createAgent(config.judge);
|
|
391
|
+
|
|
392
|
+
const rounds: DebateRound[] = [];
|
|
393
|
+
|
|
394
|
+
// Initial positions
|
|
395
|
+
const advocatePosition = await advocate.formPosition(task);
|
|
396
|
+
const criticPosition = await critic.formPosition(task);
|
|
397
|
+
|
|
398
|
+
for (let i = 0; i < config.rounds; i++) {
|
|
399
|
+
const round: DebateRound = {
|
|
400
|
+
round: i + 1,
|
|
401
|
+
advocateArgument: '',
|
|
402
|
+
criticArgument: ''
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
// Advocate presents argument
|
|
406
|
+
round.advocateArgument = await advocate.argue(
|
|
407
|
+
task,
|
|
408
|
+
criticPosition,
|
|
409
|
+
rounds
|
|
410
|
+
);
|
|
411
|
+
|
|
412
|
+
// Critic responds
|
|
413
|
+
round.criticArgument = await critic.argue(
|
|
414
|
+
task,
|
|
415
|
+
advocatePosition,
|
|
416
|
+
rounds
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
// Rebuttals (if structured format)
|
|
420
|
+
if (config.format === 'structured') {
|
|
421
|
+
round.advocateRebuttal = await advocate.rebut(round.criticArgument);
|
|
422
|
+
round.criticRebuttal = await critic.rebut(round.advocateArgument);
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
rounds.push(round);
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
// Judge evaluates debate
|
|
429
|
+
const judgment = await judge.evaluate({
|
|
430
|
+
task,
|
|
431
|
+
advocatePosition,
|
|
432
|
+
criticPosition,
|
|
433
|
+
rounds
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
return {
|
|
437
|
+
pattern: 'debate',
|
|
438
|
+
success: true,
|
|
439
|
+
result: judgment.decision,
|
|
440
|
+
metrics: {
|
|
441
|
+
rounds: rounds.length,
|
|
442
|
+
judgment: judgment,
|
|
443
|
+
strengthOfArguments: {
|
|
444
|
+
advocate: judgment.advocateScore,
|
|
445
|
+
critic: judgment.criticScore
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
};
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
```
|
|
452
|
+
|
|
453
|
+
**Uso ideal**: Decisiones de arquitectura, trade-off analysis, risk assessment.
|
|
454
|
+
|
|
455
|
+
---
|
|
456
|
+
|
|
457
|
+
### 5. Round-Robin Pattern
|
|
458
|
+
|
|
459
|
+
Agentes toman turnos procesando partes de una tarea.
|
|
460
|
+
|
|
461
|
+
```
|
|
462
|
+
┌─────────┐ ┌─────────┐ ┌─────────┐
|
|
463
|
+
│ Agent 1 │───►│ Agent 2 │───►│ Agent 3 │
|
|
464
|
+
└────┬────┘ └────┬────┘ └────┬────┘
|
|
465
|
+
│ │ │
|
|
466
|
+
▼ ▼ ▼
|
|
467
|
+
Part 1 Part 2 Part 3
|
|
468
|
+
│ │ │
|
|
469
|
+
└──────────────┼──────────────┘
|
|
470
|
+
│
|
|
471
|
+
┌──────▼──────┐
|
|
472
|
+
│ Combined │
|
|
473
|
+
│ Result │
|
|
474
|
+
└─────────────┘
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
```typescript
|
|
478
|
+
interface RoundRobinConfig {
|
|
479
|
+
agents: {
|
|
480
|
+
agentType: string;
|
|
481
|
+
model: string;
|
|
482
|
+
specialty?: string;
|
|
483
|
+
}[];
|
|
484
|
+
rotationMode: 'sequential' | 'by-specialty' | 'adaptive';
|
|
485
|
+
handoffMode: 'full-context' | 'summary-only' | 'delta-only';
|
|
486
|
+
maxRounds?: number;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
class RoundRobinPattern implements CollaborationPattern {
|
|
490
|
+
name = 'round-robin';
|
|
491
|
+
|
|
492
|
+
async execute(task: Task, config: RoundRobinConfig): Promise<CollaborationResult> {
|
|
493
|
+
const agents = await this.createAgents(config.agents);
|
|
494
|
+
const parts = await this.partitionTask(task, agents.length);
|
|
495
|
+
|
|
496
|
+
let context = { task, previousResults: [] as PartResult[] };
|
|
497
|
+
const results: PartResult[] = [];
|
|
498
|
+
|
|
499
|
+
for (let i = 0; i < parts.length; i++) {
|
|
500
|
+
const agent = this.selectAgent(agents, parts[i], config.rotationMode, i);
|
|
501
|
+
|
|
502
|
+
// Prepare handoff context
|
|
503
|
+
const handoff = this.prepareHandoff(context, config.handoffMode);
|
|
504
|
+
|
|
505
|
+
// Execute part
|
|
506
|
+
const result = await agent.execute(parts[i], handoff);
|
|
507
|
+
results.push(result);
|
|
508
|
+
|
|
509
|
+
// Update context
|
|
510
|
+
context.previousResults.push(result);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
// Combine results
|
|
514
|
+
const combined = await this.combineResults(results);
|
|
515
|
+
|
|
516
|
+
return {
|
|
517
|
+
pattern: 'round-robin',
|
|
518
|
+
success: combined.success,
|
|
519
|
+
result: combined,
|
|
520
|
+
metrics: {
|
|
521
|
+
partsProcessed: parts.length,
|
|
522
|
+
agentUtilization: this.calculateUtilization(agents, results)
|
|
523
|
+
}
|
|
524
|
+
};
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
private prepareHandoff(
|
|
528
|
+
context: Context,
|
|
529
|
+
mode: string
|
|
530
|
+
): Handoff {
|
|
531
|
+
switch (mode) {
|
|
532
|
+
case 'full-context':
|
|
533
|
+
return { ...context };
|
|
534
|
+
case 'summary-only':
|
|
535
|
+
return {
|
|
536
|
+
task: context.task,
|
|
537
|
+
previousSummary: this.summarize(context.previousResults)
|
|
538
|
+
};
|
|
539
|
+
case 'delta-only':
|
|
540
|
+
return {
|
|
541
|
+
task: context.task,
|
|
542
|
+
lastResult: context.previousResults.slice(-1)[0]
|
|
543
|
+
};
|
|
544
|
+
default:
|
|
545
|
+
return context;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
```
|
|
550
|
+
|
|
551
|
+
**Uso ideal**: Pipelines de procesamiento, iteraciones de refinamiento.
|
|
552
|
+
|
|
553
|
+
---
|
|
554
|
+
|
|
555
|
+
### 6. Swarm Pattern
|
|
556
|
+
|
|
557
|
+
Agentes auto-organizados trabajan en paralelo con comunicación emergente.
|
|
558
|
+
|
|
559
|
+
```
|
|
560
|
+
┌─────┐ ┌─────┐ ┌─────┐
|
|
561
|
+
│ A │───│ B │───│ C │
|
|
562
|
+
└──┬──┘ └──┬──┘ └──┬──┘
|
|
563
|
+
│ │ │
|
|
564
|
+
┌──┼─────────┼─────────┼──┐
|
|
565
|
+
│ │ BLACKBOARD (shared) │
|
|
566
|
+
│ │ ┌─────────┐ │
|
|
567
|
+
│ └───►│ Problem │◄──────┤
|
|
568
|
+
│ │ Space │ │
|
|
569
|
+
│ └─────────┘ │
|
|
570
|
+
│ │ │
|
|
571
|
+
│ ┌─────┼─────┐ │
|
|
572
|
+
│ ▼ ▼ ▼ │
|
|
573
|
+
│ ┌────┐┌────┐┌────┐ │
|
|
574
|
+
│ │Sol1││Sol2││Sol3│ │
|
|
575
|
+
│ └────┘└────┘└────┘ │
|
|
576
|
+
└─────────────────────────┘
|
|
577
|
+
```
|
|
578
|
+
|
|
579
|
+
```typescript
|
|
580
|
+
interface SwarmConfig {
|
|
581
|
+
agents: {
|
|
582
|
+
count: number;
|
|
583
|
+
agentType: string;
|
|
584
|
+
model: string;
|
|
585
|
+
};
|
|
586
|
+
blackboard: {
|
|
587
|
+
enabled: boolean;
|
|
588
|
+
capacity: number;
|
|
589
|
+
};
|
|
590
|
+
termination: {
|
|
591
|
+
mode: 'solution-found' | 'convergence' | 'timeout' | 'iterations';
|
|
592
|
+
threshold?: number;
|
|
593
|
+
timeout?: number;
|
|
594
|
+
maxIterations?: number;
|
|
595
|
+
};
|
|
596
|
+
communication: {
|
|
597
|
+
mode: 'broadcast' | 'neighbor' | 'pheromone';
|
|
598
|
+
frequency: 'continuous' | 'periodic';
|
|
599
|
+
};
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
class SwarmPattern implements CollaborationPattern {
|
|
603
|
+
name = 'swarm';
|
|
604
|
+
|
|
605
|
+
async execute(task: Task, config: SwarmConfig): Promise<CollaborationResult> {
|
|
606
|
+
const agents = await this.createSwarm(config.agents);
|
|
607
|
+
const blackboard = new Blackboard(config.blackboard);
|
|
608
|
+
|
|
609
|
+
// Initialize problem space
|
|
610
|
+
await blackboard.initialize(task);
|
|
611
|
+
|
|
612
|
+
let iterations = 0;
|
|
613
|
+
let converged = false;
|
|
614
|
+
|
|
615
|
+
while (!this.shouldTerminate(blackboard, config, iterations, converged)) {
|
|
616
|
+
iterations++;
|
|
617
|
+
|
|
618
|
+
// All agents work in parallel
|
|
619
|
+
const contributions = await Promise.all(
|
|
620
|
+
agents.map(agent => agent.contribute(blackboard.getState()))
|
|
621
|
+
);
|
|
622
|
+
|
|
623
|
+
// Update blackboard with contributions
|
|
624
|
+
for (const contribution of contributions) {
|
|
625
|
+
await blackboard.apply(contribution);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
// Check for convergence
|
|
629
|
+
converged = this.checkConvergence(blackboard.getHistory());
|
|
630
|
+
|
|
631
|
+
// Communicate based on mode
|
|
632
|
+
if (config.communication.mode === 'pheromone') {
|
|
633
|
+
await this.updatePheromones(blackboard, contributions);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
|
|
637
|
+
// Extract best solution
|
|
638
|
+
const solution = blackboard.getBestSolution();
|
|
639
|
+
|
|
640
|
+
return {
|
|
641
|
+
pattern: 'swarm',
|
|
642
|
+
success: solution !== null,
|
|
643
|
+
result: solution,
|
|
644
|
+
metrics: {
|
|
645
|
+
iterations,
|
|
646
|
+
converged,
|
|
647
|
+
contributionCount: blackboard.getContributionCount(),
|
|
648
|
+
solutionQuality: blackboard.getSolutionQuality()
|
|
649
|
+
}
|
|
650
|
+
};
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
|
|
654
|
+
class Blackboard {
|
|
655
|
+
private state: BlackboardState;
|
|
656
|
+
private contributions: Contribution[];
|
|
657
|
+
private solutions: Solution[];
|
|
658
|
+
|
|
659
|
+
initialize(task: Task): void {
|
|
660
|
+
this.state = {
|
|
661
|
+
problem: task,
|
|
662
|
+
partialSolutions: [],
|
|
663
|
+
constraints: [],
|
|
664
|
+
insights: []
|
|
665
|
+
};
|
|
666
|
+
this.contributions = [];
|
|
667
|
+
this.solutions = [];
|
|
668
|
+
}
|
|
669
|
+
|
|
670
|
+
apply(contribution: Contribution): void {
|
|
671
|
+
this.contributions.push(contribution);
|
|
672
|
+
|
|
673
|
+
switch (contribution.type) {
|
|
674
|
+
case 'partial-solution':
|
|
675
|
+
this.state.partialSolutions.push(contribution.data);
|
|
676
|
+
break;
|
|
677
|
+
case 'constraint':
|
|
678
|
+
this.state.constraints.push(contribution.data);
|
|
679
|
+
break;
|
|
680
|
+
case 'insight':
|
|
681
|
+
this.state.insights.push(contribution.data);
|
|
682
|
+
break;
|
|
683
|
+
case 'solution':
|
|
684
|
+
this.solutions.push(contribution.data);
|
|
685
|
+
break;
|
|
686
|
+
}
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
getState(): BlackboardState {
|
|
690
|
+
return { ...this.state };
|
|
691
|
+
}
|
|
692
|
+
|
|
693
|
+
getBestSolution(): Solution | null {
|
|
694
|
+
if (this.solutions.length === 0) return null;
|
|
695
|
+
return this.solutions.sort((a, b) => b.quality - a.quality)[0];
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
```
|
|
699
|
+
|
|
700
|
+
**Uso ideal**: Problemas de optimización, exploración creativa, brainstorming.
|
|
701
|
+
|
|
702
|
+
---
|
|
703
|
+
|
|
704
|
+
## CollaborationManager
|
|
705
|
+
|
|
706
|
+
```typescript
|
|
707
|
+
class CollaborationManager {
|
|
708
|
+
private patterns: Map<string, CollaborationPattern>;
|
|
709
|
+
private config: CollaborationConfig;
|
|
710
|
+
|
|
711
|
+
constructor(config: CollaborationConfig) {
|
|
712
|
+
this.config = config;
|
|
713
|
+
this.patterns = this.registerPatterns();
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// Execute collaboration with pattern
|
|
717
|
+
async execute(
|
|
718
|
+
patternName: string,
|
|
719
|
+
task: Task,
|
|
720
|
+
config?: Record<string, unknown>
|
|
721
|
+
): Promise<CollaborationResult> {
|
|
722
|
+
const pattern = this.patterns.get(patternName);
|
|
723
|
+
if (!pattern) {
|
|
724
|
+
throw new Error(`Unknown pattern: ${patternName}`);
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
// Validate config
|
|
728
|
+
const validatedConfig = this.validateConfig(pattern, config);
|
|
729
|
+
|
|
730
|
+
// Create execution context
|
|
731
|
+
const context: ExecutionContext = {
|
|
732
|
+
task,
|
|
733
|
+
pattern: patternName,
|
|
734
|
+
startedAt: new Date(),
|
|
735
|
+
metrics: {}
|
|
736
|
+
};
|
|
737
|
+
|
|
738
|
+
// Emit start event
|
|
739
|
+
EventBus.publish('collaboration.started', {
|
|
740
|
+
pattern: patternName,
|
|
741
|
+
task: task.id
|
|
742
|
+
});
|
|
743
|
+
|
|
744
|
+
try {
|
|
745
|
+
// Execute pattern
|
|
746
|
+
const result = await pattern.execute(task, validatedConfig);
|
|
747
|
+
|
|
748
|
+
// Record metrics
|
|
749
|
+
context.metrics = result.metrics;
|
|
750
|
+
context.completedAt = new Date();
|
|
751
|
+
|
|
752
|
+
// Emit completion event
|
|
753
|
+
EventBus.publish('collaboration.completed', {
|
|
754
|
+
pattern: patternName,
|
|
755
|
+
task: task.id,
|
|
756
|
+
success: result.success
|
|
757
|
+
});
|
|
758
|
+
|
|
759
|
+
return result;
|
|
760
|
+
} catch (error) {
|
|
761
|
+
// Emit failure event
|
|
762
|
+
EventBus.publish('collaboration.failed', {
|
|
763
|
+
pattern: patternName,
|
|
764
|
+
task: task.id,
|
|
765
|
+
error: (error as Error).message
|
|
766
|
+
});
|
|
767
|
+
|
|
768
|
+
throw error;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
|
|
772
|
+
// Auto-select best pattern for task
|
|
773
|
+
async autoSelect(task: Task): Promise<string> {
|
|
774
|
+
const analysis = await this.analyzeTask(task);
|
|
775
|
+
|
|
776
|
+
// Pattern selection rules
|
|
777
|
+
if (analysis.needsConsensus) return 'consensus';
|
|
778
|
+
if (analysis.needsDebate) return 'debate';
|
|
779
|
+
if (analysis.isLargeScale) return 'hierarchical';
|
|
780
|
+
if (analysis.hasIndependentParts) return 'supervisor';
|
|
781
|
+
if (analysis.needsIteration) return 'round-robin';
|
|
782
|
+
if (analysis.needsCreativity) return 'swarm';
|
|
783
|
+
|
|
784
|
+
return 'supervisor'; // Default
|
|
785
|
+
}
|
|
786
|
+
|
|
787
|
+
// Get available patterns
|
|
788
|
+
getPatterns(): string[] {
|
|
789
|
+
return Array.from(this.patterns.keys());
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
private registerPatterns(): Map<string, CollaborationPattern> {
|
|
793
|
+
return new Map([
|
|
794
|
+
['supervisor', new SupervisorPattern()],
|
|
795
|
+
['hierarchical', new HierarchicalPattern()],
|
|
796
|
+
['consensus', new ConsensusPattern()],
|
|
797
|
+
['debate', new DebatePattern()],
|
|
798
|
+
['round-robin', new RoundRobinPattern()],
|
|
799
|
+
['swarm', new SwarmPattern()]
|
|
800
|
+
]);
|
|
801
|
+
}
|
|
802
|
+
}
|
|
803
|
+
```
|
|
804
|
+
|
|
805
|
+
---
|
|
806
|
+
|
|
807
|
+
## Comandos
|
|
808
|
+
|
|
809
|
+
```bash
|
|
810
|
+
/elsabro:collab list # Listar patrones
|
|
811
|
+
/elsabro:collab info supervisor # Detalles de patrón
|
|
812
|
+
/elsabro:collab run debate # Ejecutar con patrón
|
|
813
|
+
/elsabro:collab auto # Auto-seleccionar patrón
|
|
814
|
+
```
|
|
815
|
+
|
|
816
|
+
---
|
|
817
|
+
|
|
818
|
+
## Configuración
|
|
819
|
+
|
|
820
|
+
```json
|
|
821
|
+
{
|
|
822
|
+
"collaboration": {
|
|
823
|
+
"enabled": true,
|
|
824
|
+
"defaultPattern": "supervisor",
|
|
825
|
+
"patterns": {
|
|
826
|
+
"supervisor": {
|
|
827
|
+
"supervisorModel": "opus",
|
|
828
|
+
"workerModel": "haiku",
|
|
829
|
+
"maxWorkers": 4
|
|
830
|
+
},
|
|
831
|
+
"consensus": {
|
|
832
|
+
"voterCount": 3,
|
|
833
|
+
"strategy": "majority"
|
|
834
|
+
},
|
|
835
|
+
"debate": {
|
|
836
|
+
"rounds": 3,
|
|
837
|
+
"judgeModel": "opus"
|
|
838
|
+
}
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
```
|
|
843
|
+
|
|
844
|
+
---
|
|
845
|
+
|
|
846
|
+
## Changelog
|
|
847
|
+
|
|
848
|
+
- **v3.3.0**: Initial Collaboration Patterns
|
|
849
|
+
- 6 patterns: supervisor, hierarchical, consensus, debate, round-robin, swarm
|
|
850
|
+
- CollaborationManager with auto-selection
|
|
851
|
+
- Blackboard communication for swarm
|