claude_swarm 1.0.9 → 1.0.11

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 (134) hide show
  1. checksums.yaml +4 -4
  2. data/{CHANGELOG.md → CHANGELOG.claude-swarm.md} +10 -0
  3. data/CLAUDE.md +346 -191
  4. data/decisions/2025-11-22-001-global-agent-registry.md +172 -0
  5. data/docs/v2/CHANGELOG.swarm_cli.md +20 -0
  6. data/docs/v2/CHANGELOG.swarm_memory.md +146 -1
  7. data/docs/v2/CHANGELOG.swarm_sdk.md +433 -10
  8. data/docs/v2/README.md +20 -5
  9. data/docs/v2/guides/complete-tutorial.md +95 -9
  10. data/docs/v2/guides/getting-started.md +10 -8
  11. data/docs/v2/guides/memory-adapters.md +41 -0
  12. data/docs/v2/guides/migrating-to-2.x.md +746 -0
  13. data/docs/v2/guides/plugins.md +52 -5
  14. data/docs/v2/guides/rails-integration.md +6 -0
  15. data/docs/v2/guides/snapshots.md +14 -14
  16. data/docs/v2/guides/swarm-memory.md +2 -13
  17. data/docs/v2/reference/architecture-flow.md +3 -3
  18. data/docs/v2/reference/cli.md +0 -1
  19. data/docs/v2/reference/configuration_reference.md +300 -0
  20. data/docs/v2/reference/event_payload_structures.md +27 -5
  21. data/docs/v2/reference/ruby-dsl.md +614 -18
  22. data/docs/v2/reference/swarm_memory_technical_details.md +7 -29
  23. data/docs/v2/reference/yaml.md +172 -54
  24. data/examples/snapshot_demo.rb +2 -2
  25. data/lib/claude_swarm/mcp_generator.rb +8 -21
  26. data/lib/claude_swarm/orchestrator.rb +8 -1
  27. data/lib/claude_swarm/version.rb +1 -1
  28. data/lib/swarm_cli/commands/run.rb +2 -2
  29. data/lib/swarm_cli/config_loader.rb +11 -11
  30. data/lib/swarm_cli/formatters/human_formatter.rb +0 -33
  31. data/lib/swarm_cli/interactive_repl.rb +2 -2
  32. data/lib/swarm_cli/ui/icons.rb +0 -23
  33. data/lib/swarm_cli/version.rb +1 -1
  34. data/lib/swarm_memory/adapters/filesystem_adapter.rb +11 -34
  35. data/lib/swarm_memory/core/semantic_index.rb +10 -2
  36. data/lib/swarm_memory/core/storage.rb +7 -2
  37. data/lib/swarm_memory/dsl/memory_config.rb +37 -0
  38. data/lib/swarm_memory/integration/sdk_plugin.rb +201 -28
  39. data/lib/swarm_memory/optimization/defragmenter.rb +1 -1
  40. data/lib/swarm_memory/prompts/memory_researcher.md.erb +0 -1
  41. data/lib/swarm_memory/tools/load_skill.rb +0 -1
  42. data/lib/swarm_memory/tools/memory_edit.rb +2 -1
  43. data/lib/swarm_memory/tools/memory_read.rb +1 -1
  44. data/lib/swarm_memory/version.rb +1 -1
  45. data/lib/swarm_memory.rb +8 -6
  46. data/lib/swarm_sdk/agent/builder.rb +58 -0
  47. data/lib/swarm_sdk/agent/chat.rb +527 -1061
  48. data/lib/swarm_sdk/agent/{chat → chat_helpers}/context_tracker.rb +13 -88
  49. data/lib/swarm_sdk/agent/chat_helpers/event_emitter.rb +204 -0
  50. data/lib/swarm_sdk/agent/{chat → chat_helpers}/hook_integration.rb +108 -46
  51. data/lib/swarm_sdk/agent/chat_helpers/instrumentation.rb +78 -0
  52. data/lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb +267 -0
  53. data/lib/swarm_sdk/agent/{chat → chat_helpers}/logging_helpers.rb +3 -3
  54. data/lib/swarm_sdk/agent/chat_helpers/serialization.rb +83 -0
  55. data/lib/swarm_sdk/agent/{chat → chat_helpers}/system_reminder_injector.rb +11 -13
  56. data/lib/swarm_sdk/agent/chat_helpers/system_reminders.rb +79 -0
  57. data/lib/swarm_sdk/agent/chat_helpers/token_tracking.rb +146 -0
  58. data/lib/swarm_sdk/agent/context.rb +1 -2
  59. data/lib/swarm_sdk/agent/definition.rb +66 -154
  60. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +4 -2
  61. data/lib/swarm_sdk/agent/system_prompt_builder.rb +161 -0
  62. data/lib/swarm_sdk/agent_registry.rb +146 -0
  63. data/lib/swarm_sdk/builders/base_builder.rb +488 -0
  64. data/lib/swarm_sdk/concerns/cleanupable.rb +39 -0
  65. data/lib/swarm_sdk/concerns/snapshotable.rb +67 -0
  66. data/lib/swarm_sdk/concerns/validatable.rb +55 -0
  67. data/lib/swarm_sdk/config.rb +302 -0
  68. data/lib/swarm_sdk/configuration/parser.rb +373 -0
  69. data/lib/swarm_sdk/configuration/translator.rb +255 -0
  70. data/lib/swarm_sdk/configuration.rb +77 -546
  71. data/lib/swarm_sdk/context_compactor/token_counter.rb +2 -6
  72. data/lib/swarm_sdk/context_compactor.rb +6 -11
  73. data/lib/swarm_sdk/context_management/builder.rb +128 -0
  74. data/lib/swarm_sdk/context_management/context.rb +328 -0
  75. data/lib/swarm_sdk/custom_tool_registry.rb +226 -0
  76. data/lib/swarm_sdk/defaults.rb +196 -0
  77. data/lib/swarm_sdk/events_to_messages.rb +18 -0
  78. data/lib/swarm_sdk/hooks/adapter.rb +3 -3
  79. data/lib/swarm_sdk/hooks/shell_executor.rb +4 -2
  80. data/lib/swarm_sdk/log_collector.rb +179 -29
  81. data/lib/swarm_sdk/log_stream.rb +29 -0
  82. data/lib/swarm_sdk/models.json +4333 -1
  83. data/lib/swarm_sdk/models.rb +43 -2
  84. data/lib/swarm_sdk/node_context.rb +1 -1
  85. data/lib/swarm_sdk/observer/builder.rb +81 -0
  86. data/lib/swarm_sdk/observer/config.rb +45 -0
  87. data/lib/swarm_sdk/observer/manager.rb +236 -0
  88. data/lib/swarm_sdk/patterns/agent_observer.rb +160 -0
  89. data/lib/swarm_sdk/plugin.rb +95 -5
  90. data/lib/swarm_sdk/result.rb +52 -0
  91. data/lib/swarm_sdk/snapshot.rb +6 -6
  92. data/lib/swarm_sdk/snapshot_from_events.rb +13 -2
  93. data/lib/swarm_sdk/state_restorer.rb +136 -151
  94. data/lib/swarm_sdk/state_snapshot.rb +65 -100
  95. data/lib/swarm_sdk/swarm/agent_initializer.rb +181 -137
  96. data/lib/swarm_sdk/swarm/builder.rb +44 -578
  97. data/lib/swarm_sdk/swarm/executor.rb +213 -0
  98. data/lib/swarm_sdk/swarm/hook_triggers.rb +151 -0
  99. data/lib/swarm_sdk/swarm/logging_callbacks.rb +341 -0
  100. data/lib/swarm_sdk/swarm/mcp_configurator.rb +7 -4
  101. data/lib/swarm_sdk/swarm/tool_configurator.rb +58 -140
  102. data/lib/swarm_sdk/swarm.rb +203 -683
  103. data/lib/swarm_sdk/tools/bash.rb +14 -8
  104. data/lib/swarm_sdk/tools/delegate.rb +61 -43
  105. data/lib/swarm_sdk/tools/edit.rb +8 -13
  106. data/lib/swarm_sdk/tools/glob.rb +12 -4
  107. data/lib/swarm_sdk/tools/grep.rb +7 -0
  108. data/lib/swarm_sdk/tools/multi_edit.rb +15 -11
  109. data/lib/swarm_sdk/tools/path_resolver.rb +51 -2
  110. data/lib/swarm_sdk/tools/read.rb +16 -18
  111. data/lib/swarm_sdk/tools/registry.rb +122 -10
  112. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +9 -5
  113. data/lib/swarm_sdk/tools/stores/storage.rb +0 -6
  114. data/lib/swarm_sdk/tools/todo_write.rb +7 -0
  115. data/lib/swarm_sdk/tools/web_fetch.rb +20 -17
  116. data/lib/swarm_sdk/tools/write.rb +8 -13
  117. data/lib/swarm_sdk/version.rb +1 -1
  118. data/lib/swarm_sdk/{node → workflow}/agent_config.rb +1 -1
  119. data/lib/swarm_sdk/workflow/builder.rb +192 -0
  120. data/lib/swarm_sdk/workflow/executor.rb +497 -0
  121. data/lib/swarm_sdk/{node/builder.rb → workflow/node_builder.rb} +7 -5
  122. data/lib/swarm_sdk/{node → workflow}/transformer_executor.rb +5 -3
  123. data/lib/swarm_sdk/{node_orchestrator.rb → workflow.rb} +152 -456
  124. data/lib/swarm_sdk.rb +294 -108
  125. data/rubocop/cop/security/no_reflection_methods.rb +1 -1
  126. data/swarm_cli.gemspec +1 -1
  127. data/swarm_memory.gemspec +8 -3
  128. data/swarm_sdk.gemspec +6 -4
  129. data/team_full.yml +124 -320
  130. metadata +42 -14
  131. data/lib/swarm_memory/chat_extension.rb +0 -34
  132. data/lib/swarm_memory/tools/memory_multi_edit.rb +0 -281
  133. data/lib/swarm_sdk/providers/openai_with_responses.rb +0 -589
  134. /data/lib/swarm_memory/{errors.rb → error.rb} +0 -0
@@ -5,10 +5,411 @@ All notable changes to SwarmSDK will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [Unreleased]
8
+ ## [2.5.1]
9
+
10
+ ### Dependencies
11
+
12
+ - Updated `ruby_llm_swarm-mcp` to `~> 0.8.1`
13
+
14
+ ## [2.5.0]
15
+
16
+ ### Added
17
+
18
+ - **Custom Tool Registration**: Simple API for registering custom tools without creating full plugins
19
+ - **`SwarmSDK.register_tool(ToolClass)`**: Register with inferred name (e.g., `WeatherTool` → `:Weather`)
20
+ - **`SwarmSDK.register_tool(:Name, ToolClass)`**: Register with explicit name
21
+ - **`SwarmSDK.custom_tool_registered?(:Name)`**: Check if tool is registered
22
+ - **`SwarmSDK.custom_tools`**: List all registered custom tool names
23
+ - **`SwarmSDK.unregister_tool(:Name)`**: Remove a registered tool
24
+ - **`SwarmSDK.clear_custom_tools!`**: Clear all registered tools (useful for testing)
25
+ - **Tool lookup order**: Plugin tools → Custom tools → Built-in tools
26
+ - **Context support**: Tools can declare `creation_requirements` for agent context (`:agent_name`, `:directory`)
27
+ - **Name consistency**: `NamedToolWrapper` ensures registered name is used for tool lookup
28
+ - **Validation**: Prevents overriding built-in tools or plugin tools
29
+ - **Use case**: Simple, stateless tools that don't need plugin lifecycle hooks or storage
30
+ - **Example**:
31
+ ```ruby
32
+ class WeatherTool < RubyLLM::Tool
33
+ description "Get weather for a city"
34
+ param :city, type: "string", required: true
35
+
36
+ def execute(city:)
37
+ "Weather in #{city}: Sunny"
38
+ end
39
+ end
40
+
41
+ SwarmSDK.register_tool(WeatherTool)
42
+
43
+ SwarmSDK.build do
44
+ name "Assistant"
45
+ lead :helper
46
+
47
+ agent :helper do
48
+ model "claude-sonnet-4"
49
+ description "Weather assistant"
50
+ system_prompt "You help with weather"
51
+ tools :Weather # Use the registered tool
52
+ end
53
+ end
54
+ ```
55
+ - **Files**: `lib/swarm_sdk/custom_tool_registry.rb`, `lib/swarm_sdk.rb`, `lib/swarm_sdk/swarm/tool_configurator.rb`
56
+ - **Tests**: 32 comprehensive tests (unit + integration)
57
+
58
+ ### Changed
59
+
60
+ - **BREAKING: Plugin API method renamed**: `storage_enabled?` → `memory_configured?` in Plugin base class
61
+ - **Rationale**: "memory" is the user-facing concept, "storage" is internal implementation detail
62
+ - **Better semantics**: "Is memory configured?" vs "Is storage enabled?"
63
+ - **No backward compatibility**: `storage_enabled?` method removed entirely (breaking change)
64
+ - **Impact**: Custom plugins implementing `storage_enabled?` must rename to `memory_configured?`
65
+ - **Migration**: Update plugin classes to implement `memory_configured?` instead of `storage_enabled?`
66
+ - **Files**: `lib/swarm_sdk/plugin.rb:142-148`
67
+ - **Updated callers**:
68
+ - `lib/swarm_sdk/swarm/agent_initializer.rb:572`
69
+ - `lib/swarm_sdk/agent/system_prompt_builder.rb:151`
70
+ - `lib/swarm_sdk/swarm/tool_configurator.rb:270`
71
+ - **Tests**: All plugin-related tests updated
72
+
73
+ ## [2.4.6]
74
+ - Use a fork of ruby_llm-mcp that requires ruby_llm_swarm instead of ruby_llm
75
+
76
+ ## [2.4.5]
77
+
78
+ ### Fixed
79
+
80
+ - **Context Window Tracking Bug**: Fixed model lookup using wrong source for context window data
81
+ - **Issue**: Changes to `models.json` had no effect on context window tracking - SDK always returned 0%
82
+ - **Root cause**: `fetch_real_model_info` was using `RubyLLM.models.find()` instead of `SwarmSDK::Models.find()`
83
+ - **Fix**: Changed model lookup to use `SwarmSDK::Models.find()` first, falling back to `RubyLLM.models.find()`
84
+ - **Impact**: Context window percentage now correctly calculated from SwarmSDK's models.json
85
+ - **Files**: `lib/swarm_sdk/agent/chat_helpers/llm_configuration.rb`
86
+
87
+ ### Added
88
+
89
+ - **Per-Agent Context Breakdown**: Real-time and historical context usage metrics per agent
90
+ - **`Swarm#context_breakdown`**: Returns live context metrics for all agents including:
91
+ - Token counts: `input_tokens`, `output_tokens`, `total_tokens`, `cached_tokens`, `cache_creation_tokens`, `effective_input_tokens`
92
+ - Context limits: `context_limit`, `usage_percentage`, `tokens_remaining`
93
+ - Cost metrics: `input_cost`, `output_cost`, `total_cost`
94
+ - **`Result#per_agent_usage`**: Extracts per-agent usage from execution logs (for historical analysis)
95
+ - **`swarm_stop` event enhancement**: Now includes `per_agent_usage` field with complete breakdown
96
+ - **Use cases**: Monitor token consumption, track costs per agent, identify context-heavy agents
97
+ - **Example**:
98
+ ```ruby
99
+ breakdown = swarm.context_breakdown
100
+ breakdown[:backend]
101
+ # => {
102
+ # input_tokens: 15000,
103
+ # output_tokens: 5000,
104
+ # total_tokens: 20000,
105
+ # cached_tokens: 2000,
106
+ # context_limit: 200000,
107
+ # usage_percentage: 10.0,
108
+ # tokens_remaining: 180000,
109
+ # input_cost: 0.045,
110
+ # output_cost: 0.075,
111
+ # total_cost: 0.12
112
+ # }
113
+ ```
114
+ - **Files**: `lib/swarm_sdk/swarm.rb`, `lib/swarm_sdk/result.rb`, `lib/swarm_sdk/swarm/hook_triggers.rb`, `lib/swarm_sdk/swarm/logging_callbacks.rb`
115
+
116
+ - **Cumulative Cost Tracking in TokenTracking**: New methods for calculating conversation costs
117
+ - **`cumulative_input_cost`**: Calculate total input cost based on tokens and model pricing
118
+ - **`cumulative_output_cost`**: Calculate total output cost based on tokens and model pricing
119
+ - **`cumulative_total_cost`**: Sum of input and output costs
120
+ - **Pricing source**: Uses `@real_model_info.pricing` from SwarmSDK's models.json
121
+ - **Files**: `lib/swarm_sdk/agent/chat_helpers/token_tracking.rb`
122
+
123
+ - **ModelInfo Class**: Wrapper class for model data with method access
124
+ - **`SwarmSDK::Models::ModelInfo`**: Replaces raw Hash returns from `Models.find()`
125
+ - **Attributes**: `id`, `name`, `provider`, `family`, `context_window`, `max_output_tokens`, `knowledge_cutoff`, `modalities`, `capabilities`, `pricing`, `metadata`
126
+ - **Files**: `lib/swarm_sdk/models.rb`
127
+
128
+ ### Tests
129
+
130
+ - **28 new tests** covering:
131
+ - `TokenTracking` cost methods (24 tests): context_limit, cumulative costs, pricing edge cases
132
+ - `Swarm#context_breakdown` (5 tests): structure, metrics, delegation instances, lazy initialization
133
+
134
+ ## [2.4.4]
9
135
 
10
136
  ### Added
11
137
 
138
+ - **Environment Variable Interpolation Control**: New `env_interpolation` setting to disable YAML variable interpolation
139
+ - **Global config**: `SwarmSDK.configure { |c| c.env_interpolation = false }`
140
+ - **Environment variable**: `SWARM_SDK_ENV_INTERPOLATION=false`
141
+ - **Per-load override**: `SwarmSDK.load(yaml, env_interpolation: false)` or `SwarmSDK.load_file(path, env_interpolation: false)`
142
+ - **Priority order**: per-load parameter > global config > environment variable > default (true)
143
+ - **Use cases**:
144
+ - Testing YAML files without setting environment variables
145
+ - Loading configs where `${...}` syntax should be preserved literally
146
+ - Security: preventing accidental environment variable exposure
147
+ - **Example**:
148
+ ```ruby
149
+ # Disable globally
150
+ SwarmSDK.configure do |config|
151
+ config.env_interpolation = false
152
+ end
153
+
154
+ # Disable for specific load
155
+ swarm = SwarmSDK.load_file("config.yml", env_interpolation: false)
156
+ ```
157
+ - **Files**: `lib/swarm_sdk/config.rb`, `lib/swarm_sdk/configuration.rb`, `lib/swarm_sdk/configuration/parser.rb`, `lib/swarm_sdk.rb`
158
+ - **Tests**: Comprehensive tests in `config_test.rb` and `configuration_test.rb`
159
+
160
+ ## [2.4.3]
161
+
162
+ ### Added
163
+
164
+ - **Global Agent Registry**: Declare agents in separate files and reference them by name across swarms
165
+ - **`SwarmSDK.agent(:name) { ... }`**: Register agents globally for reuse across multiple swarms
166
+ - **`SwarmSDK.clear_agent_registry!`**: Clear all registrations (useful for testing)
167
+ - **Registry lookup in builders**: `agent :name` (no block) fetches from global registry
168
+ - **Registry + overrides**: `agent :name do ... end` applies registry config then override block
169
+ - **Duplicate registration error**: Raises `ArgumentError` if registering same name twice
170
+ - **Workflow node auto-resolution**: Agents referenced in nodes automatically resolve from registry
171
+ - Checks workflow-level definitions first, then falls back to global registry
172
+ - Includes delegation targets (`delegates_to`) in auto-resolution
173
+ - **Best practice**: Don't set `delegates_to` in registry—delegation is swarm-specific. Set it as an override in each swarm.
174
+ - **Use case**: Define agents once in separate files, compose into multiple swarms without duplication
175
+ - **Example**:
176
+ ```ruby
177
+ # agents/backend.rb
178
+ SwarmSDK.agent :backend do
179
+ model "claude-sonnet-4"
180
+ description "Backend developer"
181
+ tools :Read, :Edit, :Bash
182
+ end
183
+
184
+ # swarm.rb
185
+ SwarmSDK.build do
186
+ name "Dev Team"
187
+ lead :backend
188
+ agent :backend # Pulls from registry
189
+ end
190
+
191
+ # workflow.rb - agents auto-resolve in nodes
192
+ SwarmSDK.workflow do
193
+ name "Pipeline"
194
+ start_node :build
195
+ node(:build) { agent(:backend) } # Auto-resolved from registry
196
+ end
197
+ ```
198
+ - **Files**: `lib/swarm_sdk/agent_registry.rb`, `lib/swarm_sdk.rb`, `lib/swarm_sdk/builders/base_builder.rb`, `lib/swarm_sdk/workflow/builder.rb`
199
+ - **Tests**: 32 comprehensive tests in `test/swarm_sdk/agent_registry_test.rb`
200
+
201
+ ## [2.4.2]
202
+
203
+ ### Fixed
204
+
205
+ - **Duplicate event emission bug**: Fixed agent_stop and agent_step events being emitted twice
206
+ - Root cause: `setup_logging` was being called twice during agent initialization
207
+ - First call in `agent_initializer.rb` when `LogStream.emitter` was set
208
+ - Second call in `emit_retroactive_agent_start_events` via `setup_logging_for_all_agents`
209
+ - Fix: Made `ContextTracker#setup_logging` idempotent with `@logging_setup` guard
210
+ - Prevents duplicate callback registration on `on_end_message`, `on_tool_result`, and `on_tool_call`
211
+
212
+ ### Added
213
+
214
+ - **Event deduplication tests**: Comprehensive test suite to prevent regression
215
+ - `test_agent_stop_event_not_duplicated` - Ensures agent_stop emitted exactly once
216
+ - `test_agent_step_event_not_duplicated` - Ensures agent_step emitted exactly once per tool response
217
+ - `test_tool_call_event_not_duplicated` - Ensures tool_call emitted exactly once per invocation
218
+ - `test_tool_result_event_not_duplicated` - Ensures tool_result emitted exactly once
219
+ - `test_setup_logging_idempotency` - Verifies idempotent behavior across multiple executions
220
+ - `test_comprehensive_event_counts_*` - Validates exact event counts for various scenarios
221
+
222
+ ### Dependencies
223
+
224
+ - Updated `ruby_llm_swarm` to `~> 1.9.5`
225
+ - Added `openssl` (`~> 3.3.2`) dependency
226
+
227
+ ## [2.4.1]
228
+ - Fix gemspec issues
229
+
230
+ ## [2.4.0]
231
+
232
+ ### Breaking Changes
233
+
234
+ - **Centralized Configuration System**: Unified all configuration into `SwarmSDK::Config`
235
+ - **New API**: `SwarmSDK.config` replaces `SwarmSDK.settings`
236
+ - **Removed**: `SwarmSDK::Settings` class removed entirely
237
+ - **Removed**: `SwarmSDK.settings` method removed
238
+ - **Removed**: `SwarmSDK.reset_settings!` → use `SwarmSDK.reset_config!`
239
+ - **Removed**: Tool constants (DEFAULT_TIMEOUT_MS, MAX_OUTPUT_LENGTH, etc.)
240
+ - **API key proxying**: All API keys automatically proxy to `RubyLLM.config`
241
+ - **Override all defaults**: Every constant in Defaults module can now be overridden at runtime
242
+ - **Priority**: explicit value → ENV variable → Defaults module constant
243
+ - **Lazy ENV loading**: Thread-safe with double-check locking
244
+ - **Migration**:
245
+ - `SwarmSDK.settings.allow_filesystem_tools` → `SwarmSDK.config.allow_filesystem_tools`
246
+ - `SwarmSDK.reset_settings!` → `SwarmSDK.reset_config!`
247
+ - Tool constants → `SwarmSDK.config.*` methods (e.g., `SwarmSDK.config.bash_command_timeout`)
248
+
249
+ ### Fixed
250
+
251
+ - **Base URL Configuration Bug**: Custom provider contexts now properly use configured API keys
252
+ - Previously: `configure_provider_base_url` read ENV directly, ignoring `RubyLLM.config`
253
+ - Now: Uses `SwarmSDK.config.openai_api_key` and other configured values
254
+ - Better error messages when API keys are missing for non-local endpoints
255
+
256
+ ## [2.3.0]
257
+
258
+ ### Breaking Changes
259
+
260
+ - **Agent::Chat Abstraction Layer**: Refactored Agent::Chat from inheritance to composition with RubyLLM::Chat
261
+ - **Removed direct access**: SDK consumers can no longer access `.tools`, `.messages`, or `.model` directly
262
+ - **New abstraction methods**: SwarmSDK-specific API that hides RubyLLM internals
263
+ - `has_tool?(name)` - Check if tool exists by name (symbol or string)
264
+ - `tool_names` - Get array of tool names (symbols)
265
+ - `model_id` - Get model identifier string
266
+ - `model_provider` - Get model provider string
267
+ - `message_count` - Get number of messages in conversation
268
+ - `has_user_message?` - Check if conversation has any user messages
269
+ - `last_assistant_message` - Get most recent assistant message
270
+ - `take_snapshot` - Serialize conversation for persistence
271
+ - `restore_snapshot(data)` - Restore conversation from serialized data
272
+ - **Internal access methods**: For helper modules that need direct access
273
+ - `internal_messages` - Direct array of RubyLLM messages (for internal use only)
274
+ - `internal_tools` - Direct hash of tool instances (for internal use only)
275
+ - `internal_model` - Direct RubyLLM model object (for internal use only)
276
+ - **Migration**:
277
+ - `chat.tools.key?(:Read)` → `chat.has_tool?(:Read)`
278
+ - `chat.tools.keys` → `chat.tool_names`
279
+ - `chat.model.id` → `chat.model_id`
280
+ - `chat.model.provider` → `chat.model_provider`
281
+ - `chat.messages.count` → `chat.message_count`
282
+ - `chat.messages` (for internal modules) → `chat.internal_messages`
283
+ - **Improved encapsulation**: Prevents tight coupling to RubyLLM internals, making future LLM library changes easier
284
+ - **Files affected**:
285
+ - `lib/swarm_sdk/agent/chat.rb` - Core abstraction implementation
286
+ - `lib/swarm_sdk/swarm.rb` - Uses `tool_names` instead of `tools.keys`
287
+ - `lib/swarm_sdk/state_snapshot.rb` - Uses `internal_messages`
288
+ - `lib/swarm_sdk/state_restorer.rb` - Uses `internal_messages`
289
+ - `lib/swarm_sdk/context_compactor.rb` - Uses `internal_messages`
290
+ - `lib/swarm_sdk/agent/chat/hook_integration.rb` - Uses abstraction methods
291
+ - `lib/swarm_sdk/agent/chat/system_reminder_injector.rb` - Uses abstraction methods
292
+ - `lib/swarm_sdk/agent/chat/context_tracker.rb` - Uses `model_id`
293
+
294
+ - **MAJOR REFACTORING**: Separated Swarm and Workflow into distinct, clear APIs
295
+ - `SwarmSDK.build` now ONLY returns `Swarm` (simple multi-agent collaboration)
296
+ - New `SwarmSDK.workflow` API for multi-stage workflows (returns `Workflow`)
297
+ - `NodeOrchestrator` class renamed to `Workflow` (clearer naming)
298
+ - Attempting to use nodes in `SwarmSDK.build` now raises `ConfigurationError`
299
+ - Snapshot version bumped to 2.0.0 (old snapshots incompatible)
300
+ - Snapshot structure changed: `swarm:` key renamed to `metadata:`
301
+
302
+ - **YAML Configuration**: Explicit type keys for Swarm vs Workflow
303
+ - `swarm:` key now ONLY for Swarm configurations (requires `lead:`, cannot have `nodes:`)
304
+ - New `workflow:` key for Workflow configurations (requires `start_node:` and `nodes:`)
305
+ - Cannot have both `swarm:` and `workflow:` keys in same file
306
+ - Same `SwarmSDK.load_file` API works for both types (auto-detects from root key)
307
+
308
+ ### Added
309
+
310
+ - New `SwarmSDK.workflow` DSL for building multi-stage workflows
311
+ - **YAML `workflow:` key support**: Explicit root key for workflow configurations
312
+ - Clearer separation between Swarm and Workflow in YAML files
313
+ - Configuration class with proper separation of concerns (type detection, validation, loading)
314
+ - Validates type-specific requirements (e.g., `swarm:` cannot have `nodes:`)
315
+ - Three new concern modules for shared functionality:
316
+ - `Concerns::Snapshotable` - Common snapshot/restore interface
317
+ - `Concerns::Validatable` - Common validation interface
318
+ - `Concerns::Cleanupable` - Common cleanup interface
319
+ - `Builders::BaseBuilder` - Shared DSL logic for both Swarm and Workflow builders
320
+ - Both `Swarm` and `Workflow` now implement common interface methods:
321
+ - `primary_agents` - Access to primary agent instances
322
+ - `delegation_instances_hash` - Access to delegation instances
323
+
324
+ ### Changed
325
+
326
+ - `Workflow` (formerly `NodeOrchestrator`) internal structure simplified to match `Swarm`:
327
+ - Replaced `@agent_instance_cache = { primary: {}, delegations: {} }`
328
+ - With `@agents = {}` and `@delegation_instances = {}`
329
+ - `Swarm::Builder` dramatically simplified: 784 lines → 208 lines (73% reduction)
330
+ - `StateSnapshot` and `StateRestorer` no longer use type checking - rely on interface methods
331
+ - `SnapshotFromEvents` updated to generate v2.0.0 snapshots with new structure
332
+ - Module namespace: `Node::` renamed to `Workflow::`
333
+ - `Node::Builder` → `Workflow::NodeBuilder`
334
+ - `Node::AgentConfig` → `Workflow::AgentConfig`
335
+ - `Node::TransformerExecutor` → `Workflow::TransformerExecutor`
336
+
337
+ ### Removed
338
+
339
+ - Dual-return-type pattern from `SwarmSDK.build` (no longer returns `NodeOrchestrator`)
340
+ - ~600 lines of duplicated code across Swarm and NodeOrchestrator
341
+ - Complex type-checking logic in StateSnapshot and StateRestorer
342
+
343
+ ### Migration Guide
344
+
345
+ **For vanilla swarm users (no nodes):** No changes needed! Your code works as-is.
346
+
347
+ **For workflow users (using Ruby DSL):** Change `SwarmSDK.build` to `SwarmSDK.workflow`:
348
+
349
+ ```ruby
350
+ # Before
351
+ SwarmSDK.build do
352
+ node :planning { ... }
353
+ end
354
+
355
+ # After
356
+ SwarmSDK.workflow do
357
+ node :planning { ... }
358
+ end
359
+ ```
360
+
361
+ **For YAML workflow users:** Change `swarm:` key to `workflow:`:
362
+
363
+ ```yaml
364
+ # Before
365
+ version: 2
366
+ swarm:
367
+ name: "Pipeline"
368
+ start_node: planning
369
+ agents: { ... }
370
+ nodes: { ... }
371
+
372
+ # After
373
+ version: 2
374
+ workflow:
375
+ name: "Pipeline"
376
+ start_node: planning
377
+ agents: { ... }
378
+ nodes: { ... }
379
+ ```
380
+
381
+ **For event-sourcing users:** No changes needed! `SnapshotFromEvents.reconstruct(events)` automatically generates v2.0.0 snapshots.
382
+
383
+ **For snapshot storage users:** Old snapshots (v1.0.0) won't restore. Create new snapshots or convert:
384
+ ```ruby
385
+ old[:version] = "2.0.0"
386
+ old[:metadata] = old.delete(:swarm)
387
+ ```
388
+
389
+ ### Added
390
+
391
+ - **Non-Blocking Execution with Cancellation Support**: Optional `wait` parameter enables task cancellation
392
+ - **`wait: true` (default)**: Maintains backward-compatible blocking behavior, returns `Result`
393
+ - **`wait: false`**: Returns `Async::Task` immediately for non-blocking execution
394
+ - **`task.stop`**: Cancels execution at next fiber yield point (HTTP I/O, tool boundaries)
395
+ - **Cooperative cancellation**: Stops when fiber yields, not immediate for synchronous operations
396
+ - **Proper cleanup**: MCP clients, fiber storage, and logging cleaned in task's ensure block
397
+ - **Cleanup on cancellation**: Ensure blocks execute when task stopped via `Async::Stop` exception
398
+ - **`task.wait` returns nil**: Cancelled tasks return `nil` from `wait` method
399
+ - **Execution flow**: Reprompting loop and all cleanup moved inside Async block
400
+ - **Parent cleanup**: Fiber storage cleaned after `task.wait` when `wait: true`
401
+ - **Examples**:
402
+ - Blocking: `result = swarm.execute("Build auth")` (current behavior)
403
+ - Non-blocking: `task = swarm.execute("Build auth", wait: false)` then `task.stop`
404
+ - **Files**: `lib/swarm_sdk/swarm.rb` (major refactor of execute method)
405
+ - **Tests**: 9 comprehensive tests in `test/swarm_sdk/execute_wait_parameter_test.rb`
406
+
407
+ - **Delegation Result Event Reconstruction**: Snapshot/restore now handles delegation events properly
408
+ - **`delegation_result` event support**: EventsToMessages reconstructs tool result messages from delegations
409
+ - **Proper conversation restoration**: Delegations correctly reconstructed from event logs
410
+ - **Snapshot compatibility**: Enables complete state restoration including delegation history
411
+ - **Files**: `lib/swarm_sdk/events_to_messages.rb`
412
+
12
413
  - **User Prompt Source Tracking**: `user_prompt` events now include source information to distinguish user interactions from delegations
13
414
  - **`source` field**: Indicates origin of prompt - `"user"` (direct user interaction) or `"delegation"` (from delegation tool)
14
415
  - **Event filtering**: Enables filtering user prompts by source in logs and analytics
@@ -36,7 +437,29 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
36
437
  - **Example**: `agent(:planner).tools(:Think, :Read)` in planning node, `agent(:planner).tools(:Write, :Edit, :Bash)` in implementation node
37
438
  - **Implementation**: New `tools(*tool_names)` method on `AgentConfig`, stored in node configuration as tool override
38
439
  - **Backward compatible**: Omit `.tools()` to use agent's global tool configuration
39
- - **Files**: `lib/swarm_sdk/node/agent_config.rb`, `lib/swarm_sdk/node/builder.rb`, `lib/swarm_sdk/node_orchestrator.rb`
440
+ - **Files**: `lib/swarm_sdk/workflow/agent_config.rb`, `lib/swarm_sdk/workflow/node_builder.rb`, `lib/swarm_sdk/workflow.rb`
441
+
442
+ ### Changed
443
+
444
+ - **BREAKING: Delegation Tool Rebranding**: Delegation tools renamed to emphasize collaboration over task delegation
445
+ - **Tool naming**: `DelegateTaskToBackend` → `WorkWithBackend`
446
+ - **Tool parameter**: `task:` → `message:` (more flexible, supports questions and collaboration)
447
+ - **Tool description**: Now emphasizes working with agents, not just delegating tasks
448
+ - **Configurable prefix**: Added `TOOL_NAME_PREFIX` constant for easy customization
449
+ - **Migration**: Update code/tests using `DelegateTaskTo*` to use `WorkWith*`
450
+ - **Parameter migration**: Change `task:` parameter to `message:` in delegation tool calls
451
+ - **Rationale**: Better reflects collaborative agent relationships and flexible communication patterns
452
+ - **Files affected**: `lib/swarm_sdk/tools/delegate.rb`, `lib/swarm_sdk/agent/chat/context_tracker.rb`, `lib/swarm_sdk/swarm/agent_initializer.rb`, `lib/swarm_cli/interactive_repl.rb`
453
+ - **Tests updated**: All delegation tests updated to use new naming (18 files)
454
+
455
+ ### Fixed
456
+
457
+ - **MCP Configuration for Non-OAuth Servers**: Fixed errors when configuring MCP servers without OAuth
458
+ - **Issue**: OAuth field was included in streamable config even when not configured, causing errors
459
+ - **Fix**: Removed `oauth` field from streamable config hash
460
+ - **Additional fix**: Only include `rate_limit` if explicitly configured (avoid nil values)
461
+ - **Impact**: MCP servers without OAuth now configure correctly without errors
462
+ - **Files**: `lib/swarm_sdk/swarm/mcp_configurator.rb`
40
463
 
41
464
  ## [2.2.0] - 2025-11-06
42
465
 
@@ -96,7 +519,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
96
519
  - **Documentation**: Complete guide in `docs/v2/guides/snapshots.md` with examples and comparisons
97
520
 
98
521
  - **System-Wide Filesystem Tools Control**: Global security setting to disable filesystem tools across all agents
99
- - **`SwarmSDK.settings.allow_filesystem_tools`** - Global setting to enable/disable filesystem tools (default: true)
522
+ - **`SwarmSDK.config.allow_filesystem_tools`** - Global setting to enable/disable filesystem tools (default: true)
100
523
  - **Environment variable**: `SWARM_SDK_ALLOW_FILESYSTEM_TOOLS` - Set via environment for production deployments
101
524
  - **Parameter override**: `allow_filesystem_tools:` parameter in `SwarmSDK.build`, `load`, and `load_file`
102
525
  - **Filesystem tools**: Read, Write, Edit, MultiEdit, Grep, Glob, Bash
@@ -158,7 +581,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
158
581
  - Enables calculating total cost/tokens for a single execution
159
582
  - Allows building complete execution traces across all agents and tools
160
583
  - **`swarm_id`**: Identifies which swarm/node emitted the event
161
- - Hierarchical format for NodeOrchestrator nodes (e.g., `workflow/node:planning`)
584
+ - Hierarchical format for Workflow nodes (e.g., `workflow/node:planning`)
162
585
  - Tracks execution flow through nested swarms and workflow stages
163
586
  - **`parent_swarm_id`**: Identifies the parent swarm for nested execution contexts
164
587
  - **Fiber-local storage implementation**: Uses Ruby 3.2+ Fiber storage for automatic propagation
@@ -203,7 +626,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
203
626
  - **Tool state isolation**: TodoWrite, ReadTracker, and other stateful tools isolated per instance
204
627
  - **Nested delegation support**: Works correctly with multi-level delegation chains
205
628
  - **Fiber-safe concurrency**: Added `Async::Semaphore` to `Chat.ask()` to prevent message corruption when multiple delegation instances call shared agents in parallel
206
- - **Atomic caching**: NodeOrchestrator caches delegation instances together with primary agents for context preservation
629
+ - **Atomic caching**: Workflow caches delegation instances together with primary agents for context preservation
207
630
  - **Agent name validation**: Agent names cannot contain '@' character (reserved for delegation instances)
208
631
  - **Automatic deduplication**: Duplicate entries in `delegates_to` are automatically removed
209
632
  - **Comprehensive test coverage**: 17 new tests covering isolated mode, shared mode, nested delegation, cleanup, and more
@@ -343,7 +766,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
343
766
  - **Context Preservation Across Nodes**: `reset_context` parameter for node agents
344
767
  - `agent(:name, reset_context: false)` preserves conversation history across nodes
345
768
  - Default: `reset_context: true` (fresh context for each node - safe default)
346
- - NodeOrchestrator caches and reuses agent instances when `reset_context: false`
769
+ - Workflow caches and reuses agent instances when `reset_context: false`
347
770
  - Enables stateful workflows where agents remember previous node conversations
348
771
  - Perfect for iterative refinement, self-reflection loops, and chain-of-thought reasoning
349
772
 
@@ -359,15 +782,15 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
359
782
  - Removes memory-specific code from SwarmSDK core (moved to SwarmMemory plugin)
360
783
  - Maintains backward compatibility - permissions remain in core SDK (not plugin-specific)
361
784
  - Enables clean separation between core SDK and plugin features (memory, skills, etc.)
362
- - Plugins can preserve their configuration when agents are cloned in NodeOrchestrator
785
+ - Plugins can preserve their configuration when agents are cloned in Workflow
363
786
 
364
- - **NodeOrchestrator**: Configurable scratchpad sharing modes
787
+ - **Workflow**: Configurable scratchpad sharing modes
365
788
  - `scratchpad: :enabled` - Share scratchpad across all nodes
366
789
  - `scratchpad: :per_node` - Isolated scratchpad per node
367
790
  - `scratchpad: :disabled` - No scratchpad tools (default)
368
791
 
369
- - **CLI ConfigLoader**: Accepts both Swarm and NodeOrchestrator instances
370
- - Bug fix: CLI now correctly handles NodeOrchestrator execution
792
+ - **CLI ConfigLoader**: Accepts both Swarm and Workflow instances
793
+ - Bug fix: CLI now correctly handles Workflow execution
371
794
  - Enables node workflows to work seamlessly with CLI commands
372
795
 
373
796
  - **Error handling in Agent::Chat**: More robust exception handling
data/docs/v2/README.md CHANGED
@@ -1,7 +1,5 @@
1
1
  # SwarmSDK, SwarmCLI & SwarmMemory Documentation
2
2
 
3
- **Version 2.1**
4
-
5
3
  Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory - a Ruby framework for orchestrating multiple AI agents as a collaborative team with persistent memory.
6
4
 
7
5
  ---
@@ -63,6 +61,10 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
63
61
  - **[Ruby DSL Reference](reference/ruby-dsl.md)**
64
62
  Complete programmatic API: `SwarmSDK.build`, `SwarmSDK.load`, agent DSL, permissions DSL, node DSL, hooks
65
63
 
64
+ ### Configuration
65
+ - **[Configuration Reference](reference/configuration_reference.md)** ⭐ NEW
66
+ Complete reference for all 45+ configuration options: API keys, timeouts, limits, WebFetch settings, security
67
+
66
68
  ### YAML Configuration
67
69
  - **[YAML Configuration Reference](reference/yaml.md)**
68
70
  Complete YAML structure: agents, tools, permissions, hooks, nodes, MCP servers
@@ -90,7 +92,7 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
90
92
  Persistent agent knowledge storage with semantic search:
91
93
  - Installation and setup
92
94
  - 4 memory categories (concept, fact, skill, experience)
93
- - 9 memory tools (MemoryWrite, LoadSkill, etc.)
95
+ - 8 memory tools (7 memory tools + LoadSkill for dynamic tool swapping)
94
96
  - Automatic skill discovery (hybrid semantic + keyword)
95
97
  - Relationship discovery and knowledge graphs
96
98
  - Performance and troubleshooting
@@ -199,12 +201,18 @@ Welcome to the official documentation for SwarmSDK, SwarmCLI, and SwarmMemory -
199
201
  **Build composable/reusable swarm teams** ⭐ NEW
200
202
  → [Composable Swarms Guide](guides/composable-swarms.md)
201
203
 
204
+ **Add custom tools to agents**
205
+ → [Ruby DSL Reference - Custom Tools](reference/ruby-dsl.md#custom-tool-registration)
206
+
202
207
  **Build a SwarmSDK plugin**
203
208
  → [Plugin System Guide](guides/plugins.md)
204
209
 
205
210
  **Build a custom storage adapter**
206
211
  → [Memory Adapter Guide](guides/memory-adapters.md)
207
212
 
213
+ **Configure SwarmSDK settings** ⭐ NEW
214
+ → [Configuration Reference](reference/configuration_reference.md)
215
+
208
216
  **Secure swarms for production** ⭐ NEW
209
217
  → [Filesystem Tools Control](reference/ruby-dsl.md#swarmsdk.configure) | [Security Considerations](guides/complete-tutorial.md#security-considerations)
210
218
 
@@ -237,6 +245,7 @@ docs/v2/
237
245
  ├── reference/ # Complete API references
238
246
  │ ├── architecture-flow.md # System architecture diagram ⭐ NEW
239
247
  │ ├── execution-flow.md # Runtime execution flow ⭐ NEW
248
+ │ ├── configuration_reference.md # All configuration options ⭐ NEW
240
249
  │ ├── event_payload_structures.md # Log event payloads
241
250
  │ ├── swarm_memory_technical_details.md # SwarmMemory deep dive
242
251
  │ ├── cli.md # CLI command reference
@@ -297,8 +306,8 @@ A command-line interface for running SwarmSDK swarms with two modes:
297
306
  A persistent memory system for agents with semantic search capabilities:
298
307
  - **Storage**: Hierarchical knowledge organization (concept, fact, skill, experience)
299
308
  - **Semantic Search**: FAISS-based vector similarity with local ONNX embeddings
300
- - **Memory Tools**: 9 tools for writing, reading, editing, and searching knowledge
301
- - **LoadSkill**: Dynamic tool swapping based on semantic skill discovery
309
+ - **Memory Tools**: 7 tools for writing, reading, editing, and searching knowledge
310
+ - **LoadSkill**: Dynamic tool swapping based on semantic skill discovery (8 tools total)
302
311
  - **Plugin Architecture**: Integrates seamlessly via SwarmSDK plugin system
303
312
 
304
313
  ### Configuration Formats
@@ -328,6 +337,7 @@ A persistent memory system for agents with semantic search capabilities:
328
337
  | **Memory Adapters** | [Adapter Guide](guides/memory-adapters.md) | [Technical Details](reference/swarm_memory_technical_details.md) |
329
338
  | **Plugins** | [Plugin Guide](guides/plugins.md) | - |
330
339
  | **Rails** | [Rails Guide](guides/rails-integration.md) | - |
340
+ | **Configuration** | - | [Configuration Ref](reference/configuration_reference.md) |
331
341
  | **Testing** | [Tutorial Part 8](guides/complete-tutorial.md#testing-strategies) | - |
332
342
 
333
343
  ---
@@ -337,10 +347,15 @@ A persistent memory system for agents with semantic search capabilities:
337
347
  All documentation in this directory follows these principles:
338
348
 
339
349
  ✅ **100% Accurate** - All information verified against source code
350
+
340
351
  ✅ **Comprehensive** - Every feature documented
352
+
341
353
  ✅ **Progressive** - Simple → Intermediate → Advanced
354
+
342
355
  ✅ **Practical** - Real-world examples throughout
356
+
343
357
  ✅ **Both Formats** - YAML and Ruby DSL for everything
358
+
344
359
  ✅ **User-Focused** - Written for developers using SwarmSDK, not implementers
345
360
 
346
361
  ---