agentic-flow 1.6.3 → 1.6.4

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.
@@ -0,0 +1,543 @@
1
+ # QUIC Swarm Coordination - Quick Start Guide
2
+
3
+ This guide will help you get started with QUIC-enabled multi-agent swarm coordination in agentic-flow.
4
+
5
+ ## Table of Contents
6
+
7
+ 1. [Installation](#installation)
8
+ 2. [Basic Usage](#basic-usage)
9
+ 3. [Topology Selection](#topology-selection)
10
+ 4. [Transport Configuration](#transport-configuration)
11
+ 5. [Agent Registration](#agent-registration)
12
+ 6. [Statistics & Monitoring](#statistics--monitoring)
13
+ 7. [Common Patterns](#common-patterns)
14
+ 8. [Troubleshooting](#troubleshooting)
15
+
16
+ ## Installation
17
+
18
+ ```bash
19
+ npm install agentic-flow
20
+ ```
21
+
22
+ ## Basic Usage
23
+
24
+ ### Initialize a Simple Swarm
25
+
26
+ ```typescript
27
+ import { initSwarm } from 'agentic-flow';
28
+
29
+ const swarm = await initSwarm({
30
+ swarmId: 'my-swarm',
31
+ topology: 'mesh',
32
+ transport: 'quic',
33
+ quicPort: 4433
34
+ });
35
+ ```
36
+
37
+ ### Register Agents
38
+
39
+ ```typescript
40
+ await swarm.registerAgent({
41
+ id: 'agent-1',
42
+ role: 'worker',
43
+ host: 'localhost',
44
+ port: 4434,
45
+ capabilities: ['compute', 'analyze']
46
+ });
47
+ ```
48
+
49
+ ### Get Statistics
50
+
51
+ ```typescript
52
+ const stats = await swarm.getStats();
53
+ console.log('Swarm stats:', stats);
54
+ ```
55
+
56
+ ### Cleanup
57
+
58
+ ```typescript
59
+ await swarm.shutdown();
60
+ ```
61
+
62
+ ## Topology Selection
63
+
64
+ ### Mesh Topology (Peer-to-Peer)
65
+
66
+ Best for: Small swarms (<20 agents), maximum redundancy
67
+
68
+ ```typescript
69
+ const swarm = await initSwarm({
70
+ swarmId: 'mesh-swarm',
71
+ topology: 'mesh',
72
+ transport: 'quic',
73
+ maxAgents: 10
74
+ });
75
+ ```
76
+
77
+ **Characteristics**:
78
+ - All agents connect to all others
79
+ - O(n²) connections
80
+ - No single point of failure
81
+ - Ideal for distributed consensus
82
+
83
+ ### Hierarchical Topology (Coordinator-Worker)
84
+
85
+ Best for: Large swarms (100+ agents), centralized task distribution
86
+
87
+ ```typescript
88
+ const swarm = await initSwarm({
89
+ swarmId: 'hierarchical-swarm',
90
+ topology: 'hierarchical',
91
+ transport: 'quic',
92
+ maxAgents: 100
93
+ });
94
+
95
+ // Register coordinators
96
+ await swarm.registerAgent({
97
+ id: 'coordinator-1',
98
+ role: 'coordinator',
99
+ host: 'localhost',
100
+ port: 4433,
101
+ capabilities: ['orchestrate']
102
+ });
103
+
104
+ // Register workers
105
+ await swarm.registerAgent({
106
+ id: 'worker-1',
107
+ role: 'worker',
108
+ host: 'localhost',
109
+ port: 4434,
110
+ capabilities: ['compute']
111
+ });
112
+ ```
113
+
114
+ **Characteristics**:
115
+ - Workers communicate through coordinators
116
+ - O(n) connections
117
+ - Scalable to 100+ agents
118
+ - Ideal for task distribution
119
+
120
+ ### Ring Topology (Circular)
121
+
122
+ Best for: Ordered processing, pipeline architectures
123
+
124
+ ```typescript
125
+ const swarm = await initSwarm({
126
+ swarmId: 'ring-swarm',
127
+ topology: 'ring',
128
+ transport: 'quic',
129
+ maxAgents: 8
130
+ });
131
+ ```
132
+
133
+ **Characteristics**:
134
+ - Each agent connects to next in circle
135
+ - O(n) connections
136
+ - Predictable message flow
137
+ - Ideal for pipelines
138
+
139
+ ### Star Topology (Hub and Spoke)
140
+
141
+ Best for: Simple coordination, fan-out/fan-in patterns
142
+
143
+ ```typescript
144
+ const swarm = await initSwarm({
145
+ swarmId: 'star-swarm',
146
+ topology: 'star',
147
+ transport: 'quic',
148
+ maxAgents: 20
149
+ });
150
+
151
+ // Register central coordinator
152
+ await swarm.registerAgent({
153
+ id: 'central',
154
+ role: 'coordinator',
155
+ host: 'localhost',
156
+ port: 4433,
157
+ capabilities: ['coordinate']
158
+ });
159
+
160
+ // Register spoke agents
161
+ await swarm.registerAgent({
162
+ id: 'spoke-1',
163
+ role: 'worker',
164
+ host: 'localhost',
165
+ port: 4434,
166
+ capabilities: ['compute']
167
+ });
168
+ ```
169
+
170
+ **Characteristics**:
171
+ - All messages through central coordinator
172
+ - O(n) connections
173
+ - Single coordination point
174
+ - Simple to manage
175
+
176
+ ## Transport Configuration
177
+
178
+ ### QUIC Transport (Recommended)
179
+
180
+ Fastest option with 0-RTT connection establishment:
181
+
182
+ ```typescript
183
+ const swarm = await initSwarm({
184
+ swarmId: 'quic-swarm',
185
+ topology: 'mesh',
186
+ transport: 'quic',
187
+ quicPort: 4433,
188
+ quicHost: 'localhost'
189
+ });
190
+ ```
191
+
192
+ **Features**:
193
+ - 0-RTT connection establishment
194
+ - 100+ concurrent streams per connection
195
+ - No head-of-line blocking
196
+ - Connection migration support
197
+
198
+ ### HTTP/2 Transport (Fallback)
199
+
200
+ Compatible fallback option:
201
+
202
+ ```typescript
203
+ const swarm = await initSwarm({
204
+ swarmId: 'http2-swarm',
205
+ topology: 'mesh',
206
+ transport: 'http2',
207
+ quicPort: 8443 // HTTP/2 port
208
+ });
209
+ ```
210
+
211
+ **Features**:
212
+ - Universal compatibility
213
+ - Proven reliability
214
+ - Standard TLS security
215
+
216
+ ### Auto Transport (Default)
217
+
218
+ Automatically select best available transport:
219
+
220
+ ```typescript
221
+ const swarm = await initSwarm({
222
+ swarmId: 'auto-swarm',
223
+ topology: 'mesh',
224
+ transport: 'auto', // Try QUIC, fallback to HTTP/2
225
+ enableFallback: true
226
+ });
227
+ ```
228
+
229
+ **Features**:
230
+ - Automatic protocol selection
231
+ - Transparent fallback
232
+ - Continuous health monitoring
233
+ - Best performance available
234
+
235
+ ## Agent Registration
236
+
237
+ ### Basic Agent
238
+
239
+ ```typescript
240
+ await swarm.registerAgent({
241
+ id: 'agent-1',
242
+ role: 'worker',
243
+ host: 'localhost',
244
+ port: 4434,
245
+ capabilities: ['compute']
246
+ });
247
+ ```
248
+
249
+ ### Agent with Metadata
250
+
251
+ ```typescript
252
+ await swarm.registerAgent({
253
+ id: 'agent-2',
254
+ role: 'worker',
255
+ host: 'agent-2.example.com',
256
+ port: 4435,
257
+ capabilities: ['compute', 'analyze', 'aggregate'],
258
+ metadata: {
259
+ region: 'us-east-1',
260
+ instance_type: 'c5.2xlarge',
261
+ max_concurrent_tasks: 10
262
+ }
263
+ });
264
+ ```
265
+
266
+ ### Unregister Agent
267
+
268
+ ```typescript
269
+ await swarm.unregisterAgent('agent-1');
270
+ ```
271
+
272
+ ## Statistics & Monitoring
273
+
274
+ ### Swarm Statistics
275
+
276
+ ```typescript
277
+ const stats = await swarm.getStats();
278
+
279
+ console.log('Swarm ID:', stats.swarmId);
280
+ console.log('Topology:', stats.topology);
281
+ console.log('Transport:', stats.transport);
282
+ console.log('QUIC Available:', stats.quicAvailable);
283
+ console.log('Total Agents:', stats.coordinatorStats?.totalAgents);
284
+ console.log('Active Agents:', stats.coordinatorStats?.activeAgents);
285
+ console.log('Total Messages:', stats.coordinatorStats?.totalMessages);
286
+ console.log('Avg Latency:', stats.coordinatorStats?.averageLatency, 'ms');
287
+ ```
288
+
289
+ ### Transport Statistics
290
+
291
+ ```typescript
292
+ const stats = await swarm.getStats();
293
+
294
+ if (stats.transportStats instanceof Map) {
295
+ const quicStats = stats.transportStats.get('quic');
296
+ const http2Stats = stats.transportStats.get('http2');
297
+
298
+ console.log('QUIC Stats:', quicStats);
299
+ console.log('HTTP/2 Stats:', http2Stats);
300
+ }
301
+ ```
302
+
303
+ ### Per-Agent Statistics
304
+
305
+ ```typescript
306
+ // Access through coordinator if available
307
+ const coordinator = swarm.router?.getCoordinator();
308
+ if (coordinator) {
309
+ const agentStats = coordinator.getAgentStats('agent-1');
310
+ console.log('Agent Stats:', agentStats);
311
+
312
+ const allStats = coordinator.getAllAgentStats();
313
+ console.log('All Agent Stats:', allStats);
314
+ }
315
+ ```
316
+
317
+ ## Common Patterns
318
+
319
+ ### Pattern 1: Distributed Computation
320
+
321
+ ```typescript
322
+ // Initialize mesh swarm for distributed computation
323
+ const swarm = await initSwarm({
324
+ swarmId: 'compute-swarm',
325
+ topology: 'mesh',
326
+ transport: 'quic',
327
+ maxAgents: 10
328
+ });
329
+
330
+ // Register compute nodes
331
+ for (let i = 1; i <= 10; i++) {
332
+ await swarm.registerAgent({
333
+ id: `compute-${i}`,
334
+ role: 'worker',
335
+ host: `compute-${i}.local`,
336
+ port: 4433 + i,
337
+ capabilities: ['compute', 'verify']
338
+ });
339
+ }
340
+
341
+ // Agents can now communicate peer-to-peer
342
+ // for distributed computation tasks
343
+ ```
344
+
345
+ ### Pattern 2: Task Distribution Pipeline
346
+
347
+ ```typescript
348
+ // Initialize hierarchical swarm for task distribution
349
+ const swarm = await initSwarm({
350
+ swarmId: 'pipeline-swarm',
351
+ topology: 'hierarchical',
352
+ transport: 'quic',
353
+ maxAgents: 50
354
+ });
355
+
356
+ // Register task coordinators
357
+ for (let i = 1; i <= 5; i++) {
358
+ await swarm.registerAgent({
359
+ id: `coordinator-${i}`,
360
+ role: 'coordinator',
361
+ host: `coordinator-${i}.local`,
362
+ port: 4433,
363
+ capabilities: ['distribute', 'aggregate']
364
+ });
365
+ }
366
+
367
+ // Register processing workers
368
+ for (let i = 1; i <= 40; i++) {
369
+ await swarm.registerAgent({
370
+ id: `worker-${i}`,
371
+ role: 'worker',
372
+ host: `worker-${i}.local`,
373
+ port: 4434 + i,
374
+ capabilities: ['process']
375
+ });
376
+ }
377
+ ```
378
+
379
+ ### Pattern 3: Data Processing Pipeline
380
+
381
+ ```typescript
382
+ // Initialize ring swarm for sequential processing
383
+ const swarm = await initSwarm({
384
+ swarmId: 'data-pipeline',
385
+ topology: 'ring',
386
+ transport: 'quic',
387
+ maxAgents: 5
388
+ });
389
+
390
+ // Register pipeline stages
391
+ const stages = ['ingest', 'validate', 'transform', 'enrich', 'store'];
392
+ for (let i = 0; i < stages.length; i++) {
393
+ await swarm.registerAgent({
394
+ id: `stage-${stages[i]}`,
395
+ role: 'worker',
396
+ host: `stage-${i}.local`,
397
+ port: 4433 + i,
398
+ capabilities: [stages[i]]
399
+ });
400
+ }
401
+
402
+ // Data flows through stages in order
403
+ ```
404
+
405
+ ### Pattern 4: Hub-Based Coordination
406
+
407
+ ```typescript
408
+ // Initialize star swarm for centralized coordination
409
+ const swarm = await initSwarm({
410
+ swarmId: 'hub-swarm',
411
+ topology: 'star',
412
+ transport: 'quic',
413
+ maxAgents: 20
414
+ });
415
+
416
+ // Register central hub
417
+ await swarm.registerAgent({
418
+ id: 'hub',
419
+ role: 'coordinator',
420
+ host: 'hub.local',
421
+ port: 4433,
422
+ capabilities: ['coordinate', 'aggregate', 'monitor']
423
+ });
424
+
425
+ // Register spoke agents
426
+ for (let i = 1; i <= 15; i++) {
427
+ await swarm.registerAgent({
428
+ id: `spoke-${i}`,
429
+ role: 'worker',
430
+ host: `spoke-${i}.local`,
431
+ port: 4434 + i,
432
+ capabilities: ['process']
433
+ });
434
+ }
435
+
436
+ // All communication goes through hub
437
+ ```
438
+
439
+ ## Troubleshooting
440
+
441
+ ### QUIC Not Available
442
+
443
+ **Problem**: Swarm falls back to HTTP/2 unexpectedly
444
+
445
+ **Solutions**:
446
+ 1. Check WASM module is loaded:
447
+ ```typescript
448
+ import { checkQuicAvailability } from 'agentic-flow';
449
+ const available = await checkQuicAvailability();
450
+ console.log('QUIC available:', available);
451
+ ```
452
+
453
+ 2. Verify TLS certificates (if using peer verification):
454
+ ```bash
455
+ ls -la ./certs/cert.pem
456
+ ls -la ./certs/key.pem
457
+ ```
458
+
459
+ 3. Check firewall allows UDP traffic on QUIC port:
460
+ ```bash
461
+ sudo ufw allow 4433/udp
462
+ ```
463
+
464
+ ### High Message Latency
465
+
466
+ **Problem**: Messages taking longer than expected
467
+
468
+ **Solutions**:
469
+ 1. Check transport being used:
470
+ ```typescript
471
+ const stats = await swarm.getStats();
472
+ console.log('Current transport:', stats.transport);
473
+ ```
474
+
475
+ 2. Enable QUIC explicitly:
476
+ ```typescript
477
+ const swarm = await initSwarm({
478
+ transport: 'quic',
479
+ enableFallback: false
480
+ });
481
+ ```
482
+
483
+ 3. Monitor QUIC statistics:
484
+ ```typescript
485
+ const quicStats = stats.transportStats?.get('quic');
486
+ console.log('RTT:', quicStats?.rttMs, 'ms');
487
+ console.log('Packet loss:', quicStats?.packetsLost);
488
+ ```
489
+
490
+ ### Connection Pool Exhaustion
491
+
492
+ **Problem**: "Maximum connections reached" errors
493
+
494
+ **Solutions**:
495
+ 1. Increase max agents:
496
+ ```typescript
497
+ const swarm = await initSwarm({
498
+ maxAgents: 50 // Increase from default 10
499
+ });
500
+ ```
501
+
502
+ 2. Use hierarchical topology for better scaling:
503
+ ```typescript
504
+ const swarm = await initSwarm({
505
+ topology: 'hierarchical' // Better for large swarms
506
+ });
507
+ ```
508
+
509
+ ### Agent Registration Failures
510
+
511
+ **Problem**: Cannot register new agents
512
+
513
+ **Solutions**:
514
+ 1. Check max agents limit:
515
+ ```typescript
516
+ const stats = await swarm.getStats();
517
+ console.log('Total agents:', stats.coordinatorStats?.totalAgents);
518
+ console.log('Max agents:', stats.coordinatorStats?.maxAgents);
519
+ ```
520
+
521
+ 2. Verify agent connectivity:
522
+ ```bash
523
+ nc -zv agent-1.local 4434
524
+ ```
525
+
526
+ 3. Check for duplicate agent IDs:
527
+ ```typescript
528
+ await swarm.unregisterAgent('existing-agent-id');
529
+ await swarm.registerAgent({ id: 'existing-agent-id', ... });
530
+ ```
531
+
532
+ ## Next Steps
533
+
534
+ - Read the [Architecture Documentation](../architecture/QUIC-SWARM-INTEGRATION.md)
535
+ - Explore [Example Applications](../../examples/)
536
+ - Learn about [Transport Configuration](../guides/QUIC-TRANSPORT-CONFIG.md)
537
+ - See [Performance Benchmarks](../validation-reports/QUIC-PERFORMANCE.md)
538
+
539
+ ## Support
540
+
541
+ - GitHub Issues: https://github.com/ruvnet/agentic-flow/issues
542
+ - Documentation: https://github.com/ruvnet/agentic-flow/docs
543
+ - Examples: https://github.com/ruvnet/agentic-flow/examples