claude_swarm 1.0.8 → 1.0.10

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 (114) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +15 -0
  3. data/CLAUDE.md +347 -191
  4. data/docs/v1/README.md +10 -0
  5. data/docs/v2/CHANGELOG.swarm_cli.md +8 -0
  6. data/docs/v2/CHANGELOG.swarm_memory.md +7 -1
  7. data/docs/v2/CHANGELOG.swarm_sdk.md +184 -9
  8. data/docs/v2/README.md +6 -1
  9. data/docs/v2/guides/complete-tutorial.md +2 -2
  10. data/docs/v2/guides/getting-started.md +7 -7
  11. data/docs/v2/guides/migrating-to-2.3.md +541 -0
  12. data/docs/v2/guides/snapshots.md +14 -14
  13. data/docs/v2/reference/architecture-flow.md +3 -3
  14. data/docs/v2/reference/event_payload_structures.md +1 -1
  15. data/docs/v2/reference/ruby-dsl.md +157 -14
  16. data/docs/v2/reference/yaml.md +170 -52
  17. data/examples/snapshot_demo.rb +2 -2
  18. data/lib/claude_swarm/claude_mcp_server.rb +1 -0
  19. data/lib/claude_swarm/cli.rb +5 -0
  20. data/lib/claude_swarm/configuration.rb +2 -1
  21. data/lib/claude_swarm/mcp_generator.rb +8 -20
  22. data/lib/claude_swarm/openai/chat_completion.rb +2 -1
  23. data/lib/claude_swarm/openai/executor.rb +3 -1
  24. data/lib/claude_swarm/openai/responses.rb +11 -21
  25. data/lib/claude_swarm/version.rb +1 -1
  26. data/lib/swarm_cli/commands/run.rb +2 -2
  27. data/lib/swarm_cli/config_loader.rb +11 -11
  28. data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
  29. data/lib/swarm_cli/interactive_repl.rb +2 -2
  30. data/lib/swarm_cli/ui/icons.rb +0 -23
  31. data/lib/swarm_cli/version.rb +1 -1
  32. data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
  33. data/lib/swarm_memory/integration/sdk_plugin.rb +87 -7
  34. data/lib/swarm_memory/version.rb +1 -1
  35. data/lib/swarm_memory.rb +1 -1
  36. data/lib/swarm_sdk/agent/builder.rb +58 -0
  37. data/lib/swarm_sdk/agent/chat.rb +527 -1061
  38. data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +9 -88
  39. data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
  40. data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
  41. data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
  42. data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +233 -0
  43. data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +1 -1
  44. data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
  45. data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +12 -12
  46. data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
  47. data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +98 -0
  48. data/lib/swarm_sdk/agent/context.rb +2 -2
  49. data/lib/swarm_sdk/agent/definition.rb +66 -154
  50. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
  51. data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
  52. data/lib/swarm_sdk/builders/base_builder.rb +409 -0
  53. data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
  54. data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
  55. data/lib/swarm_sdk/concerns/validatable.rb +55 -0
  56. data/lib/swarm_sdk/configuration/parser.rb +353 -0
  57. data/lib/swarm_sdk/configuration/translator.rb +255 -0
  58. data/lib/swarm_sdk/configuration.rb +65 -543
  59. data/lib/swarm_sdk/context_compactor/token_counter.rb +3 -3
  60. data/lib/swarm_sdk/context_compactor.rb +6 -11
  61. data/lib/swarm_sdk/context_management/builder.rb +128 -0
  62. data/lib/swarm_sdk/context_management/context.rb +328 -0
  63. data/lib/swarm_sdk/defaults.rb +196 -0
  64. data/lib/swarm_sdk/events_to_messages.rb +18 -0
  65. data/lib/swarm_sdk/hooks/shell_executor.rb +2 -1
  66. data/lib/swarm_sdk/log_collector.rb +179 -29
  67. data/lib/swarm_sdk/log_stream.rb +29 -0
  68. data/lib/swarm_sdk/node_context.rb +1 -1
  69. data/lib/swarm_sdk/observer/builder.rb +81 -0
  70. data/lib/swarm_sdk/observer/config.rb +45 -0
  71. data/lib/swarm_sdk/observer/manager.rb +236 -0
  72. data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
  73. data/lib/swarm_sdk/plugin.rb +93 -3
  74. data/lib/swarm_sdk/snapshot.rb +6 -6
  75. data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
  76. data/lib/swarm_sdk/state_restorer.rb +136 -151
  77. data/lib/swarm_sdk/state_snapshot.rb +65 -100
  78. data/lib/swarm_sdk/swarm/agent_initializer.rb +180 -136
  79. data/lib/swarm_sdk/swarm/builder.rb +44 -578
  80. data/lib/swarm_sdk/swarm/executor.rb +213 -0
  81. data/lib/swarm_sdk/swarm/hook_triggers.rb +150 -0
  82. data/lib/swarm_sdk/swarm/logging_callbacks.rb +340 -0
  83. data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
  84. data/lib/swarm_sdk/swarm/tool_configurator.rb +42 -138
  85. data/lib/swarm_sdk/swarm.rb +137 -680
  86. data/lib/swarm_sdk/tools/bash.rb +11 -3
  87. data/lib/swarm_sdk/tools/delegate.rb +61 -43
  88. data/lib/swarm_sdk/tools/edit.rb +8 -13
  89. data/lib/swarm_sdk/tools/glob.rb +9 -1
  90. data/lib/swarm_sdk/tools/grep.rb +7 -0
  91. data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
  92. data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
  93. data/lib/swarm_sdk/tools/read.rb +11 -13
  94. data/lib/swarm_sdk/tools/registry.rb +122 -10
  95. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +8 -5
  96. data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
  97. data/lib/swarm_sdk/tools/todo_write.rb +7 -0
  98. data/lib/swarm_sdk/tools/web_fetch.rb +3 -2
  99. data/lib/swarm_sdk/tools/write.rb +8 -13
  100. data/lib/swarm_sdk/version.rb +1 -1
  101. data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
  102. data/lib/swarm_sdk/workflow/builder.rb +143 -0
  103. data/lib/swarm_sdk/workflow/executor.rb +497 -0
  104. data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +3 -3
  105. data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +3 -2
  106. data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
  107. data/lib/swarm_sdk.rb +33 -3
  108. data/rubocop/cop/security/no_reflection_methods.rb +1 -1
  109. data/swarm_memory.gemspec +1 -1
  110. data/swarm_sdk.gemspec +4 -2
  111. data/team_full.yml +24 -24
  112. metadata +35 -11
  113. data/lib/swarm_memory/chat_extension.rb +0 -34
  114. data/lib/swarm_sdk/providers/openai_with_responses.rb +0 -589
@@ -32,6 +32,116 @@ result = swarm.execute("Task prompt")
32
32
 
33
33
  ## Top-Level Methods
34
34
 
35
+ ### SwarmSDK.build
36
+
37
+ Build a simple multi-agent swarm.
38
+
39
+ **Signature:**
40
+ ```ruby
41
+ SwarmSDK.build(allow_filesystem_tools: nil) {|builder| ... } → Swarm
42
+ ```
43
+
44
+ **Returns:**
45
+ - `Swarm` - Always returns a Swarm instance (simple multi-agent collaboration)
46
+
47
+ **Parameters:**
48
+ - `allow_filesystem_tools` (Boolean, optional): Override global filesystem tools setting for this swarm
49
+ - `block` (required): Configuration block using the DSL
50
+
51
+ **Description:**
52
+ Creates a simple multi-agent swarm where agents can collaborate through delegation. Use this for most use cases where you need multiple AI agents working together.
53
+
54
+ **Example:**
55
+ ```ruby
56
+ swarm = SwarmSDK.build do
57
+ name "Development Team"
58
+ lead :backend
59
+
60
+ agent :backend do
61
+ model "gpt-4"
62
+ description "Backend developer"
63
+ tools :Read, :Write, :Bash
64
+ delegates_to :tester
65
+ end
66
+
67
+ agent :tester do
68
+ model "gpt-4o-mini"
69
+ description "Test specialist"
70
+ tools :Read, :Bash
71
+ end
72
+ end
73
+
74
+ result = swarm.execute("Build authentication API")
75
+ ```
76
+
77
+ **Notes:**
78
+ - Cannot use `node` definitions (raises `ConfigurationError`)
79
+ - Must specify `lead` agent
80
+ - For multi-stage workflows, use `SwarmSDK.workflow` instead
81
+
82
+ ---
83
+
84
+ ### SwarmSDK.workflow
85
+
86
+ Build a multi-stage workflow with nodes.
87
+
88
+ **Signature:**
89
+ ```ruby
90
+ SwarmSDK.workflow(allow_filesystem_tools: nil) {|builder| ... } → Workflow
91
+ ```
92
+
93
+ **Returns:**
94
+ - `Workflow` - Always returns a Workflow instance (multi-stage pipeline)
95
+
96
+ **Parameters:**
97
+ - `allow_filesystem_tools` (Boolean, optional): Override global filesystem tools setting for this workflow
98
+ - `block` (required): Configuration block using the DSL
99
+
100
+ **Description:**
101
+ Creates a multi-stage workflow where different teams of agents execute in sequence. Each node is an independent swarm execution with its own agent configuration and delegation topology. Use this for complex pipelines with distinct stages (planning → implementation → testing).
102
+
103
+ **Example:**
104
+ ```ruby
105
+ workflow = SwarmSDK.workflow do
106
+ name "Build Pipeline"
107
+ start_node :planning
108
+
109
+ agent :architect do
110
+ model "gpt-4"
111
+ description "System architect"
112
+ end
113
+
114
+ agent :coder do
115
+ model "gpt-4"
116
+ description "Implementation specialist"
117
+ end
118
+
119
+ node :planning do
120
+ agent(:architect)
121
+ end
122
+
123
+ node :implementation do
124
+ agent(:coder)
125
+ depends_on :planning
126
+
127
+ # Transform input from planning node
128
+ input do |ctx|
129
+ "Implement this plan:\n#{ctx.content}"
130
+ end
131
+ end
132
+ end
133
+
134
+ result = workflow.execute("Build authentication system")
135
+ ```
136
+
137
+ **Notes:**
138
+ - Cannot use `lead` (raises `ConfigurationError`)
139
+ - Must specify `start_node`
140
+ - Nodes execute in topological order based on `depends_on`
141
+ - Each node can have different agents and delegation topology
142
+
143
+ ---
144
+
35
145
  ### SwarmSDK.configure
36
146
 
37
147
  Configure global SwarmSDK settings.
@@ -105,7 +215,7 @@ Build a swarm using the DSL.
105
215
 
106
216
  **Signature:**
107
217
  ```ruby
108
- SwarmSDK.build(allow_filesystem_tools: nil, &block) → Swarm | NodeOrchestrator
218
+ SwarmSDK.build(allow_filesystem_tools: nil, &block) → Swarm | Workflow
109
219
  ```
110
220
 
111
221
  **Parameters:**
@@ -114,7 +224,7 @@ SwarmSDK.build(allow_filesystem_tools: nil, &block) → Swarm | NodeOrchestrator
114
224
 
115
225
  **Returns:**
116
226
  - `Swarm`: For single-swarm configurations
117
- - `NodeOrchestrator`: For multi-node workflow configurations
227
+ - `Workflow`: For multi-node workflow configurations
118
228
 
119
229
  **Example:**
120
230
  ```ruby
@@ -400,7 +510,7 @@ scratchpad(mode) → void
400
510
  **Parameters:**
401
511
  - `mode` (Symbol, required): Scratchpad mode
402
512
  - For regular Swarms: `:enabled` or `:disabled`
403
- - For NodeOrchestrator (workflows with nodes): `:enabled`, `:per_node`, or `:disabled`
513
+ - For Workflow (workflows with nodes): `:enabled`, `:per_node`, or `:disabled`
404
514
 
405
515
  **Default:** `:disabled`
406
516
 
@@ -409,8 +519,8 @@ Controls scratchpad availability and sharing behavior:
409
519
 
410
520
  - **`:enabled`**: Scratchpad tools available (ScratchpadWrite, ScratchpadRead, ScratchpadList)
411
521
  - Regular Swarm: All agents share one scratchpad
412
- - NodeOrchestrator: All nodes share one scratchpad across the workflow
413
- - **`:per_node`**: (NodeOrchestrator only) Each node gets isolated scratchpad storage
522
+ - Workflow: All nodes share one scratchpad across the workflow
523
+ - **`:per_node`**: (Workflow only) Each node gets isolated scratchpad storage
414
524
  - **`:disabled`**: No scratchpad tools available
415
525
 
416
526
  Scratchpad is volatile (in-memory only) and provides temporary storage for cross-agent or cross-node communication.
@@ -423,7 +533,7 @@ SwarmSDK.build do
423
533
  scratchpad :disabled # Disable scratchpad (default)
424
534
  end
425
535
 
426
- # NodeOrchestrator - shared across nodes
536
+ # Workflow - shared across nodes
427
537
  SwarmSDK.build do
428
538
  scratchpad :enabled # All nodes share one scratchpad
429
539
 
@@ -432,7 +542,7 @@ SwarmSDK.build do
432
542
  start_node :planning
433
543
  end
434
544
 
435
- # NodeOrchestrator - isolated per node
545
+ # Workflow - isolated per node
436
546
  SwarmSDK.build do
437
547
  scratchpad :per_node # Each node gets its own scratchpad
438
548
 
@@ -910,7 +1020,7 @@ delegates_to(*agent_names) → void
910
1020
 
911
1021
  **Behavior:**
912
1022
  - Multiple calls are cumulative
913
- - Creates a `DelegateTaskTo{Agent}` tool for each target (e.g., `DelegateTaskToDatabase`)
1023
+ - Creates a `WorkWith{Agent}` tool for each target (e.g., `WorkWithDatabase`)
914
1024
 
915
1025
  **Example:**
916
1026
  ```ruby
@@ -1962,16 +2072,19 @@ Execute a task using the lead agent.
1962
2072
 
1963
2073
  **Signature:**
1964
2074
  ```ruby
1965
- swarm.execute(prompt, &block) → Result
2075
+ swarm.execute(prompt, wait: true, &block) → Result | Async::Task
1966
2076
  ```
1967
2077
 
1968
2078
  **Parameters:**
1969
2079
  - `prompt` (String, required): Task prompt
2080
+ - `wait` (Boolean, optional): If true (default), blocks until execution completes. If false, returns Async::Task immediately for non-blocking execution.
1970
2081
  - `block` (optional): Log entry handler for streaming
1971
2082
 
1972
- **Returns:** `Result` object
2083
+ **Returns:**
2084
+ - `Result` if `wait: true` (default)
2085
+ - `Async::Task` if `wait: false`
1973
2086
 
1974
- **Example:**
2087
+ **Example - Blocking execution (default):**
1975
2088
  ```ruby
1976
2089
  # Basic execution
1977
2090
  result = swarm.execute("Build a REST API")
@@ -1992,6 +2105,36 @@ else
1992
2105
  end
1993
2106
  ```
1994
2107
 
2108
+ **Example - Non-blocking execution with cancellation:**
2109
+ ```ruby
2110
+ # Start non-blocking execution
2111
+ task = swarm.execute("Build a REST API", wait: false) do |log_entry|
2112
+ puts "#{log_entry[:type]}: #{log_entry[:agent]}"
2113
+ end
2114
+
2115
+ # ... do other work ...
2116
+
2117
+ # Cancel anytime
2118
+ task.stop
2119
+
2120
+ # Wait for result (returns nil if cancelled)
2121
+ result = task.wait
2122
+ if result.nil?
2123
+ puts "Execution was cancelled"
2124
+ elsif result.success?
2125
+ puts result.content
2126
+ else
2127
+ puts "Error: #{result.error.message}"
2128
+ end
2129
+ ```
2130
+
2131
+ **Non-blocking execution details:**
2132
+ - **`wait: false`**: Returns `Async::Task` immediately, enabling cancellation via `task.stop`
2133
+ - **Cooperative cancellation**: Stops when fiber yields (HTTP I/O, tool boundaries), not immediate
2134
+ - **Proper cleanup**: MCP clients, fiber storage, and logging cleaned in task's ensure block
2135
+ - **`task.wait` returns nil**: Cancelled tasks return `nil` from `wait` method
2136
+ - **Use cases**: Long-running tasks, user-initiated cancellation, timeout handling
2137
+
1995
2138
  ---
1996
2139
 
1997
2140
  ## Result Object
@@ -2421,7 +2564,7 @@ Jump to a different node with custom content, bypassing normal dependency order.
2421
2564
  - `node_name` (Symbol, required): Target node name
2422
2565
  - `content` (String, required): Content to pass to target node (validated non-nil)
2423
2566
 
2424
- **Returns:** Control hash (processed by NodeOrchestrator)
2567
+ **Returns:** Control hash (processed by Workflow)
2425
2568
 
2426
2569
  **Valid in:** Both input and output transformers
2427
2570
 
@@ -2452,7 +2595,7 @@ Stop entire workflow execution immediately and return content as final result.
2452
2595
  **Parameters:**
2453
2596
  - `content` (String, required): Final content to return (validated non-nil)
2454
2597
 
2455
- **Returns:** Control hash (processed by NodeOrchestrator)
2598
+ **Returns:** Control hash (processed by Workflow)
2456
2599
 
2457
2600
  **Valid in:** Both input and output transformers
2458
2601
 
@@ -2483,7 +2626,7 @@ Skip LLM execution for current node and use provided content instead.
2483
2626
  **Parameters:**
2484
2627
  - `content` (String, required): Content to use instead of LLM execution (validated non-nil)
2485
2628
 
2486
- **Returns:** Control hash (processed by NodeOrchestrator)
2629
+ **Returns:** Control hash (processed by Workflow)
2487
2630
 
2488
2631
  **Valid in:** Input transformers only
2489
2632
 
@@ -6,25 +6,55 @@ Complete YAML configuration reference for SwarmSDK v2.
6
6
 
7
7
  ## Document Structure
8
8
 
9
- SwarmSDK v2 configurations follow this structure:
9
+ SwarmSDK v2 configurations support two types, distinguished by the root key:
10
+
11
+ ### Simple Swarm (Multi-Agent Collaboration)
10
12
 
11
13
  ```yaml
12
14
  version: 2
13
- swarm:
14
- name: "Swarm Name"
15
- lead: agent_name
15
+ swarm: # Use 'swarm:' key for swarms
16
+ name: "Development Team"
17
+ lead: backend # Required for swarms
16
18
  agents:
17
- agent_name:
19
+ backend:
18
20
  # Agent configuration
19
- all_agents:
20
- # Shared agent configuration
21
- hooks:
22
- # Swarm-level hooks
23
- nodes:
24
- # Node configurations (optional)
25
- start_node: node_name # Required if nodes defined
21
+ tester:
22
+ # Agent configuration
23
+ ```
24
+
25
+ **Returns:** `SwarmSDK::Swarm` when loaded with `SwarmSDK.load_file`
26
+
27
+ ### Workflow (Multi-Stage Pipeline)
28
+
29
+ ```yaml
30
+ version: 2
31
+ workflow: # Use 'workflow:' key for workflows
32
+ name: "Build Pipeline"
33
+ start_node: planning # Required for workflows
34
+ agents:
35
+ architect:
36
+ # Agent configuration
37
+ coder:
38
+ # Agent configuration
39
+ nodes: # Required for workflows
40
+ planning:
41
+ agents:
42
+ - agent: architect
43
+ implementation:
44
+ agents:
45
+ - agent: coder
46
+ dependencies:
47
+ - planning
26
48
  ```
27
49
 
50
+ **Returns:** `SwarmSDK::Workflow` when loaded with `SwarmSDK.load_file`
51
+
52
+ **Type Detection:**
53
+ - `swarm:` key → Creates `SwarmSDK::Swarm` (requires `lead:`, cannot have `nodes:`)
54
+ - `workflow:` key → Creates `SwarmSDK::Workflow` (requires `start_node:` and `nodes:`)
55
+ - Cannot have both `swarm:` and `workflow:` keys in same file
56
+ - Same `SwarmSDK.load_file` API works for both types!
57
+
28
58
  ---
29
59
 
30
60
  ## Top-Level Fields
@@ -43,8 +73,10 @@ version: 2
43
73
 
44
74
  ### swarm
45
75
 
46
- **Type:** Object (required)
47
- **Description:** Root configuration object containing all swarm settings.
76
+ **Type:** Object (required for Swarm type)
77
+ **Description:** Root configuration object for multi-agent collaboration swarms. Use this key when you want agents to collaborate through delegation.
78
+
79
+ **Mutually exclusive with:** `workflow:`
48
80
 
49
81
  ```yaml
50
82
  swarm:
@@ -56,9 +88,28 @@ swarm:
56
88
 
57
89
  ---
58
90
 
91
+ ### workflow
92
+
93
+ **Type:** Object (required for Workflow type)
94
+ **Description:** Root configuration object for multi-stage pipeline workflows. Use this key when you want to orchestrate agents through sequential or parallel nodes.
95
+
96
+ **Mutually exclusive with:** `swarm:`
97
+
98
+ ```yaml
99
+ workflow:
100
+ name: "Build Pipeline"
101
+ start_node: planning
102
+ agents:
103
+ # ...
104
+ nodes:
105
+ # ...
106
+ ```
107
+
108
+ ---
109
+
59
110
  ## Swarm Configuration
60
111
 
61
- Fields under the `swarm` key.
112
+ Fields under the `swarm` key (for Swarm type configurations).
62
113
 
63
114
  ### id
64
115
 
@@ -224,25 +275,21 @@ swarm:
224
275
  scratchpad: enabled # enable scratchpad
225
276
  scratchpad: disabled # no scratchpad (default)
226
277
 
227
- # With nodes - shared across all nodes
228
- swarm:
278
+ # Workflow - shared across all nodes
279
+ workflow:
229
280
  scratchpad: enabled
230
-
281
+ start_node: planning
231
282
  nodes:
232
283
  planning: { ... }
233
284
  implementation: { ... }
234
285
 
235
- start_node: planning
236
-
237
- # With nodes - isolated per node
238
- swarm:
286
+ # Workflow - isolated per node
287
+ workflow:
239
288
  scratchpad: per_node
240
-
289
+ start_node: planning
241
290
  nodes:
242
291
  planning: { ... }
243
292
  implementation: { ... }
244
-
245
- start_node: planning
246
293
  ```
247
294
 
248
295
  ---
@@ -313,33 +360,44 @@ swarm:
313
360
 
314
361
  ### nodes
315
362
 
316
- **Type:** Object (optional)
363
+ **Type:** Object (required for Workflow type)
317
364
  **Description:** Map of node names to node configurations. Enables multi-stage workflows with multiple execution stages.
318
365
  **Format:** `{ node_name: node_config }`
319
366
 
367
+ **Important:** This field is only valid under the `workflow:` key, not `swarm:`.
368
+
320
369
  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.
321
370
 
322
371
  **Example:**
323
372
  ```yaml
324
- nodes:
325
- planning:
326
- agents:
327
- - agent: architect
328
- output_command: "tee plan.txt"
373
+ workflow:
374
+ name: "Build Pipeline"
375
+ start_node: planning
376
+ agents:
377
+ architect: { ... }
378
+ backend: { ... }
379
+ tester: { ... }
380
+ reviewer: { ... }
329
381
 
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"
382
+ nodes:
383
+ planning:
384
+ agents:
385
+ - agent: architect
386
+ output_command: "tee plan.txt"
338
387
 
339
- review:
340
- agents:
341
- - agent: reviewer
342
- dependencies: [implementation]
388
+ implementation:
389
+ agents:
390
+ - agent: backend
391
+ delegates_to: [tester]
392
+ tools: [Read, Edit, Write] # Override tools for this node
393
+ - agent: tester
394
+ dependencies: [planning]
395
+ input_command: "cat plan.txt"
396
+
397
+ review:
398
+ agents:
399
+ - agent: reviewer
400
+ dependencies: [implementation]
343
401
  ```
344
402
 
345
403
  **Node configuration fields:**
@@ -376,14 +434,16 @@ nodes:
376
434
 
377
435
  ### start_node
378
436
 
379
- **Type:** String (required if nodes defined)
437
+ **Type:** String (required for Workflow type)
380
438
  **Description:** Name of the starting node for workflow execution.
381
439
 
440
+ **Important:** This field is only valid under the `workflow:` key, not `swarm:`.
441
+
382
442
  **Example:**
383
443
  ```yaml
384
- swarm:
444
+ workflow:
385
445
  name: "Dev Workflow"
386
- lead: coordinator
446
+ start_node: planning # Required: Start with planning node
387
447
  agents:
388
448
  coordinator:
389
449
  description: "Coordinator"
@@ -399,7 +459,6 @@ swarm:
399
459
  agents:
400
460
  - agent: backend
401
461
  dependencies: [planning]
402
- start_node: planning # Start with planning node
403
462
  ```
404
463
 
405
464
  ---
@@ -1583,7 +1642,7 @@ agents:
1583
1642
 
1584
1643
  ## Node Configuration
1585
1644
 
1586
- Fields under each node in `swarm.nodes`.
1645
+ Fields under each node in `workflow.nodes`.
1587
1646
 
1588
1647
  ### agents
1589
1648
 
@@ -1904,7 +1963,11 @@ permissions:
1904
1963
 
1905
1964
  ---
1906
1965
 
1907
- ## Complete Example
1966
+ ## Complete Examples
1967
+
1968
+ ### Complete Swarm Example
1969
+
1970
+ A multi-agent collaboration swarm where agents delegate tasks to each other:
1908
1971
 
1909
1972
  ```yaml
1910
1973
  version: 2
@@ -2043,8 +2106,65 @@ swarm:
2043
2106
 
2044
2107
  parameters:
2045
2108
  temperature: 0.2
2109
+ ```
2110
+
2111
+ ---
2112
+
2113
+ ### Complete Workflow Example
2114
+
2115
+ A multi-stage pipeline workflow with sequential and parallel node execution:
2116
+
2117
+ ```yaml
2118
+ version: 2
2119
+
2120
+ workflow:
2121
+ name: "Development Pipeline"
2122
+ start_node: planning
2123
+
2124
+ # Global configuration for all agents
2125
+ all_agents:
2126
+ provider: openai
2127
+ timeout: 180
2128
+ coding_agent: true
2129
+
2130
+ # Agent definitions (shared across nodes)
2131
+ agents:
2132
+ coordinator:
2133
+ description: "Lead coordinator for planning"
2134
+ model: gpt-5
2135
+ system_prompt: "You create detailed project plans"
2136
+ tools: [Read, TodoWrite]
2137
+
2138
+ backend:
2139
+ description: "Backend developer specializing in Ruby on Rails"
2140
+ model: claude-sonnet-4
2141
+ provider: anthropic
2142
+ directory: "backend"
2143
+ system_prompt: "You build clean, testable backend APIs"
2144
+ tools: [Read, Write, Edit, Bash]
2145
+ delegates_to: [database]
2046
2146
 
2047
- # Multi-stage workflow
2147
+ frontend:
2148
+ description: "Frontend developer specializing in React"
2149
+ model: gpt-5
2150
+ directory: "frontend"
2151
+ system_prompt: "You build modern, accessible frontends"
2152
+ tools: [Read, Write, Edit, Bash]
2153
+
2154
+ database:
2155
+ description: "Database expert for schema design"
2156
+ model: gpt-5
2157
+ directory: "backend"
2158
+ system_prompt: "You design efficient database schemas"
2159
+ tools: [Read, Write, Bash]
2160
+
2161
+ reviewer:
2162
+ description: "Code reviewer checking for bugs"
2163
+ model: o4
2164
+ system_prompt: "You review code for quality and security"
2165
+ tools: [Read, Grep, Glob]
2166
+
2167
+ # Multi-stage workflow nodes
2048
2168
  nodes:
2049
2169
  planning:
2050
2170
  agents:
@@ -2072,8 +2192,6 @@ swarm:
2072
2192
  dependencies: [backend_implementation, frontend_implementation]
2073
2193
  input_command: "scripts/gather-changes.sh"
2074
2194
  output_command: "scripts/format-review.sh"
2075
-
2076
- start_node: planning
2077
2195
  ```
2078
2196
 
2079
2197
  ---
@@ -27,7 +27,7 @@ swarm = SwarmSDK.build do
27
27
  agent(:assistant) do
28
28
  provider("openai")
29
29
  model("claude-haiku-4-5")
30
- base_url("https://proxy-shopify-ai.local.shop.dev/v1")
30
+ base_url("https://api.example.com/v1")
31
31
  description("Helpful assistant")
32
32
  system_prompt("You are a helpful assistant")
33
33
  tools(:Think)
@@ -77,7 +77,7 @@ swarm2 = SwarmSDK.build do
77
77
  agent(:assistant) do
78
78
  provider("openai")
79
79
  model("claude-haiku-4-5")
80
- base_url("https://proxy-shopify-ai.local.shop.dev/v1")
80
+ base_url("https://api.example.com/v1")
81
81
  description("Helpful assistant")
82
82
  system_prompt("You are a helpful assistant")
83
83
  tools(:Think)
@@ -36,6 +36,7 @@ module ClaudeSwarm
36
36
  openai_token_env: instance_config[:openai_token_env],
37
37
  base_url: instance_config[:base_url],
38
38
  reasoning_effort: instance_config[:reasoning_effort],
39
+ zdr: instance_config[:zdr],
39
40
  )
40
41
  else
41
42
  # Default Claude behavior - always use SDK
@@ -172,6 +172,10 @@ module ClaudeSwarm
172
172
  method_option :reasoning_effort,
173
173
  type: :string,
174
174
  desc: "Reasoning effort for OpenAI models"
175
+ method_option :zdr,
176
+ type: :boolean,
177
+ default: false,
178
+ desc: "Enable ZDR for OpenAI models"
175
179
  def mcp_serve
176
180
  # Validate reasoning_effort if provided
177
181
  if options[:reasoning_effort]
@@ -208,6 +212,7 @@ module ClaudeSwarm
208
212
  openai_token_env: options[:openai_token_env],
209
213
  base_url: options[:base_url],
210
214
  reasoning_effort: options[:reasoning_effort],
215
+ zdr: options[:zdr],
211
216
  }
212
217
 
213
218
  begin
@@ -4,7 +4,7 @@ module ClaudeSwarm
4
4
  class Configuration
5
5
  # Frozen constants for validation
6
6
  VALID_PROVIDERS = ["claude", "openai"].freeze
7
- OPENAI_SPECIFIC_FIELDS = ["temperature", "api_version", "openai_token_env", "base_url", "reasoning_effort"].freeze
7
+ OPENAI_SPECIFIC_FIELDS = ["temperature", "api_version", "openai_token_env", "base_url", "reasoning_effort", "zdr"].freeze
8
8
  VALID_API_VERSIONS = ["chat_completion", "responses"].freeze
9
9
  VALID_REASONING_EFFORTS = ["low", "medium", "high"].freeze
10
10
 
@@ -232,6 +232,7 @@ module ClaudeSwarm
232
232
  instance_config[:openai_token_env] = config["openai_token_env"] || "OPENAI_API_KEY"
233
233
  instance_config[:base_url] = config["base_url"]
234
234
  instance_config[:reasoning_effort] = config["reasoning_effort"] if config["reasoning_effort"]
235
+ instance_config[:zdr] = config["zdr"] if config.key?("zdr")
235
236
  # Default vibe to true for OpenAI instances if not specified
236
237
  instance_config[:vibe] = true if config["vibe"].nil?
237
238
  elsif config["vibe"].nil?