claude_swarm 1.0.6 → 1.0.8

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 (107) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +336 -1037
  5. data/docs/V1_TO_V2_MIGRATION_GUIDE.md +1120 -0
  6. data/docs/v1/README.md +1197 -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/cli.rb +0 -18
  37. data/lib/claude_swarm/configuration.rb +28 -18
  38. data/lib/claude_swarm/openai/chat_completion.rb +2 -11
  39. data/lib/claude_swarm/openai/responses.rb +2 -11
  40. data/lib/claude_swarm/version.rb +1 -1
  41. data/lib/swarm_cli/formatters/human_formatter.rb +103 -0
  42. data/lib/swarm_cli/interactive_repl.rb +9 -3
  43. data/lib/swarm_cli/version.rb +1 -1
  44. data/lib/swarm_memory/core/storage_read_tracker.rb +51 -14
  45. data/lib/swarm_memory/integration/cli_registration.rb +3 -2
  46. data/lib/swarm_memory/integration/sdk_plugin.rb +11 -5
  47. data/lib/swarm_memory/tools/memory_edit.rb +2 -2
  48. data/lib/swarm_memory/tools/memory_multi_edit.rb +2 -2
  49. data/lib/swarm_memory/tools/memory_read.rb +3 -3
  50. data/lib/swarm_memory/version.rb +1 -1
  51. data/lib/swarm_memory.rb +5 -0
  52. data/lib/swarm_sdk/agent/builder.rb +33 -0
  53. data/lib/swarm_sdk/agent/chat/context_tracker.rb +33 -0
  54. data/lib/swarm_sdk/agent/chat/hook_integration.rb +49 -3
  55. data/lib/swarm_sdk/agent/chat/system_reminder_injector.rb +11 -27
  56. data/lib/swarm_sdk/agent/chat.rb +200 -51
  57. data/lib/swarm_sdk/agent/context.rb +6 -2
  58. data/lib/swarm_sdk/agent/context_manager.rb +6 -0
  59. data/lib/swarm_sdk/agent/definition.rb +14 -2
  60. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +180 -0
  61. data/lib/swarm_sdk/configuration.rb +387 -94
  62. data/lib/swarm_sdk/events_to_messages.rb +181 -0
  63. data/lib/swarm_sdk/log_collector.rb +31 -5
  64. data/lib/swarm_sdk/log_stream.rb +37 -8
  65. data/lib/swarm_sdk/model_aliases.json +4 -1
  66. data/lib/swarm_sdk/node/agent_config.rb +33 -8
  67. data/lib/swarm_sdk/node/builder.rb +39 -18
  68. data/lib/swarm_sdk/node_orchestrator.rb +293 -26
  69. data/lib/swarm_sdk/proc_helpers.rb +53 -0
  70. data/lib/swarm_sdk/providers/openai_with_responses.rb +22 -15
  71. data/lib/swarm_sdk/restore_result.rb +65 -0
  72. data/lib/swarm_sdk/snapshot.rb +156 -0
  73. data/lib/swarm_sdk/snapshot_from_events.rb +386 -0
  74. data/lib/swarm_sdk/state_restorer.rb +491 -0
  75. data/lib/swarm_sdk/state_snapshot.rb +369 -0
  76. data/lib/swarm_sdk/swarm/agent_initializer.rb +360 -55
  77. data/lib/swarm_sdk/swarm/all_agents_builder.rb +28 -1
  78. data/lib/swarm_sdk/swarm/builder.rb +208 -12
  79. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +67 -0
  80. data/lib/swarm_sdk/swarm/tool_configurator.rb +46 -11
  81. data/lib/swarm_sdk/swarm.rb +338 -42
  82. data/lib/swarm_sdk/swarm_loader.rb +145 -0
  83. data/lib/swarm_sdk/swarm_registry.rb +136 -0
  84. data/lib/swarm_sdk/tools/delegate.rb +92 -7
  85. data/lib/swarm_sdk/tools/read.rb +17 -5
  86. data/lib/swarm_sdk/tools/stores/read_tracker.rb +47 -12
  87. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +45 -0
  88. data/lib/swarm_sdk/utils.rb +18 -0
  89. data/lib/swarm_sdk/validation_result.rb +33 -0
  90. data/lib/swarm_sdk/version.rb +1 -1
  91. data/lib/swarm_sdk.rb +40 -8
  92. data/swarm_cli.gemspec +1 -1
  93. data/swarm_memory.gemspec +2 -2
  94. data/swarm_sdk.gemspec +2 -2
  95. metadata +21 -13
  96. data/examples/learning-assistant/assistant.md +0 -7
  97. data/examples/learning-assistant/example-memories/concept-example.md +0 -90
  98. data/examples/learning-assistant/example-memories/experience-example.md +0 -66
  99. data/examples/learning-assistant/example-memories/fact-example.md +0 -76
  100. data/examples/learning-assistant/example-memories/memory-index.md +0 -78
  101. data/examples/learning-assistant/example-memories/skill-example.md +0 -168
  102. data/examples/learning-assistant/learning_assistant.rb +0 -34
  103. data/examples/learning-assistant/learning_assistant.yml +0 -20
  104. data/lib/swarm_sdk/mcp.rb +0 -16
  105. data/llm.v2.txt +0 -13407
  106. /data/docs/v2/guides/{MEMORY_DEFRAG_GUIDE.md → memory-defrag-guide.md} +0 -0
  107. /data/{llms.txt → llms.claude-swarm.txt} +0 -0
@@ -60,6 +60,31 @@ swarm:
60
60
 
61
61
  Fields under the `swarm` key.
62
62
 
63
+ ### id
64
+
65
+ **Type:** String (optional)
66
+ **Description:** Unique swarm identifier.
67
+
68
+ **When required:**
69
+ - **Required** when using composable swarms (`swarms:` section)
70
+ - **Optional** otherwise (auto-generates if omitted)
71
+
72
+ **Purpose:**
73
+ - Hierarchical swarm tracking in events (`swarm_id`, `parent_swarm_id`)
74
+ - Building parent/child relationships in composable swarms
75
+ - Identifying swarms in logs and monitoring
76
+
77
+ If omitted and not using composable swarms, an ID is auto-generated from the swarm name with a random suffix.
78
+
79
+ ```yaml
80
+ swarm:
81
+ id: development_team
82
+ id: code_review_v2
83
+ id: main_app
84
+ ```
85
+
86
+ ---
87
+
63
88
  ### name
64
89
 
65
90
  **Type:** String (required)
@@ -73,6 +98,94 @@ swarm:
73
98
 
74
99
  ---
75
100
 
101
+ ### swarms
102
+
103
+ **Type:** Object (optional)
104
+ **Description:** External swarms to register for composable swarms feature.
105
+ **Format:** `{ swarm_name: swarm_config }`
106
+
107
+ **Enables delegation to other swarms as if they were agents.** A swarm IS an agent - delegating to a child swarm is identical to delegating to an agent. The child swarm's lead agent serves as its public interface.
108
+
109
+ **Configuration per swarm:**
110
+ - `file` (String): Path to swarm file (.rb or .yml)
111
+ - `yaml` (String): YAML configuration content (for dynamic loading)
112
+ - `swarm` (Object): Inline swarm definition
113
+ - `keep_context` (Boolean, optional): Preserve conversation (default: true)
114
+
115
+ **Rules:**
116
+ - Exactly ONE of `file`, `yaml`, or `swarm` must be provided
117
+ - `id` must be set on parent swarm when using `swarms:`
118
+
119
+ **Example - From Files:**
120
+ ```yaml
121
+ swarm:
122
+ id: main_app
123
+ name: "Main Application"
124
+ lead: backend
125
+
126
+ swarms:
127
+ code_review:
128
+ file: "./swarms/code_review.rb"
129
+ keep_context: true
130
+
131
+ testing:
132
+ file: "./swarms/testing.yml"
133
+ keep_context: false
134
+
135
+ agents:
136
+ backend:
137
+ delegates_to:
138
+ - code_review
139
+ - testing
140
+ ```
141
+
142
+ **Example - Inline Definition:**
143
+ ```yaml
144
+ swarm:
145
+ id: main_app
146
+ name: "Main Application"
147
+ lead: backend
148
+
149
+ swarms:
150
+ # File reference
151
+ code_review:
152
+ file: "./swarms/code_review.rb"
153
+
154
+ # Inline definition - no file needed!
155
+ testing:
156
+ keep_context: false
157
+ swarm:
158
+ id: testing_team
159
+ name: "Testing Team"
160
+ lead: tester
161
+ agents:
162
+ tester:
163
+ description: "Test specialist"
164
+ model: gpt-4o-mini
165
+ system: "You test code"
166
+ tools:
167
+ - Think
168
+ - Bash
169
+
170
+ agents:
171
+ backend:
172
+ description: "Backend developer"
173
+ delegates_to:
174
+ - code_review
175
+ - testing
176
+ ```
177
+
178
+ **Hierarchical IDs:**
179
+ Sub-swarms automatically get hierarchical IDs:
180
+ - Parent swarm: `main_app`
181
+ - Sub-swarms: `main_app/code_review`, `main_app/testing`
182
+
183
+ **Keep Context:**
184
+ - `keep_context: true` (default): Swarm maintains conversation history
185
+ - `keep_context: false`: Swarm context resets after each delegation
186
+
187
+ ---
188
+
76
189
  ### lead
77
190
 
78
191
  **Type:** String (required)
@@ -86,18 +199,50 @@ swarm:
86
199
 
87
200
  ---
88
201
 
89
- ### use_scratchpad
202
+ ### scratchpad
90
203
 
91
- **Type:** Boolean (optional)
92
- **Default:** `true`
93
- **Description:** Enable or disable shared scratchpad tools for all agents in the swarm.
204
+ **Type:** Symbol/String (optional)
205
+ **Default:** `disabled`
206
+ **Description:** Configure scratchpad mode for the swarm or workflow.
207
+
208
+ **Valid Values:**
209
+ - For regular Swarms: `enabled`, `disabled`
210
+ - For workflows with nodes: `enabled`, `per_node`, `disabled`
94
211
 
95
- When enabled, all agents get scratchpad tools (ScratchpadWrite, ScratchpadRead, ScratchpadList). Scratchpad is volatile (in-memory only) and shared across all agents.
212
+ **Modes:**
213
+ - **`enabled`**: Scratchpad tools available (ScratchpadWrite, ScratchpadRead, ScratchpadList)
214
+ - Regular Swarm: All agents share one scratchpad
215
+ - With nodes: All nodes share one scratchpad across workflow
216
+ - **`per_node`**: (Nodes only) Each node gets isolated scratchpad storage
217
+ - **`disabled`**: No scratchpad tools available
218
+
219
+ Scratchpad is volatile (in-memory only) and provides temporary storage for cross-agent or cross-node communication.
96
220
 
97
221
  ```yaml
222
+ # Regular swarm
223
+ swarm:
224
+ scratchpad: enabled # enable scratchpad
225
+ scratchpad: disabled # no scratchpad (default)
226
+
227
+ # With nodes - shared across all nodes
228
+ swarm:
229
+ scratchpad: enabled
230
+
231
+ nodes:
232
+ planning: { ... }
233
+ implementation: { ... }
234
+
235
+ start_node: planning
236
+
237
+ # With nodes - isolated per node
98
238
  swarm:
99
- use_scratchpad: true # default
100
- use_scratchpad: false # disable scratchpad
239
+ scratchpad: per_node
240
+
241
+ nodes:
242
+ planning: { ... }
243
+ implementation: { ... }
244
+
245
+ start_node: planning
101
246
  ```
102
247
 
103
248
  ---
@@ -168,53 +313,93 @@ swarm:
168
313
 
169
314
  ### nodes
170
315
 
171
- > **⚠️ IMPORTANT: Node workflows are ONLY supported in Ruby DSL, NOT in YAML configuration.**
172
- >
173
- > The documentation below describes the node structure for reference, but you cannot use nodes in YAML files.
174
- > To use node-based workflows, you must use the Ruby DSL. See [Ruby DSL Reference](./ruby-dsl.md#node-builder-dsl) for details.
175
-
176
- **Type:** Object (optional, **Ruby DSL only**)
177
- **Description:** Map of node names to node configurations. Enables multi-stage workflows.
316
+ **Type:** Object (optional)
317
+ **Description:** Map of node names to node configurations. Enables multi-stage workflows with multiple execution stages.
178
318
  **Format:** `{ node_name: node_config }`
179
319
 
180
- **Note:** This section is for reference only. YAML configuration does not support nodes.
320
+ Nodes allow you to create workflows where different agent teams collaborate in sequence. Each node is an independent swarm execution that can receive input from previous nodes and pass output to subsequent nodes.
181
321
 
182
- ```ruby
183
- # Ruby DSL only - NOT valid in YAML
184
- SwarmSDK.build do
185
- nodes:
186
- planning:
187
- agents:
188
- - agent: architect
322
+ **Example:**
323
+ ```yaml
324
+ nodes:
325
+ planning:
326
+ agents:
327
+ - agent: architect
328
+ output_command: "tee plan.txt"
189
329
 
190
- implementation:
191
- agents:
192
- - agent: backend
193
- delegates_to: [tester]
194
- - agent: tester
195
- dependencies: [planning]
196
- end
330
+ implementation:
331
+ agents:
332
+ - agent: backend
333
+ delegates_to: [tester]
334
+ tools: [Read, Edit, Write] # Override tools for this node
335
+ - agent: tester
336
+ dependencies: [planning]
337
+ input_command: "cat plan.txt"
338
+
339
+ review:
340
+ agents:
341
+ - agent: reviewer
342
+ dependencies: [implementation]
343
+ ```
344
+
345
+ **Node configuration fields:**
346
+ - `agents` - Array of agent configurations (optional for computation-only nodes)
347
+ - `dependencies` - Array of prerequisite node names
348
+ - `lead` - Override the lead agent for this node
349
+ - `input_command` - Bash command to transform input before execution
350
+ - `input_timeout` - Timeout for input_command (seconds, default: 60)
351
+ - `output_command` - Bash command to transform output after execution
352
+ - `output_timeout` - Timeout for output_command (seconds, default: 60)
353
+
354
+ **Per-node agent configuration:**
355
+ Each agent in a node's `agents` array can have:
356
+ - `agent` (required) - Agent name (must be defined in global `agents` section)
357
+ - `delegates_to` (optional) - Override delegation targets for this node
358
+ - `reset_context` (optional) - Whether to reset context (default: true)
359
+ - `tools` (optional) - Override tools for this node (replaces global agent tools)
360
+
361
+ ```yaml
362
+ nodes:
363
+ planning:
364
+ agents:
365
+ - agent: backend
366
+ tools: [Read, Think] # Restrict to read-only + reasoning in planning
367
+
368
+ implementation:
369
+ agents:
370
+ - agent: backend
371
+ delegates_to: [tester]
372
+ tools: [Read, Edit, Write, Bash] # Full tools in implementation
197
373
  ```
198
374
 
199
375
  ---
200
376
 
201
377
  ### start_node
202
378
 
203
- > **⚠️ Note: Node workflows are Ruby DSL only, not supported in YAML.**
204
-
205
- **Type:** String (required if nodes defined, **Ruby DSL only**)
379
+ **Type:** String (required if nodes defined)
206
380
  **Description:** Name of the starting node for workflow execution.
207
381
 
208
- **Note:** This field only applies to Ruby DSL. Not supported in YAML configuration.
209
-
210
- ```ruby
211
- # Ruby DSL only - NOT valid in YAML
212
- SwarmSDK.build do
213
- start_node :planning
382
+ **Example:**
383
+ ```yaml
384
+ swarm:
385
+ name: "Dev Workflow"
386
+ lead: coordinator
387
+ agents:
388
+ coordinator:
389
+ description: "Coordinator"
390
+ model: "gpt-5"
391
+ backend:
392
+ description: "Backend dev"
393
+ model: "gpt-5"
214
394
  nodes:
215
395
  planning:
216
- # ...
217
- end
396
+ agents:
397
+ - agent: coordinator
398
+ implementation:
399
+ agents:
400
+ - agent: backend
401
+ dependencies: [planning]
402
+ start_node: planning # Start with planning node
218
403
  ```
219
404
 
220
405
  ---
@@ -401,7 +586,7 @@ agents:
401
586
  **Default tools (when `default tools enabled`):**
402
587
  - `Read`, `Glob`, `Grep`, `TodoWrite`, `Think`, `WebFetch`
403
588
 
404
- **Scratchpad tools** (added if `use_scratchpad: true` at swarm level, default):
589
+ **Scratchpad tools** (opt-in via `scratchpad: enabled` at swarm level):
405
590
  - `ScratchpadWrite`, `ScratchpadRead`, `ScratchpadList`
406
591
 
407
592
  **Memory tools** (added if agent has `memory` configured):
@@ -457,6 +642,60 @@ agents:
457
642
 
458
643
  ---
459
644
 
645
+ ### shared_across_delegations
646
+
647
+ **Type:** Boolean (optional)
648
+ **Default:** `false`
649
+ **Description:** Control whether multiple agents share the same instance when delegating to this agent.
650
+
651
+ **Values:**
652
+ - `false` (default): Create isolated instances per delegator (recommended)
653
+ - `true`: Share the same instance across all delegators
654
+
655
+ **Behavior:**
656
+
657
+ By default, when multiple agents delegate to the same target, each gets its own isolated instance with separate conversation history. This prevents context mixing.
658
+
659
+ **Isolated Mode Example (default):**
660
+ ```yaml
661
+ agents:
662
+ tester:
663
+ description: "Testing agent"
664
+ # shared_across_delegations: false (default)
665
+
666
+ frontend:
667
+ delegates_to: [tester] # Gets tester@frontend
668
+
669
+ backend:
670
+ delegates_to: [tester] # Gets tester@backend (separate)
671
+ ```
672
+
673
+ **Shared Mode Example (opt-in):**
674
+ ```yaml
675
+ agents:
676
+ database:
677
+ description: "Database coordination agent"
678
+ shared_across_delegations: true # All delegators share this
679
+
680
+ frontend:
681
+ delegates_to: [database] # Gets shared database primary
682
+
683
+ backend:
684
+ delegates_to: [database] # Gets same shared database
685
+ ```
686
+
687
+ **Memory Sharing:**
688
+
689
+ Plugin storage (like SwarmMemory) is always shared by base agent name:
690
+ - `tester@frontend` and `tester@backend` share memory storage
691
+ - Only conversation history and tool state are isolated
692
+
693
+ **When to use:**
694
+ - **Shared mode**: Stateful coordination, database agents, shared context needs
695
+ - **Isolated mode (default)**: Testing different codebases, reviewing different PRs, preventing context mixing
696
+
697
+ ---
698
+
460
699
  ### memory
461
700
 
462
701
  **Type:** Object (optional)
@@ -719,7 +958,7 @@ agents:
719
958
 
720
959
  **Type:** Boolean (optional)
721
960
  **Default:** `true`
722
- **Description:** Include default tools (Read, Grep, Glob, TodoWrite, Think, and scratchpad tools).
961
+ **Description:** Include default tools (Read, Grep, Glob, and scratchpad tools).
723
962
 
724
963
  ```yaml
725
964
  agents:
@@ -1342,14 +1581,9 @@ agents:
1342
1581
 
1343
1582
  ---
1344
1583
 
1345
- ## Node Configuration (**Ruby DSL Only**)
1584
+ ## Node Configuration
1346
1585
 
1347
- > **⚠️ CRITICAL: Nodes are NOT supported in YAML configuration.**
1348
- >
1349
- > The following documentation is for reference only. To use node-based workflows, you MUST use the Ruby DSL.
1350
- > See [Ruby DSL Reference](./ruby-dsl.md#node-builder-dsl) for working examples.
1351
-
1352
- Fields under each node in `swarm.nodes` (**Ruby DSL only**).
1586
+ Fields under each node in `swarm.nodes`.
1353
1587
 
1354
1588
  ### agents
1355
1589
 
@@ -1357,7 +1591,9 @@ Fields under each node in `swarm.nodes` (**Ruby DSL only**).
1357
1591
  **Default:** `[]`
1358
1592
  **Description:** List of agents participating in this node.
1359
1593
 
1360
- **Format:** Array of objects with `agent` and optional `delegates_to`
1594
+ Nodes can have zero agents (computation-only nodes with transformers) or multiple agents working together. Each agent can have delegation configured and context preservation settings.
1595
+
1596
+ **Format:** Array of objects with `agent`, optional `delegates_to`, and optional `reset_context`
1361
1597
 
1362
1598
  ```yaml
1363
1599
  nodes:
@@ -1367,6 +1603,7 @@ nodes:
1367
1603
  delegates_to: [tester, database]
1368
1604
  - agent: tester
1369
1605
  delegates_to: [database]
1606
+ reset_context: false # Preserve context from previous nodes
1370
1607
  - agent: database
1371
1608
  ```
1372
1609
 
@@ -1376,7 +1613,9 @@ nodes:
1376
1613
 
1377
1614
  **Type:** String (optional)
1378
1615
  **Default:** First agent in `agents` list
1379
- **Description:** Lead agent for this node (overrides first agent).
1616
+ **Description:** Lead agent for this node (overrides default first agent).
1617
+
1618
+ The lead agent receives the initial prompt and coordinates the node's execution.
1380
1619
 
1381
1620
  ```yaml
1382
1621
  nodes:
@@ -1384,7 +1623,7 @@ nodes:
1384
1623
  agents:
1385
1624
  - agent: backend
1386
1625
  - agent: reviewer
1387
- lead: reviewer # Make reviewer the lead instead of backend
1626
+ lead: reviewer # reviewer leads instead of backend
1388
1627
  ```
1389
1628
 
1390
1629
  ---
@@ -1395,7 +1634,7 @@ nodes:
1395
1634
  **Default:** `[]`
1396
1635
  **Description:** List of prerequisite node names that must execute before this node.
1397
1636
 
1398
- **Note:** In Ruby DSL, use the `depends_on` method. In YAML (if nodes were supported), the field name is `dependencies`.
1637
+ Dependencies create a directed acyclic graph (DAG) of node execution. A node waits for all its dependencies to complete before starting.
1399
1638
 
1400
1639
  ```yaml
1401
1640
  nodes:
@@ -1406,20 +1645,36 @@ nodes:
1406
1645
  implementation:
1407
1646
  agents:
1408
1647
  - agent: backend
1409
- dependencies: [planning]
1648
+ dependencies: [planning] # Runs after planning
1410
1649
 
1411
1650
  testing:
1412
1651
  agents:
1413
1652
  - agent: tester
1414
- dependencies: [implementation]
1653
+ dependencies: [implementation] # Runs after implementation
1415
1654
  ```
1416
1655
 
1417
1656
  ---
1418
1657
 
1419
- ### input
1658
+ ### reset_context
1420
1659
 
1421
- **Type:** String (optional, Ruby DSL only)
1422
- **Description:** Ruby block for input transformation. Not supported in YAML - use `input_command` instead.
1660
+ **Type:** Boolean (optional, per-agent in node)
1661
+ **Default:** `true`
1662
+ **Description:** Whether to reset agent conversation context in this node.
1663
+
1664
+ Set to `false` to preserve conversation history from previous nodes, enabling stateful multi-node workflows.
1665
+
1666
+ ```yaml
1667
+ nodes:
1668
+ first:
1669
+ agents:
1670
+ - agent: architect
1671
+
1672
+ second:
1673
+ agents:
1674
+ - agent: architect
1675
+ reset_context: false # Preserve history from first node
1676
+ dependencies: [first]
1677
+ ```
1423
1678
 
1424
1679
  ---
1425
1680
 
@@ -1789,12 +2044,11 @@ swarm:
1789
2044
  parameters:
1790
2045
  temperature: 0.2
1791
2046
 
1792
- # Multi-stage workflow (optional)
2047
+ # Multi-stage workflow
1793
2048
  nodes:
1794
2049
  planning:
1795
2050
  agents:
1796
2051
  - agent: coordinator
1797
-
1798
2052
  output_command: "tee plan.txt"
1799
2053
 
1800
2054
  backend_implementation:
@@ -1803,7 +2057,6 @@ swarm:
1803
2057
  delegates_to: [database]
1804
2058
  - agent: database
1805
2059
  dependencies: [planning]
1806
-
1807
2060
  input_command: "scripts/prepare-backend-context.sh"
1808
2061
  output_command: "scripts/save-backend-results.sh"
1809
2062
 
@@ -1811,14 +2064,12 @@ swarm:
1811
2064
  agents:
1812
2065
  - agent: frontend
1813
2066
  dependencies: [planning]
1814
-
1815
2067
  input_command: "scripts/prepare-frontend-context.sh"
1816
2068
 
1817
2069
  review:
1818
2070
  agents:
1819
2071
  - agent: reviewer
1820
2072
  dependencies: [backend_implementation, frontend_implementation]
1821
-
1822
2073
  input_command: "scripts/gather-changes.sh"
1823
2074
  output_command: "scripts/format-review.sh"
1824
2075
 
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ # Demo of SwarmSDK Snapshot/Restore functionality
5
+ #
6
+ # This example demonstrates:
7
+ # 1. Creating a swarm and executing tasks
8
+ # 2. Creating a snapshot object
9
+ # 3. Saving snapshot to file
10
+ # 4. Loading snapshot from file
11
+ # 5. Restoring into a new swarm instance
12
+
13
+ require "bundler/setup"
14
+ require "swarm_sdk"
15
+
16
+ # Set dummy API key for demo (agents won't actually call LLM)
17
+ ENV["OPENAI_API_KEY"] = "test-key"
18
+
19
+ puts "=== SwarmSDK Snapshot/Restore Demo ===\n\n"
20
+
21
+ # Create a simple swarm
22
+ puts "1. Creating swarm..."
23
+ swarm = SwarmSDK.build do
24
+ name("Demo Team")
25
+ lead(:assistant)
26
+
27
+ agent(:assistant) do
28
+ provider("openai")
29
+ model("claude-haiku-4-5")
30
+ base_url("https://proxy-shopify-ai.local.shop.dev/v1")
31
+ description("Helpful assistant")
32
+ system_prompt("You are a helpful assistant")
33
+ tools(:Think)
34
+ end
35
+ end
36
+
37
+ puts " ✓ Swarm created\n\n"
38
+
39
+ # Execute a task (simulated with direct message for demo)
40
+ puts "2. Adding conversation history..."
41
+ # Simulate a conversation by accessing the agent and adding messages manually
42
+ assistant_agent = swarm.agent(:assistant)
43
+ assistant_agent.messages << RubyLLM::Message.new(
44
+ role: :user,
45
+ content: "Hello! Can you help me with Ruby development?",
46
+ )
47
+ assistant_agent.messages << RubyLLM::Message.new(
48
+ role: :assistant,
49
+ content: "Of course! I'd be happy to help with Ruby development. What do you need?",
50
+ )
51
+
52
+ puts " ✓ Conversation history added (#{assistant_agent.messages.size} messages)\n\n"
53
+
54
+ # Create snapshot
55
+ puts "3. Creating snapshot..."
56
+ snapshot = swarm.snapshot
57
+
58
+ puts " ✓ Snapshot created"
59
+ puts " - Type: #{snapshot.type}"
60
+ puts " - Version: #{snapshot.version}"
61
+ puts " - Created at: #{snapshot.snapshot_at}"
62
+ puts " - Agents: #{snapshot.agent_names.join(", ")}\n\n"
63
+
64
+ # Save to file
65
+ puts "4. Saving snapshot to file..."
66
+ snapshot_path = "/tmp/swarm_demo_snapshot.json"
67
+ snapshot.write_to_file(snapshot_path)
68
+
69
+ puts " ✓ Snapshot saved to: #{snapshot_path}\n\n"
70
+
71
+ # Create a new swarm (same config)
72
+ puts "5. Creating new swarm instance (simulating new process)..."
73
+ swarm2 = SwarmSDK.build do
74
+ name("Demo Team")
75
+ lead(:assistant)
76
+
77
+ agent(:assistant) do
78
+ provider("openai")
79
+ model("claude-haiku-4-5")
80
+ base_url("https://proxy-shopify-ai.local.shop.dev/v1")
81
+ description("Helpful assistant")
82
+ system_prompt("You are a helpful assistant")
83
+ tools(:Think)
84
+ end
85
+ end
86
+
87
+ puts " ✓ New swarm created (conversation is empty)\n\n"
88
+
89
+ # Load snapshot from file
90
+ puts "6. Loading snapshot from file..."
91
+ loaded_snapshot = SwarmSDK::Snapshot.from_file(snapshot_path)
92
+
93
+ puts " ✓ Snapshot loaded\n\n"
94
+
95
+ # Restore into new swarm
96
+ puts "7. Restoring conversation state..."
97
+ result = swarm2.restore(loaded_snapshot)
98
+
99
+ if result.success?
100
+ puts " ✓ Restore successful!"
101
+ puts " - All agents restored\n\n"
102
+ else
103
+ puts " ⚠ Partial restore"
104
+ puts " - #{result.summary}\n\n"
105
+ end
106
+
107
+ # Verify restoration
108
+ puts "8. Verifying restoration..."
109
+ assistant2 = swarm2.agent(:assistant)
110
+ puts " ✓ Agent has #{assistant2.messages.size} messages (should be 3)"
111
+ assistant2.messages.each_with_index do |msg, i|
112
+ content_preview = msg.content.to_s[0..50]
113
+ puts " - Message #{i + 1} [#{msg.role}]: #{content_preview}..."
114
+ end
115
+ puts
116
+
117
+ # Cleanup
118
+ File.delete(snapshot_path) if File.exist?(snapshot_path)
119
+ puts "=== Demo Complete ===\n"
@@ -8,8 +8,6 @@
8
8
  # Run: bundle exec ruby -Ilib lib/swarm_sdk/examples/dsl/01_basic.rb
9
9
 
10
10
  require "swarm_sdk"
11
- require_relative "../../../swarm_sdk/swarm_builder"
12
- require_relative "../../../swarm_sdk/agent_builder"
13
11
 
14
12
  ENV["OPENAI_API_KEY"] = "test-key"
15
13
 
@@ -8,8 +8,6 @@
8
8
  # Run: bundle exec ruby -Ilib lib/swarm_sdk/examples/dsl/02_core_parameters.rb
9
9
 
10
10
  require "swarm_sdk"
11
- require_relative "../../../swarm_sdk/swarm_builder"
12
- require_relative "../../../swarm_sdk/agent_builder"
13
11
 
14
12
  ENV["OPENAI_API_KEY"] = "test-key"
15
13
 
@@ -8,8 +8,6 @@
8
8
  # Run: bundle exec ruby -Ilib lib/swarm_sdk/examples/dsl/03_capabilities.rb
9
9
 
10
10
  require "swarm_sdk"
11
- require_relative "../../../swarm_sdk/swarm_builder"
12
- require_relative "../../../swarm_sdk/agent_builder"
13
11
 
14
12
  ENV["OPENAI_API_KEY"] = "test-key"
15
13
 
@@ -8,8 +8,6 @@
8
8
  # Run: bundle exec ruby -Ilib lib/swarm_sdk/examples/dsl/04_llm_parameters.rb
9
9
 
10
10
  require "swarm_sdk"
11
- require_relative "../../../swarm_sdk/swarm_builder"
12
- require_relative "../../../swarm_sdk/agent_builder"
13
11
 
14
12
  ENV["OPENAI_API_KEY"] = "test-key"
15
13
 
@@ -8,9 +8,6 @@
8
8
  # Run: bundle exec ruby -Ilib lib/swarm_sdk/examples/dsl/05_advanced_flags.rb
9
9
 
10
10
  require "swarm_sdk"
11
- require_relative "../../../swarm_sdk/swarm_builder"
12
- require_relative "../../../swarm_sdk/agent_builder"
13
- require_relative "../../../swarm_sdk/permissions_builder"
14
11
 
15
12
  ENV["OPENAI_API_KEY"] = "test-key"
16
13