claude_swarm 1.0.6 → 1.0.7

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.
Files changed (104) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +14 -0
  4. data/README.md +336 -1037
  5. data/docs/V1_TO_V2_MIGRATION_GUIDE.md +1120 -0
  6. data/docs/v1/README.md +1195 -0
  7. data/docs/v2/CHANGELOG.swarm_cli.md +22 -0
  8. data/docs/v2/CHANGELOG.swarm_memory.md +20 -0
  9. data/docs/v2/CHANGELOG.swarm_sdk.md +287 -10
  10. data/docs/v2/README.md +32 -6
  11. data/docs/v2/guides/complete-tutorial.md +133 -37
  12. data/docs/v2/guides/composable-swarms.md +1178 -0
  13. data/docs/v2/guides/getting-started.md +42 -1
  14. data/docs/v2/guides/snapshots.md +1498 -0
  15. data/docs/v2/reference/architecture-flow.md +5 -3
  16. data/docs/v2/reference/event_payload_structures.md +249 -12
  17. data/docs/v2/reference/execution-flow.md +1 -1
  18. data/docs/v2/reference/ruby-dsl.md +368 -22
  19. data/docs/v2/reference/yaml.md +314 -63
  20. data/examples/snapshot_demo.rb +119 -0
  21. data/examples/v2/dsl/01_basic.rb +0 -2
  22. data/examples/v2/dsl/02_core_parameters.rb +0 -2
  23. data/examples/v2/dsl/03_capabilities.rb +0 -2
  24. data/examples/v2/dsl/04_llm_parameters.rb +0 -2
  25. data/examples/v2/dsl/05_advanced_flags.rb +0 -3
  26. data/examples/v2/dsl/06_permissions.rb +0 -4
  27. data/examples/v2/dsl/07_mcp_server.rb +0 -2
  28. data/examples/v2/dsl/08_swarm_hooks.rb +0 -2
  29. data/examples/v2/dsl/09_agent_hooks.rb +0 -2
  30. data/examples/v2/dsl/10_all_agents_hooks.rb +0 -3
  31. data/examples/v2/dsl/11_delegation.rb +0 -2
  32. data/examples/v2/dsl/12_complete_integration.rb +2 -6
  33. data/examples/v2/node_context_demo.rb +1 -1
  34. data/examples/v2/node_workflow.rb +2 -4
  35. data/examples/v2/plan_and_execute.rb +157 -0
  36. data/lib/claude_swarm/configuration.rb +28 -4
  37. data/lib/claude_swarm/version.rb +1 -1
  38. data/lib/swarm_cli/formatters/human_formatter.rb +103 -0
  39. data/lib/swarm_cli/interactive_repl.rb +9 -3
  40. data/lib/swarm_cli/version.rb +1 -1
  41. data/lib/swarm_memory/core/storage_read_tracker.rb +51 -14
  42. data/lib/swarm_memory/integration/cli_registration.rb +3 -2
  43. data/lib/swarm_memory/integration/sdk_plugin.rb +11 -5
  44. data/lib/swarm_memory/tools/memory_edit.rb +2 -2
  45. data/lib/swarm_memory/tools/memory_multi_edit.rb +2 -2
  46. data/lib/swarm_memory/tools/memory_read.rb +3 -3
  47. data/lib/swarm_memory/version.rb +1 -1
  48. data/lib/swarm_memory.rb +5 -0
  49. data/lib/swarm_sdk/agent/builder.rb +33 -0
  50. data/lib/swarm_sdk/agent/chat/context_tracker.rb +33 -0
  51. data/lib/swarm_sdk/agent/chat/hook_integration.rb +49 -3
  52. data/lib/swarm_sdk/agent/chat/system_reminder_injector.rb +11 -27
  53. data/lib/swarm_sdk/agent/chat.rb +200 -51
  54. data/lib/swarm_sdk/agent/context.rb +6 -2
  55. data/lib/swarm_sdk/agent/context_manager.rb +6 -0
  56. data/lib/swarm_sdk/agent/definition.rb +14 -2
  57. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +180 -0
  58. data/lib/swarm_sdk/configuration.rb +387 -94
  59. data/lib/swarm_sdk/events_to_messages.rb +181 -0
  60. data/lib/swarm_sdk/log_collector.rb +31 -5
  61. data/lib/swarm_sdk/log_stream.rb +37 -8
  62. data/lib/swarm_sdk/model_aliases.json +4 -1
  63. data/lib/swarm_sdk/node/agent_config.rb +33 -8
  64. data/lib/swarm_sdk/node/builder.rb +39 -18
  65. data/lib/swarm_sdk/node_orchestrator.rb +293 -26
  66. data/lib/swarm_sdk/proc_helpers.rb +53 -0
  67. data/lib/swarm_sdk/providers/openai_with_responses.rb +22 -15
  68. data/lib/swarm_sdk/restore_result.rb +65 -0
  69. data/lib/swarm_sdk/snapshot.rb +156 -0
  70. data/lib/swarm_sdk/snapshot_from_events.rb +386 -0
  71. data/lib/swarm_sdk/state_restorer.rb +491 -0
  72. data/lib/swarm_sdk/state_snapshot.rb +369 -0
  73. data/lib/swarm_sdk/swarm/agent_initializer.rb +360 -55
  74. data/lib/swarm_sdk/swarm/all_agents_builder.rb +28 -1
  75. data/lib/swarm_sdk/swarm/builder.rb +208 -12
  76. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +67 -0
  77. data/lib/swarm_sdk/swarm/tool_configurator.rb +46 -11
  78. data/lib/swarm_sdk/swarm.rb +338 -42
  79. data/lib/swarm_sdk/swarm_loader.rb +145 -0
  80. data/lib/swarm_sdk/swarm_registry.rb +136 -0
  81. data/lib/swarm_sdk/tools/delegate.rb +92 -7
  82. data/lib/swarm_sdk/tools/read.rb +17 -5
  83. data/lib/swarm_sdk/tools/stores/read_tracker.rb +47 -12
  84. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +45 -0
  85. data/lib/swarm_sdk/utils.rb +18 -0
  86. data/lib/swarm_sdk/validation_result.rb +33 -0
  87. data/lib/swarm_sdk/version.rb +1 -1
  88. data/lib/swarm_sdk.rb +40 -8
  89. data/swarm_cli.gemspec +1 -1
  90. data/swarm_memory.gemspec +2 -2
  91. data/swarm_sdk.gemspec +2 -2
  92. metadata +21 -13
  93. data/examples/learning-assistant/assistant.md +0 -7
  94. data/examples/learning-assistant/example-memories/concept-example.md +0 -90
  95. data/examples/learning-assistant/example-memories/experience-example.md +0 -66
  96. data/examples/learning-assistant/example-memories/fact-example.md +0 -76
  97. data/examples/learning-assistant/example-memories/memory-index.md +0 -78
  98. data/examples/learning-assistant/example-memories/skill-example.md +0 -168
  99. data/examples/learning-assistant/learning_assistant.rb +0 -34
  100. data/examples/learning-assistant/learning_assistant.yml +0 -20
  101. data/lib/swarm_sdk/mcp.rb +0 -16
  102. data/llm.v2.txt +0 -13407
  103. /data/docs/v2/guides/{MEMORY_DEFRAG_GUIDE.md → memory-defrag-guide.md} +0 -0
  104. /data/{llms.txt → llms.claude-swarm.txt} +0 -0
@@ -0,0 +1,1120 @@
1
+ # Migration Guide: Claude Swarm v1 → SwarmSDK v2
2
+
3
+ A comprehensive guide for migrating from Claude Swarm (v1) to SwarmSDK (v2).
4
+
5
+ ---
6
+
7
+ ## 📖 Table of Contents
8
+
9
+ - [TL;DR: Quick Migration Summary](#tldr-quick-migration-summary)
10
+ - [Understanding the Changes](#understanding-the-changes)
11
+ - [Step-by-Step Migration](#step-by-step-migration)
12
+ - [Configuration Changes Reference](#configuration-changes-reference)
13
+ - [Migration Examples](#migration-examples)
14
+ - [Swarm Organization Best Practices](#swarm-organization-best-practices)
15
+ - [Common Migration Scenarios](#common-migration-scenarios)
16
+ - [Troubleshooting](#troubleshooting)
17
+
18
+ ---
19
+
20
+ ## TL;DR: Quick Migration Summary
21
+
22
+ ### What Changed?
23
+
24
+ SwarmSDK v2 is a **complete redesign** that's not backward compatible with Claude Swarm v1:
25
+
26
+ **Architecture:**
27
+ - ❌ **No more Claude Code dependency** - Decoupled from Claude Code entirely
28
+ - ✅ **Single process** - All agents run in one Ruby process using [RubyLLM](https://github.com/parruda/ruby_llm)
29
+ - ✅ **Direct method calls** - No more MCP inter-process communication overhead
30
+ - ✅ **More efficient** - Better performance and lower resource usage
31
+
32
+ **Configuration:**
33
+ - Change `version: 1` → `version: 2`
34
+ - Rename `instances` → `agents`
35
+ - Rename `connections` → `delegates_to`
36
+ - Rename `mcps` → `mcp_servers`
37
+ - Rename `allowed_tools` → `tools`
38
+ - Rename `prompt` → `system_prompt`
39
+
40
+ **New Features:**
41
+ - 🎯 Node workflows for multi-stage pipelines
42
+ - 🔧 Comprehensive hooks system (12 events, 6 action types)
43
+ - 🧠 SwarmMemory for persistent agent knowledge
44
+ - 🔌 Plugin system for extensibility
45
+ - 📊 Structured logging and cost tracking
46
+ - 🎮 Interactive REPL
47
+ - 🌐 Multiple LLM providers (Claude, OpenAI, Gemini, DeepSeek, etc.)
48
+
49
+ ### Migration Effort
50
+
51
+ 1. Update YAML field names
52
+ 2. Test and verify behavior
53
+ 3. Optional: Add new v2 features
54
+
55
+ ---
56
+
57
+ ## Understanding the Changes
58
+
59
+ ### Why SwarmSDK v2?
60
+
61
+ Claude Swarm v1 had architectural limitations:
62
+
63
+ **v1 Architecture (Multi-Process):**
64
+ ```
65
+ Main Claude Code Process
66
+ ├── MCP Server (Instance 1 - Claude Code)
67
+ ├── MCP Server (Instance 2 - Claude Code)
68
+ └── MCP Server (Instance 3 - Claude Code)
69
+ ```
70
+
71
+ **Problems:**
72
+ - Heavy resource usage (multiple Claude Code processes)
73
+ - MCP communication overhead (JSON serialization/deserialization)
74
+ - Complex state management across processes
75
+ - Limited control over agent behavior
76
+ - Tied to Claude Code's release cycle
77
+
78
+ **v2 Architecture (Single Process):**
79
+ ```
80
+ Single Ruby Process
81
+ ├── Agent 1 (RubyLLM)
82
+ ├── Agent 2 (RubyLLM)
83
+ └── Agent 3 (RubyLLM)
84
+ ```
85
+
86
+ **Benefits:**
87
+ - ✅ Lightweight - Single Ruby process
88
+ - ✅ Fast - Direct method calls
89
+ - ✅ Flexible - Any LLM provider
90
+ - ✅ Feature-rich - Hooks, workflows, memory
91
+ - ✅ Better DX - Ruby DSL, structured logging
92
+
93
+ ---
94
+
95
+ ## Step-by-Step Migration
96
+
97
+ ### Step 1: Install SwarmSDK
98
+
99
+ ```bash
100
+ # Install the CLI (includes swarm_sdk)
101
+ gem install swarm_cli
102
+
103
+ # Or add to your Gemfile
104
+ gem 'swarm_sdk', '~> 2.2'
105
+ gem 'swarm_cli', '~> 2.1'
106
+ ```
107
+
108
+ ### Step 2: Update Configuration Version
109
+
110
+ Change the version field:
111
+
112
+ ```yaml
113
+ # Before (v1)
114
+ version: 1
115
+
116
+ # After (v2)
117
+ version: 2
118
+ ```
119
+
120
+ ### Step 3: Update Field Names
121
+
122
+ Apply these systematic changes to your YAML:
123
+
124
+ | v1 Field | v2 Field | Notes |
125
+ |----------|----------|-------|
126
+ | `instances` | `agents` | Renamed for clarity |
127
+ | `connections` | `delegates_to` | More descriptive |
128
+ | `mcps` | `mcp_servers` | Consistent naming |
129
+ | `allowed_tools` | `tools` | Simplified |
130
+ | `prompt` | `system_prompt` | Explicit purpose |
131
+
132
+ ### Step 4: Update Tool Names
133
+
134
+ No changes needed! All tools use the same names.
135
+
136
+ ### Step 5: Test Your Swarm
137
+
138
+ ```bash
139
+ # Interactive mode - test behavior
140
+ swarm run your_swarm.yml
141
+
142
+ # One-shot mode - automation
143
+ swarm run your_swarm.yml -p "Your test prompt"
144
+ ```
145
+
146
+ ### Step 6: Optional Enhancements
147
+
148
+ Consider adding v2-specific features:
149
+
150
+ **Hooks:**
151
+ ```yaml
152
+ agents:
153
+ backend:
154
+ hooks:
155
+ pre_tool_use:
156
+ - matcher: "Write|Edit"
157
+ type: command
158
+ command: "rubocop --auto-correct"
159
+ ```
160
+
161
+ **Permissions:**
162
+ ```yaml
163
+ agents:
164
+ backend:
165
+ permissions:
166
+ Bash:
167
+ allowed_commands: ["^bundle", "^rake"]
168
+ Write:
169
+ allowed_paths: ["app/**/*", "lib/**/*"]
170
+ ```
171
+
172
+ **Memory:**
173
+ ```yaml
174
+ agents:
175
+ backend:
176
+ memory:
177
+ enabled: true
178
+ directory: ".swarm/memory"
179
+ ```
180
+
181
+ ---
182
+
183
+ ## Configuration Changes Reference
184
+
185
+ ### Complete Side-by-Side Comparison
186
+
187
+ #### v1 Configuration (Claude Swarm)
188
+
189
+ ```yaml
190
+ version: 1
191
+ swarm:
192
+ name: "Development Team"
193
+ main: lead
194
+ instances:
195
+ lead:
196
+ description: "Lead developer"
197
+ directory: .
198
+ model: opus
199
+ connections: [frontend, backend]
200
+ prompt: "You are the lead developer"
201
+ allowed_tools: [Read, Edit, Bash]
202
+ mcps:
203
+ - name: "headless_browser"
204
+ type: "stdio"
205
+ command: "bundle"
206
+ args: ["exec", "hbt", "stdio"]
207
+ hooks:
208
+ PreToolUse:
209
+ - matcher: "Write|Edit"
210
+ hooks:
211
+ - type: "command"
212
+ command: "rubocop --auto-correct"
213
+
214
+ frontend:
215
+ description: "Frontend developer"
216
+ directory: .
217
+ model: sonnet
218
+ connections: []
219
+ prompt: "You specialize in frontend"
220
+ allowed_tools: [Read, Write, Edit]
221
+ ```
222
+
223
+ #### v2 Configuration (SwarmSDK)
224
+
225
+ ```yaml
226
+ version: 2
227
+ swarm:
228
+ name: "Development Team"
229
+ lead: lead
230
+ agents:
231
+ lead:
232
+ description: "Lead developer"
233
+ directory: .
234
+ model: claude-opus-4-1
235
+ provider: anthropic
236
+ delegates_to: [frontend, backend]
237
+ system_prompt: "You are the lead developer"
238
+ tools: [Read, Edit, Bash]
239
+ mcp_servers:
240
+ - name: "headless_browser"
241
+ type: "stdio"
242
+ command: "bundle"
243
+ args: ["exec", "hbt", "stdio"]
244
+ hooks:
245
+ pre_tool_use:
246
+ - matcher: "Write|Edit"
247
+ type: command
248
+ command: "rubocop --auto-correct"
249
+
250
+ frontend:
251
+ description: "Frontend developer"
252
+ directory: .
253
+ model: sonnet
254
+ delegates_to: []
255
+ system_prompt: "You specialize in frontend"
256
+ tools: [Read, Write, Edit]
257
+ ```
258
+
259
+ ### Key Differences
260
+
261
+ 1. **Top-level structure unchanged** - Still uses `swarm:` key
262
+ 2. **`main` → `lead`** - More intuitive naming
263
+ 3. **`instances` → `agents`** - Clearer terminology
264
+ 4. **`connections` → `delegates_to`** - More descriptive
265
+ 5. **`prompt` → `system_prompt`** - Explicit purpose
266
+ 6. **`allowed_tools` → `tools`** - Simplified
267
+ 7. **`mcps` → `mcp_servers`** - Consistent naming
268
+ 8. **Hook event names** - lowercase with underscores:
269
+ - `PreToolUse` → `pre_tool_use`
270
+ - `PostToolUse` → `post_tool_use`
271
+ - `UserPromptSubmit` → `user_prompt_submit`
272
+
273
+ ---
274
+
275
+ ## Migration Examples
276
+
277
+ ### Example 1: Simple Two-Agent Swarm
278
+
279
+ **Before (v1):**
280
+ ```yaml
281
+ version: 1
282
+ swarm:
283
+ name: "Code Review"
284
+ main: reviewer
285
+ instances:
286
+ reviewer:
287
+ description: "Code reviewer"
288
+ model: opus
289
+ connections: [implementer]
290
+ prompt: "Review code and provide feedback"
291
+ allowed_tools: [Read, Bash]
292
+
293
+ implementer:
294
+ description: "Code implementer"
295
+ model: sonnet
296
+ connections: []
297
+ prompt: "Implement requested changes"
298
+ allowed_tools: [Read, Write, Edit]
299
+ ```
300
+
301
+ **After (v2):**
302
+ ```yaml
303
+ version: 2
304
+ swarm:
305
+ name: "Code Review"
306
+ lead: reviewer
307
+ agents:
308
+ reviewer:
309
+ description: "Code reviewer"
310
+ model: claude-opus-4-1
311
+ provider: anthropic
312
+ delegates_to: [implementer]
313
+ system_prompt: "Review code and provide feedback"
314
+ tools: [Read, Bash]
315
+
316
+ implementer:
317
+ description: "Code implementer"
318
+ model: sonnet
319
+ system_prompt: "Implement requested changes"
320
+ tools: [Read, Write, Edit]
321
+ ```
322
+
323
+ **Changes Made:**
324
+ - `version: 1` → `version: 2`
325
+ - `main` → `lead`
326
+ - `instances` → `agents`
327
+ - `connections` → `delegates_to`
328
+ - `prompt` → `system_prompt`
329
+ - `allowed_tools` → `tools`
330
+ - Removed `connections: []` (empty arrays can be omitted)
331
+
332
+ ### Example 2: Complex Multi-Agent Swarm
333
+
334
+ **Before (v1):**
335
+ ```yaml
336
+ version: 1
337
+ swarm:
338
+ name: "Full-Stack Team"
339
+ main: architect
340
+ instances:
341
+ architect:
342
+ description: "Lead architect"
343
+ directory: .
344
+ model: opus
345
+ connections: [frontend, backend, qa]
346
+ prompt: "Coordinate the development team"
347
+ allowed_tools: [Read, Edit]
348
+
349
+ frontend:
350
+ description: "Frontend specialist"
351
+ directory: ./frontend
352
+ model: sonnet
353
+ connections: [qa]
354
+ prompt: "Build React components"
355
+ allowed_tools: [Read, Write, Edit, Bash]
356
+
357
+ backend:
358
+ description: "Backend specialist"
359
+ directory: ./backend
360
+ model: sonnet
361
+ connections: [qa]
362
+ prompt: "Build REST APIs"
363
+ allowed_tools: [Read, Write, Edit, Bash]
364
+
365
+ qa:
366
+ description: "QA engineer"
367
+ directory: .
368
+ model: sonnet
369
+ connections: []
370
+ prompt: "Test and review code"
371
+ allowed_tools: [Read, Bash]
372
+ ```
373
+
374
+ **After (v2):**
375
+ ```yaml
376
+ version: 2
377
+ swarm:
378
+ name: "Full-Stack Team"
379
+ lead: architect
380
+ agents:
381
+ architect:
382
+ description: "Lead architect"
383
+ directory: .
384
+ model: claude-opus-4-1
385
+ provider: anthropic
386
+ delegates_to: [frontend, backend, qa]
387
+ system_prompt: "Coordinate the development team"
388
+ tools: [Read, Edit]
389
+
390
+ frontend:
391
+ description: "Frontend specialist"
392
+ directory: ./frontend
393
+ model: claude-sonnet-4-5
394
+ provider: anthropic
395
+ delegates_to: [qa]
396
+ system_prompt: "Build React components"
397
+ tools: [Read, Write, Edit, Bash]
398
+
399
+ backend:
400
+ description: "Backend specialist"
401
+ directory: ./backend
402
+ model: claude-sonnet-4-5
403
+ provider: anthropic
404
+ delegates_to: [qa]
405
+ system_prompt: "Build REST APIs"
406
+ tools: [Read, Write, Edit, Bash]
407
+
408
+ qa:
409
+ description: "QA engineer"
410
+ directory: .
411
+ model: claude-sonnet-4-5
412
+ provider: anthropic
413
+ system_prompt: "Test and review code"
414
+ tools: [Read, Bash]
415
+ ```
416
+
417
+ ### Example 3: With Hooks
418
+
419
+ **Before (v1):**
420
+ ```yaml
421
+ version: 1
422
+ swarm:
423
+ name: "Rails Team"
424
+ main: lead
425
+ instances:
426
+ lead:
427
+ description: "Rails developer"
428
+ hooks:
429
+ PreToolUse:
430
+ - matcher: "Write|Edit"
431
+ hooks:
432
+ - type: "command"
433
+ command: "rubocop --auto-correct"
434
+ PostToolUse:
435
+ - matcher: "Bash"
436
+ hooks:
437
+ - type: "command"
438
+ command: "echo 'Command executed' >> /tmp/log"
439
+ ```
440
+
441
+ **After (v2):**
442
+ ```yaml
443
+ version: 2
444
+ swarm:
445
+ name: "Rails Team"
446
+ lead: lead
447
+ agents:
448
+ lead:
449
+ description: "Rails developer"
450
+ hooks:
451
+ pre_tool_use:
452
+ - matcher: "Write|Edit"
453
+ type: command
454
+ command: "rubocop --auto-correct"
455
+ post_tool_use:
456
+ - matcher: "Bash"
457
+ type: command
458
+ command: "echo 'Command executed' >> /tmp/log"
459
+ ```
460
+
461
+ **Changes:**
462
+ - Hook event names: `PreToolUse` → `pre_tool_use`
463
+ - Hook structure: Flattened (removed nested `hooks:` array)
464
+ - Hook type: Moved `type:` to top level of hook definition
465
+
466
+ ---
467
+
468
+ ## Swarm Organization Best Practices
469
+
470
+ ### Finding the Sweet Spot
471
+
472
+ The key to effective swarm organization is **clear separation of concerns** with **appropriate delegation**.
473
+
474
+ ### Organizational Patterns
475
+
476
+ #### Pattern 1: Hierarchical Leadership
477
+
478
+ **When to use:** Complex projects with multiple domains
479
+
480
+ ```yaml
481
+ version: 2
482
+ swarm:
483
+ name: "E-Commerce Platform"
484
+ lead: cto
485
+ agents:
486
+ cto:
487
+ description: "CTO coordinating all teams"
488
+ delegates_to: [frontend_lead, backend_lead, data_lead]
489
+ tools: [Read]
490
+
491
+ frontend_lead:
492
+ description: "Frontend team lead"
493
+ delegates_to: [react_dev, ui_designer]
494
+ tools: [Read, Edit]
495
+
496
+ backend_lead:
497
+ description: "Backend team lead"
498
+ delegates_to: [api_dev, db_engineer]
499
+ tools: [Read, Edit]
500
+ ```
501
+
502
+ **Pros:**
503
+ - Clear chain of command
504
+ - Scales well with team size
505
+ - Easy to understand responsibilities
506
+
507
+ **Cons:**
508
+ - More delegation overhead
509
+ - Can be slower for simple tasks
510
+
511
+ #### Pattern 2: Flat Collaboration
512
+
513
+ **When to use:** Small teams, simple projects
514
+
515
+ ```yaml
516
+ version: 2
517
+ swarm:
518
+ name: "Microservice Team"
519
+ lead: coordinator
520
+ agents:
521
+ coordinator:
522
+ description: "Coordinates peer developers"
523
+ delegates_to: [dev1, dev2, dev3]
524
+ tools: [Read]
525
+
526
+ dev1:
527
+ description: "Full-stack developer"
528
+ tools: [Read, Write, Edit, Bash]
529
+
530
+ dev2:
531
+ description: "Full-stack developer"
532
+ tools: [Read, Write, Edit, Bash]
533
+ ```
534
+
535
+ **Pros:**
536
+ - Simple structure
537
+ - Fast execution
538
+ - Low overhead
539
+
540
+ **Cons:**
541
+ - Doesn't scale well
542
+ - Can be confusing with many agents
543
+
544
+ #### Pattern 3: Specialized Roles
545
+
546
+ **When to use:** Projects requiring distinct expertise
547
+
548
+ ```yaml
549
+ version: 2
550
+ swarm:
551
+ name: "Development Lifecycle"
552
+ lead: product_manager
553
+ agents:
554
+ product_manager:
555
+ description: "Translates requirements"
556
+ delegates_to: [architect, developer, qa, devops]
557
+ tools: [Read, Write]
558
+
559
+ architect:
560
+ description: "Designs system architecture"
561
+ tools: [Read, Write]
562
+
563
+ developer:
564
+ description: "Implements features"
565
+ delegates_to: [qa]
566
+ tools: [Read, Write, Edit, Bash]
567
+
568
+ qa:
569
+ description: "Tests implementation"
570
+ tools: [Read, Bash]
571
+
572
+ devops:
573
+ description: "Handles deployment"
574
+ tools: [Read, Bash]
575
+ ```
576
+
577
+ **Pros:**
578
+ - Clear expertise boundaries
579
+ - High-quality specialized output
580
+ - Easy to add/remove roles
581
+
582
+ **Cons:**
583
+ - More complex delegation
584
+ - Requires clear handoffs
585
+
586
+ ### Responsibility Ownership Guidelines
587
+
588
+ #### 1. Lead Agent Responsibilities
589
+
590
+ The lead agent should:
591
+ - ✅ Understand the overall goal
592
+ - ✅ Break down complex tasks
593
+ - ✅ Delegate to specialists
594
+ - ✅ Synthesize results
595
+ - ❌ NOT implement everything themselves
596
+
597
+ **Example Lead System Prompt:**
598
+ ```yaml
599
+ lead:
600
+ system_prompt: |
601
+ You coordinate a development team with these specialists:
602
+ - frontend_dev: React, UI/UX, styling
603
+ - backend_dev: APIs, databases, business logic
604
+ - qa_engineer: Testing, code review
605
+
606
+ Your responsibilities:
607
+ 1. Understand the user's request
608
+ 2. Break it into frontend/backend/qa tasks
609
+ 3. Delegate to appropriate specialists
610
+ 4. Review and integrate their work
611
+ 5. Ensure requirements are met
612
+
613
+ DON'T write code yourself - delegate to specialists.
614
+ ```
615
+
616
+ #### 2. Specialist Agent Responsibilities
617
+
618
+ Specialist agents should:
619
+ - ✅ Focus on their domain
620
+ - ✅ Have necessary tools for their work
621
+ - ✅ Delegate to other specialists when needed
622
+ - ❌ NOT work outside their expertise
623
+
624
+ **Example Specialist:**
625
+ ```yaml
626
+ backend_dev:
627
+ system_prompt: |
628
+ You are a backend specialist focusing on:
629
+ - REST APIs and GraphQL
630
+ - Database design and queries
631
+ - Business logic and services
632
+ - Authentication and authorization
633
+
634
+ You can delegate to:
635
+ - qa_engineer: For testing your work
636
+
637
+ Stay in your lane - don't touch frontend code.
638
+ ```
639
+
640
+ #### 3. Delegation Patterns
641
+
642
+ **Cross-cutting delegation:**
643
+ ```yaml
644
+ # Good: Frontend and backend can both delegate to QA
645
+ frontend_dev:
646
+ delegates_to: [qa_engineer]
647
+
648
+ backend_dev:
649
+ delegates_to: [qa_engineer]
650
+ ```
651
+
652
+ **Sequential delegation:**
653
+ ```yaml
654
+ # Good: Clear pipeline
655
+ developer:
656
+ delegates_to: [code_reviewer]
657
+
658
+ code_reviewer:
659
+ delegates_to: [qa_engineer]
660
+ ```
661
+
662
+ **Avoid circular delegation:**
663
+ ```yaml
664
+ # ❌ BAD: Circular dependency
665
+ agent_a:
666
+ delegates_to: [agent_b]
667
+
668
+ agent_b:
669
+ delegates_to: [agent_a] # Error!
670
+ ```
671
+
672
+ ### Tool Distribution Strategy
673
+
674
+ #### Strategy 1: Least Privilege
675
+
676
+ Give agents only the tools they need:
677
+
678
+ ```yaml
679
+ architect:
680
+ tools: [Read] # Only reads code
681
+
682
+ developer:
683
+ tools: [Read, Write, Edit, Bash] # Full development tools
684
+
685
+ qa:
686
+ tools: [Read, Bash] # Read and test
687
+ ```
688
+
689
+ #### Strategy 2: Shared Core + Specialized
690
+
691
+ ```yaml
692
+ all_agents:
693
+ tools: [Read, Think] # Everyone gets these
694
+
695
+ agents:
696
+ developer:
697
+ tools: [Write, Edit, Bash] # Additional tools
698
+
699
+ qa:
700
+ tools: [Bash] # Additional tools
701
+ ```
702
+
703
+ #### Strategy 3: Progressive Access
704
+
705
+ ```yaml
706
+ junior_dev:
707
+ tools: [Read, Write]
708
+ permissions:
709
+ Write:
710
+ allowed_paths: ["src/components/**/*"]
711
+
712
+ senior_dev:
713
+ tools: [Read, Write, Edit, Bash]
714
+ # Full access
715
+ ```
716
+
717
+ ### Real-World Examples
718
+
719
+ #### Example 1: Rails Development Team
720
+
721
+ ```yaml
722
+ version: 2
723
+ swarm:
724
+ name: "Rails Expert Team"
725
+ lead: senior_rails_dev
726
+ agents:
727
+ senior_rails_dev:
728
+ description: "Senior Rails developer coordinating team"
729
+ system_prompt: |
730
+ You coordinate a Rails team with:
731
+ - backend_dev: Models, controllers, services, jobs, APIs
732
+ - frontend_dev: Views, Stimulus/Turbo, assets, CSS/JS
733
+ - test_engineer: Minitest, fixtures, system tests
734
+
735
+ Delegate Rails work appropriately and ensure quality.
736
+ tools: [Read, Edit, Bash]
737
+ delegates_to: [backend_dev, frontend_dev, test_engineer]
738
+
739
+ backend_dev:
740
+ description: "Backend Rails specialist"
741
+ system_prompt: |
742
+ You focus on Rails backend:
743
+ - ActiveRecord models and migrations
744
+ - Controllers and services
745
+ - ActiveJob background jobs
746
+ - REST APIs and JSON responses
747
+
748
+ Always delegate to test_engineer for test coverage.
749
+ tools: [Read, Write, Edit, Bash]
750
+ delegates_to: [test_engineer]
751
+
752
+ frontend_dev:
753
+ description: "Frontend Rails specialist"
754
+ system_prompt: |
755
+ You focus on Rails frontend:
756
+ - ERB views and partials
757
+ - Stimulus controllers
758
+ - Turbo Frames/Streams
759
+ - Asset pipeline and JavaScript
760
+
761
+ Always delegate to test_engineer for system tests.
762
+ tools: [Read, Write, Edit]
763
+ delegates_to: [test_engineer]
764
+
765
+ test_engineer:
766
+ description: "Rails testing specialist"
767
+ system_prompt: |
768
+ You write comprehensive Rails tests:
769
+ - Unit tests for models
770
+ - Controller tests
771
+ - System tests with Capybara
772
+ - Fixtures and factories
773
+
774
+ Ensure high test coverage and quality.
775
+ tools: [Read, Write, Edit, Bash]
776
+ ```
777
+
778
+ **Why this works:**
779
+ - Clear role separation
780
+ - Backend/frontend don't overlap
781
+ - Both delegate to testing
782
+ - Senior dev coordinates but doesn't implement
783
+
784
+ #### Example 2: Microservices Platform
785
+
786
+ ```yaml
787
+ version: 2
788
+ swarm:
789
+ name: "Microservices Platform"
790
+ lead: platform_architect
791
+ agents:
792
+ platform_architect:
793
+ description: "Platform architect"
794
+ system_prompt: |
795
+ You design microservices architecture and coordinate:
796
+ - auth_service_dev: Authentication microservice
797
+ - api_gateway_dev: API gateway
798
+ - core_service_dev: Core business logic service
799
+ - shared_lib_dev: Shared libraries
800
+
801
+ Focus on system design, not implementation.
802
+ tools: [Read, Write]
803
+ delegates_to: [auth_service_dev, api_gateway_dev, core_service_dev]
804
+
805
+ auth_service_dev:
806
+ description: "Auth service developer"
807
+ system_prompt: |
808
+ You develop the authentication microservice:
809
+ - OAuth2 and JWT
810
+ - User management
811
+ - Session handling
812
+
813
+ Directory: backend/auth-service/
814
+ directory: backend/auth-service
815
+ tools: [Read, Write, Edit, Bash]
816
+ delegates_to: [shared_lib_dev]
817
+
818
+ api_gateway_dev:
819
+ description: "API gateway developer"
820
+ system_prompt: |
821
+ You develop the API gateway:
822
+ - Request routing
823
+ - Rate limiting
824
+ - Request transformation
825
+
826
+ Directory: backend/api-gateway/
827
+ directory: backend/api-gateway
828
+ tools: [Read, Write, Edit, Bash]
829
+ delegates_to: [shared_lib_dev]
830
+
831
+ core_service_dev:
832
+ description: "Core service developer"
833
+ system_prompt: |
834
+ You develop the core business logic service:
835
+ - Main application features
836
+ - Business rules
837
+ - Data processing
838
+
839
+ Directory: backend/core-service/
840
+ directory: backend/core-service
841
+ tools: [Read, Write, Edit, Bash]
842
+ delegates_to: [shared_lib_dev]
843
+
844
+ shared_lib_dev:
845
+ description: "Shared libraries developer"
846
+ system_prompt: |
847
+ You maintain shared code used across services:
848
+ - Common utilities
849
+ - Shared types/interfaces
850
+ - Reusable components
851
+
852
+ Directory: shared-libs/
853
+ directory: shared-libs
854
+ tools: [Read, Write, Edit, Bash]
855
+ ```
856
+
857
+ **Why this works:**
858
+ - Each service has dedicated developer
859
+ - Directory isolation prevents conflicts
860
+ - Shared lib developer prevents duplication
861
+ - Architect designs without implementing
862
+
863
+ #### Example 3: Data Platform Team
864
+
865
+ ```yaml
866
+ version: 2
867
+ swarm:
868
+ name: "Data Platform"
869
+ lead: data_lead
870
+ agents:
871
+ data_lead:
872
+ description: "Data team lead"
873
+ system_prompt: |
874
+ You lead the data team:
875
+ - data_engineer: ETL pipelines, data warehouse
876
+ - ml_engineer: ML models, training, deployment
877
+ - analytics_dev: Dashboards, reports, BI
878
+
879
+ Coordinate data initiatives and architecture.
880
+ tools: [Read, Edit]
881
+ delegates_to: [data_engineer, ml_engineer, analytics_dev]
882
+
883
+ data_engineer:
884
+ description: "Data engineer"
885
+ system_prompt: |
886
+ You build data infrastructure:
887
+ - ETL/ELT pipelines
888
+ - Data warehouse design
889
+ - Streaming data (Kafka, etc.)
890
+ - Data quality checks
891
+
892
+ Directory: data-platform/pipelines/
893
+ directory: data-platform/pipelines
894
+ tools: [Read, Write, Edit, Bash]
895
+
896
+ ml_engineer:
897
+ description: "ML engineer"
898
+ system_prompt: |
899
+ You develop ML models:
900
+ - Model training and tuning
901
+ - Feature engineering
902
+ - Model deployment
903
+ - A/B testing
904
+
905
+ Directory: data-platform/ml-models/
906
+ directory: data-platform/ml-models
907
+ tools: [Read, Write, Edit, Bash]
908
+
909
+ analytics_dev:
910
+ description: "Analytics developer"
911
+ system_prompt: |
912
+ You create analytics and BI:
913
+ - SQL queries and views
914
+ - Dashboards and visualizations
915
+ - Business intelligence reports
916
+ - Data storytelling
917
+
918
+ Directory: data-platform/analytics/
919
+ directory: data-platform/analytics
920
+ tools: [Read, Write, Edit, Bash]
921
+ ```
922
+
923
+ **Why this works:**
924
+ - Distinct data disciplines
925
+ - Clear data flow: engineer → ML/analytics
926
+ - No overlap in responsibilities
927
+ - Lead focuses on coordination
928
+
929
+ ---
930
+
931
+ ## Common Migration Scenarios
932
+
933
+ ### Scenario 1: Basic Configuration Only
934
+
935
+ **If you only have:**
936
+ - Agent definitions
937
+ - Basic tool assignments
938
+ - Simple connections
939
+
940
+ **Migration time: 5-10 minutes**
941
+
942
+ Just update field names and test.
943
+
944
+ ### Scenario 2: With MCP Servers
945
+
946
+ **If you have:**
947
+ - External MCP server integrations
948
+
949
+ **Changes needed:**
950
+ - `mcps` → `mcp_servers`
951
+ - Structure remains the same
952
+
953
+ **Migration time: 10-15 minutes**
954
+
955
+ ### Scenario 3: With Hooks
956
+
957
+ **If you have:**
958
+ - Shell hooks for validation
959
+ - Pre/post tool use hooks
960
+
961
+ **Changes needed:**
962
+ - Event names: `PreToolUse` → `pre_tool_use`
963
+ - Flatten hook structure
964
+ - Move `type` to top level
965
+
966
+ **Migration time: 15-20 minutes**
967
+
968
+ ### Scenario 4: Complex Multi-Directory Setup
969
+
970
+ **If you have:**
971
+ - Multiple agents in different directories
972
+ - Worktree configurations
973
+
974
+ **Good news:**
975
+ - Directory configurations work the same
976
+ - Worktrees not needed in v2 (single process)
977
+
978
+ **Migration time: 10-15 minutes**
979
+
980
+ ### Scenario 5: Custom Provider (OpenAI)
981
+
982
+ **If you have:**
983
+ - OpenAI provider configurations
984
+ - Custom API parameters
985
+
986
+ **Changes needed:**
987
+ - None! Provider configs transfer directly
988
+
989
+ **Migration time: 5 minutes**
990
+
991
+ ---
992
+
993
+ ## Troubleshooting
994
+
995
+ ### Error: "SwarmSDK requires version: 2"
996
+
997
+ **Problem:** You forgot to update the version field.
998
+
999
+ **Solution:**
1000
+ ```yaml
1001
+ # Change this
1002
+ version: 1
1003
+
1004
+ # To this
1005
+ version: 2
1006
+ ```
1007
+
1008
+ ### Error: "Missing 'agents' field in swarm configuration"
1009
+
1010
+ **Problem:** You didn't rename `instances` to `agents`.
1011
+
1012
+ **Solution:**
1013
+ ```yaml
1014
+ # Change this
1015
+ swarm:
1016
+ instances:
1017
+ ...
1018
+
1019
+ # To this
1020
+ swarm:
1021
+ agents:
1022
+ ...
1023
+ ```
1024
+
1025
+ ### Error: "Agent 'X' missing required 'description' field"
1026
+
1027
+ **Problem:** Description is now required in v2.
1028
+
1029
+ **Solution:**
1030
+ Add a description to every agent:
1031
+ ```yaml
1032
+ agents:
1033
+ backend:
1034
+ description: "Backend developer specializing in APIs"
1035
+ ...
1036
+ ```
1037
+
1038
+ ### Error: Unknown field 'connections'
1039
+
1040
+ **Problem:** Field renamed to `delegates_to`.
1041
+
1042
+ **Solution:**
1043
+ ```yaml
1044
+ # Change this
1045
+ agents:
1046
+ lead:
1047
+ connections: [backend, frontend]
1048
+
1049
+ # To this
1050
+ agents:
1051
+ lead:
1052
+ delegates_to: [backend, frontend]
1053
+ ```
1054
+
1055
+ ### Error: Unknown field 'allowed_tools'
1056
+
1057
+ **Problem:** Field renamed to `tools`.
1058
+
1059
+ **Solution:**
1060
+ ```yaml
1061
+ # Change this
1062
+ agents:
1063
+ dev:
1064
+ allowed_tools: [Read, Write]
1065
+
1066
+ # To this
1067
+ agents:
1068
+ dev:
1069
+ tools: [Read, Write]
1070
+ ```
1071
+
1072
+ ### Migration Checklist
1073
+
1074
+ Use this checklist to ensure complete migration:
1075
+
1076
+ - [ ] Updated `version: 1` to `version: 2`
1077
+ - [ ] Renamed `main` to `lead`
1078
+ - [ ] Renamed `instances` to `agents`
1079
+ - [ ] Renamed `connections` to `delegates_to`
1080
+ - [ ] Renamed `allowed_tools` to `tools`
1081
+ - [ ] Renamed `prompt` to `system_prompt`
1082
+ - [ ] Renamed `mcps` to `mcp_servers` (if used)
1083
+ - [ ] Updated hook event names to lowercase (if used)
1084
+ - [ ] Added `description` to all agents
1085
+ - [ ] Added the `provider` key to all agents
1086
+ - [ ] Tested configuration with `swarm run`
1087
+ - [ ] Verified agent delegation works
1088
+ - [ ] Confirmed tools execute correctly
1089
+
1090
+ ---
1091
+
1092
+ ## Need Help?
1093
+
1094
+ ### Resources
1095
+
1096
+ - **[SwarmSDK Documentation](docs/v2/README.md)** - Complete v2 documentation
1097
+ - **[Complete Tutorial](docs/v2/guides/complete-tutorial.md)** - In-depth feature guide
1098
+ - **[YAML Reference](docs/v2/reference/yaml.md)** - Full configuration reference
1099
+ - **[CLI Reference](docs/v2/reference/cli.md)** - Command-line usage
1100
+
1101
+ ### Support
1102
+
1103
+ - **GitHub Issues**: [Report issues](https://github.com/parruda/claude-swarm/issues)
1104
+ - **Examples**: Check `examples/v2/` directory for working configurations
1105
+
1106
+ ---
1107
+
1108
+ ## Next Steps
1109
+
1110
+ After migration, explore v2 features:
1111
+
1112
+ 1. **[Node Workflows](docs/v2/guides/complete-tutorial.md#part-5-node-workflows)** - Multi-stage pipelines
1113
+ 2. **[Hooks System](docs/v2/guides/complete-tutorial.md#part-4-hooks-system)** - Custom lifecycle logic
1114
+ 3. **[SwarmMemory](docs/v2/guides/swarm-memory.md)** - Persistent agent knowledge
1115
+ 4. **[Composable Swarms](docs/v2/guides/composable-swarms.md)** - Reusable team components
1116
+ 5. **[Permissions](docs/v2/guides/complete-tutorial.md#permissions-system)** - Fine-grained control
1117
+
1118
+ ---
1119
+
1120
+ **Happy Migrating! 🚀**