claude_swarm 1.0.9 → 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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/CLAUDE.md +347 -191
- data/docs/v2/CHANGELOG.swarm_cli.md +8 -0
- data/docs/v2/CHANGELOG.swarm_memory.md +7 -1
- data/docs/v2/CHANGELOG.swarm_sdk.md +184 -9
- data/docs/v2/README.md +6 -1
- data/docs/v2/guides/complete-tutorial.md +2 -2
- data/docs/v2/guides/getting-started.md +7 -7
- data/docs/v2/guides/migrating-to-2.3.md +541 -0
- data/docs/v2/guides/snapshots.md +14 -14
- data/docs/v2/reference/architecture-flow.md +3 -3
- data/docs/v2/reference/event_payload_structures.md +1 -1
- data/docs/v2/reference/ruby-dsl.md +157 -14
- data/docs/v2/reference/yaml.md +170 -52
- data/examples/snapshot_demo.rb +2 -2
- data/lib/claude_swarm/mcp_generator.rb +7 -20
- data/lib/claude_swarm/version.rb +1 -1
- data/lib/swarm_cli/commands/run.rb +2 -2
- data/lib/swarm_cli/config_loader.rb +11 -11
- data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
- data/lib/swarm_cli/interactive_repl.rb +2 -2
- data/lib/swarm_cli/ui/icons.rb +0 -23
- data/lib/swarm_cli/version.rb +1 -1
- data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
- data/lib/swarm_memory/integration/sdk_plugin.rb +87 -7
- data/lib/swarm_memory/version.rb +1 -1
- data/lib/swarm_memory.rb +1 -1
- data/lib/swarm_sdk/agent/builder.rb +58 -0
- data/lib/swarm_sdk/agent/chat.rb +527 -1061
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +9 -88
- data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
- data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
- data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +233 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +1 -1
- data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
- data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +12 -12
- data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
- data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +98 -0
- data/lib/swarm_sdk/agent/context.rb +2 -2
- data/lib/swarm_sdk/agent/definition.rb +66 -154
- data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
- data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
- data/lib/swarm_sdk/builders/base_builder.rb +409 -0
- data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
- data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
- data/lib/swarm_sdk/concerns/validatable.rb +55 -0
- data/lib/swarm_sdk/configuration/parser.rb +353 -0
- data/lib/swarm_sdk/configuration/translator.rb +255 -0
- data/lib/swarm_sdk/configuration.rb +65 -543
- data/lib/swarm_sdk/context_compactor/token_counter.rb +3 -3
- data/lib/swarm_sdk/context_compactor.rb +6 -11
- data/lib/swarm_sdk/context_management/builder.rb +128 -0
- data/lib/swarm_sdk/context_management/context.rb +328 -0
- data/lib/swarm_sdk/defaults.rb +196 -0
- data/lib/swarm_sdk/events_to_messages.rb +18 -0
- data/lib/swarm_sdk/hooks/shell_executor.rb +2 -1
- data/lib/swarm_sdk/log_collector.rb +179 -29
- data/lib/swarm_sdk/log_stream.rb +29 -0
- data/lib/swarm_sdk/node_context.rb +1 -1
- data/lib/swarm_sdk/observer/builder.rb +81 -0
- data/lib/swarm_sdk/observer/config.rb +45 -0
- data/lib/swarm_sdk/observer/manager.rb +236 -0
- data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
- data/lib/swarm_sdk/plugin.rb +93 -3
- data/lib/swarm_sdk/snapshot.rb +6 -6
- data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
- data/lib/swarm_sdk/state_restorer.rb +136 -151
- data/lib/swarm_sdk/state_snapshot.rb +65 -100
- data/lib/swarm_sdk/swarm/agent_initializer.rb +180 -136
- data/lib/swarm_sdk/swarm/builder.rb +44 -578
- data/lib/swarm_sdk/swarm/executor.rb +213 -0
- data/lib/swarm_sdk/swarm/hook_triggers.rb +150 -0
- data/lib/swarm_sdk/swarm/logging_callbacks.rb +340 -0
- data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
- data/lib/swarm_sdk/swarm/tool_configurator.rb +42 -138
- data/lib/swarm_sdk/swarm.rb +137 -680
- data/lib/swarm_sdk/tools/bash.rb +11 -3
- data/lib/swarm_sdk/tools/delegate.rb +61 -43
- data/lib/swarm_sdk/tools/edit.rb +8 -13
- data/lib/swarm_sdk/tools/glob.rb +9 -1
- data/lib/swarm_sdk/tools/grep.rb +7 -0
- data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
- data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
- data/lib/swarm_sdk/tools/read.rb +11 -13
- data/lib/swarm_sdk/tools/registry.rb +122 -10
- data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +8 -5
- data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
- data/lib/swarm_sdk/tools/todo_write.rb +7 -0
- data/lib/swarm_sdk/tools/web_fetch.rb +3 -2
- data/lib/swarm_sdk/tools/write.rb +8 -13
- data/lib/swarm_sdk/version.rb +1 -1
- data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
- data/lib/swarm_sdk/workflow/builder.rb +143 -0
- data/lib/swarm_sdk/workflow/executor.rb +497 -0
- data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +3 -3
- data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +3 -2
- data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
- data/lib/swarm_sdk.rb +33 -3
- data/rubocop/cop/security/no_reflection_methods.rb +1 -1
- data/swarm_memory.gemspec +1 -1
- data/swarm_sdk.gemspec +4 -2
- data/team_full.yml +24 -24
- metadata +35 -11
- data/lib/swarm_memory/chat_extension.rb +0 -34
- 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 |
|
|
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
|
-
- `
|
|
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
|
|
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
|
-
-
|
|
413
|
-
- **`:per_node`**: (
|
|
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
|
-
#
|
|
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
|
-
#
|
|
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 `
|
|
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:**
|
|
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
|
|
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
|
|
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
|
|
2629
|
+
**Returns:** Control hash (processed by Workflow)
|
|
2487
2630
|
|
|
2488
2631
|
**Valid in:** Input transformers only
|
|
2489
2632
|
|
data/docs/v2/reference/yaml.md
CHANGED
|
@@ -6,25 +6,55 @@ Complete YAML configuration reference for SwarmSDK v2.
|
|
|
6
6
|
|
|
7
7
|
## Document Structure
|
|
8
8
|
|
|
9
|
-
SwarmSDK v2 configurations
|
|
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: "
|
|
15
|
-
lead:
|
|
15
|
+
swarm: # Use 'swarm:' key for swarms
|
|
16
|
+
name: "Development Team"
|
|
17
|
+
lead: backend # Required for swarms
|
|
16
18
|
agents:
|
|
17
|
-
|
|
19
|
+
backend:
|
|
18
20
|
# Agent configuration
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
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
|
|
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
|
-
#
|
|
228
|
-
|
|
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
|
-
|
|
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 (
|
|
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
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
373
|
+
workflow:
|
|
374
|
+
name: "Build Pipeline"
|
|
375
|
+
start_node: planning
|
|
376
|
+
agents:
|
|
377
|
+
architect: { ... }
|
|
378
|
+
backend: { ... }
|
|
379
|
+
tester: { ... }
|
|
380
|
+
reviewer: { ... }
|
|
329
381
|
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
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
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
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
|
|
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
|
-
|
|
444
|
+
workflow:
|
|
385
445
|
name: "Dev Workflow"
|
|
386
|
-
|
|
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 `
|
|
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
|
|
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
|
-
|
|
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
|
---
|
data/examples/snapshot_demo.rb
CHANGED
|
@@ -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://
|
|
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://
|
|
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)
|
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
module ClaudeSwarm
|
|
4
4
|
class McpGenerator
|
|
5
|
+
CLAUDE_MCP_SERVER_CONFIG = {
|
|
6
|
+
"type" => "stdio",
|
|
7
|
+
"command" => "claude",
|
|
8
|
+
"args" => ["mcp", "serve"],
|
|
9
|
+
}.freeze
|
|
10
|
+
|
|
5
11
|
def initialize(configuration, vibe: false, restore_session_path: nil)
|
|
6
12
|
@config = configuration
|
|
7
13
|
@vibe = vibe
|
|
@@ -65,7 +71,7 @@ module ClaudeSwarm
|
|
|
65
71
|
end
|
|
66
72
|
|
|
67
73
|
# Add Claude tools MCP server for OpenAI instances
|
|
68
|
-
mcp_servers["claude_tools"] =
|
|
74
|
+
mcp_servers["claude_tools"] = CLAUDE_MCP_SERVER_CONFIG.dup if instance[:provider] == "openai"
|
|
69
75
|
|
|
70
76
|
config = {
|
|
71
77
|
"instance_id" => @instance_ids[name],
|
|
@@ -96,25 +102,6 @@ module ClaudeSwarm
|
|
|
96
102
|
end
|
|
97
103
|
end
|
|
98
104
|
|
|
99
|
-
def build_claude_tools_mcp_config
|
|
100
|
-
# Build environment for claude mcp serve by excluding Ruby/Bundler-specific variables
|
|
101
|
-
# This preserves all system variables while removing Ruby contamination
|
|
102
|
-
clean_env = ENV.to_h.reject do |key, _|
|
|
103
|
-
key.start_with?("BUNDLE_") ||
|
|
104
|
-
key.start_with?("RUBY") ||
|
|
105
|
-
key.start_with?("GEM_") ||
|
|
106
|
-
key == "RUBYOPT" ||
|
|
107
|
-
key == "RUBYLIB"
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
"type" => "stdio",
|
|
112
|
-
"command" => "claude",
|
|
113
|
-
"args" => ["mcp", "serve"],
|
|
114
|
-
"env" => clean_env,
|
|
115
|
-
}
|
|
116
|
-
end
|
|
117
|
-
|
|
118
105
|
def build_instance_mcp_config(name, instance, calling_instance:, calling_instance_id:)
|
|
119
106
|
# Get the path to the claude-swarm executable
|
|
120
107
|
exe_path = "claude-swarm"
|
data/lib/claude_swarm/version.rb
CHANGED
|
@@ -134,8 +134,8 @@ module SwarmCLI
|
|
|
134
134
|
|
|
135
135
|
def emit_validation_warnings(swarm, formatter)
|
|
136
136
|
# Setup temporary logging to capture and emit warnings
|
|
137
|
-
SwarmSDK::LogCollector.
|
|
138
|
-
formatter.on_log(log_entry)
|
|
137
|
+
SwarmSDK::LogCollector.subscribe(filter: { type: "model_lookup_warning" }) do |log_entry|
|
|
138
|
+
formatter.on_log(log_entry)
|
|
139
139
|
end
|
|
140
140
|
|
|
141
141
|
SwarmSDK::LogStream.emitter = SwarmSDK::LogCollector
|