claude_swarm 1.0.6 → 1.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (107) hide show
  1. checksums.yaml +4 -4
  2. data/.ruby-version +1 -1
  3. data/CHANGELOG.md +27 -0
  4. data/README.md +336 -1037
  5. data/docs/V1_TO_V2_MIGRATION_GUIDE.md +1120 -0
  6. data/docs/v1/README.md +1197 -0
  7. data/docs/v2/CHANGELOG.swarm_cli.md +22 -0
  8. data/docs/v2/CHANGELOG.swarm_memory.md +20 -0
  9. data/docs/v2/CHANGELOG.swarm_sdk.md +287 -10
  10. data/docs/v2/README.md +32 -6
  11. data/docs/v2/guides/complete-tutorial.md +133 -37
  12. data/docs/v2/guides/composable-swarms.md +1178 -0
  13. data/docs/v2/guides/getting-started.md +42 -1
  14. data/docs/v2/guides/snapshots.md +1498 -0
  15. data/docs/v2/reference/architecture-flow.md +5 -3
  16. data/docs/v2/reference/event_payload_structures.md +249 -12
  17. data/docs/v2/reference/execution-flow.md +1 -1
  18. data/docs/v2/reference/ruby-dsl.md +368 -22
  19. data/docs/v2/reference/yaml.md +314 -63
  20. data/examples/snapshot_demo.rb +119 -0
  21. data/examples/v2/dsl/01_basic.rb +0 -2
  22. data/examples/v2/dsl/02_core_parameters.rb +0 -2
  23. data/examples/v2/dsl/03_capabilities.rb +0 -2
  24. data/examples/v2/dsl/04_llm_parameters.rb +0 -2
  25. data/examples/v2/dsl/05_advanced_flags.rb +0 -3
  26. data/examples/v2/dsl/06_permissions.rb +0 -4
  27. data/examples/v2/dsl/07_mcp_server.rb +0 -2
  28. data/examples/v2/dsl/08_swarm_hooks.rb +0 -2
  29. data/examples/v2/dsl/09_agent_hooks.rb +0 -2
  30. data/examples/v2/dsl/10_all_agents_hooks.rb +0 -3
  31. data/examples/v2/dsl/11_delegation.rb +0 -2
  32. data/examples/v2/dsl/12_complete_integration.rb +2 -6
  33. data/examples/v2/node_context_demo.rb +1 -1
  34. data/examples/v2/node_workflow.rb +2 -4
  35. data/examples/v2/plan_and_execute.rb +157 -0
  36. data/lib/claude_swarm/cli.rb +0 -18
  37. data/lib/claude_swarm/configuration.rb +28 -18
  38. data/lib/claude_swarm/openai/chat_completion.rb +2 -11
  39. data/lib/claude_swarm/openai/responses.rb +2 -11
  40. data/lib/claude_swarm/version.rb +1 -1
  41. data/lib/swarm_cli/formatters/human_formatter.rb +103 -0
  42. data/lib/swarm_cli/interactive_repl.rb +9 -3
  43. data/lib/swarm_cli/version.rb +1 -1
  44. data/lib/swarm_memory/core/storage_read_tracker.rb +51 -14
  45. data/lib/swarm_memory/integration/cli_registration.rb +3 -2
  46. data/lib/swarm_memory/integration/sdk_plugin.rb +11 -5
  47. data/lib/swarm_memory/tools/memory_edit.rb +2 -2
  48. data/lib/swarm_memory/tools/memory_multi_edit.rb +2 -2
  49. data/lib/swarm_memory/tools/memory_read.rb +3 -3
  50. data/lib/swarm_memory/version.rb +1 -1
  51. data/lib/swarm_memory.rb +5 -0
  52. data/lib/swarm_sdk/agent/builder.rb +33 -0
  53. data/lib/swarm_sdk/agent/chat/context_tracker.rb +33 -0
  54. data/lib/swarm_sdk/agent/chat/hook_integration.rb +49 -3
  55. data/lib/swarm_sdk/agent/chat/system_reminder_injector.rb +11 -27
  56. data/lib/swarm_sdk/agent/chat.rb +200 -51
  57. data/lib/swarm_sdk/agent/context.rb +6 -2
  58. data/lib/swarm_sdk/agent/context_manager.rb +6 -0
  59. data/lib/swarm_sdk/agent/definition.rb +14 -2
  60. data/lib/swarm_sdk/agent/llm_instrumentation_middleware.rb +180 -0
  61. data/lib/swarm_sdk/configuration.rb +387 -94
  62. data/lib/swarm_sdk/events_to_messages.rb +181 -0
  63. data/lib/swarm_sdk/log_collector.rb +31 -5
  64. data/lib/swarm_sdk/log_stream.rb +37 -8
  65. data/lib/swarm_sdk/model_aliases.json +4 -1
  66. data/lib/swarm_sdk/node/agent_config.rb +33 -8
  67. data/lib/swarm_sdk/node/builder.rb +39 -18
  68. data/lib/swarm_sdk/node_orchestrator.rb +293 -26
  69. data/lib/swarm_sdk/proc_helpers.rb +53 -0
  70. data/lib/swarm_sdk/providers/openai_with_responses.rb +22 -15
  71. data/lib/swarm_sdk/restore_result.rb +65 -0
  72. data/lib/swarm_sdk/snapshot.rb +156 -0
  73. data/lib/swarm_sdk/snapshot_from_events.rb +386 -0
  74. data/lib/swarm_sdk/state_restorer.rb +491 -0
  75. data/lib/swarm_sdk/state_snapshot.rb +369 -0
  76. data/lib/swarm_sdk/swarm/agent_initializer.rb +360 -55
  77. data/lib/swarm_sdk/swarm/all_agents_builder.rb +28 -1
  78. data/lib/swarm_sdk/swarm/builder.rb +208 -12
  79. data/lib/swarm_sdk/swarm/swarm_registry_builder.rb +67 -0
  80. data/lib/swarm_sdk/swarm/tool_configurator.rb +46 -11
  81. data/lib/swarm_sdk/swarm.rb +338 -42
  82. data/lib/swarm_sdk/swarm_loader.rb +145 -0
  83. data/lib/swarm_sdk/swarm_registry.rb +136 -0
  84. data/lib/swarm_sdk/tools/delegate.rb +92 -7
  85. data/lib/swarm_sdk/tools/read.rb +17 -5
  86. data/lib/swarm_sdk/tools/stores/read_tracker.rb +47 -12
  87. data/lib/swarm_sdk/tools/stores/scratchpad_storage.rb +45 -0
  88. data/lib/swarm_sdk/utils.rb +18 -0
  89. data/lib/swarm_sdk/validation_result.rb +33 -0
  90. data/lib/swarm_sdk/version.rb +1 -1
  91. data/lib/swarm_sdk.rb +40 -8
  92. data/swarm_cli.gemspec +1 -1
  93. data/swarm_memory.gemspec +2 -2
  94. data/swarm_sdk.gemspec +2 -2
  95. metadata +21 -13
  96. data/examples/learning-assistant/assistant.md +0 -7
  97. data/examples/learning-assistant/example-memories/concept-example.md +0 -90
  98. data/examples/learning-assistant/example-memories/experience-example.md +0 -66
  99. data/examples/learning-assistant/example-memories/fact-example.md +0 -76
  100. data/examples/learning-assistant/example-memories/memory-index.md +0 -78
  101. data/examples/learning-assistant/example-memories/skill-example.md +0 -168
  102. data/examples/learning-assistant/learning_assistant.rb +0 -34
  103. data/examples/learning-assistant/learning_assistant.yml +0 -20
  104. data/lib/swarm_sdk/mcp.rb +0 -16
  105. data/llm.v2.txt +0 -13407
  106. /data/docs/v2/guides/{MEMORY_DEFRAG_GUIDE.md → memory-defrag-guide.md} +0 -0
  107. /data/{llms.txt → llms.claude-swarm.txt} +0 -0
@@ -395,7 +395,7 @@ agent :planner do
395
395
  description "Task planner"
396
396
  model "gpt-4"
397
397
  system_prompt "Plan and track work"
398
- # TodoWrite included by default
398
+ tools :Read, :Grep, :Glob, :TodoWrite # Add TodoWrite explicitly
399
399
  end
400
400
  ```
401
401
 
@@ -538,7 +538,7 @@ agent :problem_solver do
538
538
  description "Problem solver"
539
539
  model "gpt-4"
540
540
  system_prompt "Use the Think tool frequently to reason through problems"
541
- # Think included by default
541
+ tools :Read, :Grep, :Glob, :Think # Add Think explicitly
542
542
  end
543
543
  ```
544
544
 
@@ -585,7 +585,7 @@ agent :researcher do
585
585
  description "Web researcher"
586
586
  model "gpt-4"
587
587
  system_prompt "Research information from web sources"
588
- # WebFetch included by default
588
+ tools :Read, :Grep, :Glob, :WebFetch # Add WebFetch explicitly
589
589
  end
590
590
  ```
591
591
 
@@ -631,8 +631,7 @@ WebFetch(url: "https://example.com/api-docs", prompt: "List all available API en
631
631
  agent :agent_name do
632
632
  description "..."
633
633
  model "gpt-4"
634
- disable_default_tools [:Think, :WebFetch] # Disable specific tools
635
- # Or disable multiple: [:Think, :TodoWrite, :Grep]
634
+ disable_default_tools [:Read, :Grep] # Disable specific tools
636
635
  end
637
636
  ```
638
637
 
@@ -678,8 +677,8 @@ end
678
677
  agent :selective_agent do
679
678
  description "Selective agent"
680
679
  model "gpt-4"
681
- disable_default_tools [:Think, :TodoWrite] # Disable these
682
- # Still has: Read, Grep, Glob, Scratchpad tools
680
+ disable_default_tools [:Read, :Grep] # Disable these
681
+ # Still has: Glob, Scratchpad tools
683
682
  end
684
683
  ```
685
684
 
@@ -1084,6 +1083,67 @@ Lead ──┼──→ Security
1084
1083
  - **Hub and Spoke**: Parallel tasks coordinated by lead
1085
1084
  - **Specialist Pool**: Lead delegates to any specialist as needed
1086
1085
 
1086
+ #### Delegation Isolation Modes
1087
+
1088
+ When multiple agents delegate to the same target agent, you can control whether they share conversation history or get isolated instances.
1089
+
1090
+ **Problem this solves**: Without isolation, multiple agents delegating to the same target share conversation history, causing context mixing. For example, if both `frontend` and `backend` delegate to `tester`, the tester's conversation includes both delegations mixed together, making it confusing.
1091
+
1092
+ **Solution: Isolated Instances (Default)**
1093
+
1094
+ By default, each delegator gets its own isolated instance:
1095
+
1096
+ ```yaml
1097
+ agents:
1098
+ tester:
1099
+ description: "Testing agent"
1100
+ # shared_across_delegations: false (default - isolated mode)
1101
+
1102
+ frontend:
1103
+ description: "Frontend developer"
1104
+ delegates_to: [tester] # Gets tester@frontend
1105
+
1106
+ backend:
1107
+ description: "Backend developer"
1108
+ delegates_to: [tester] # Gets tester@backend (separate instance)
1109
+ ```
1110
+
1111
+ **Result**:
1112
+ - `frontend` → `tester@frontend` (isolated conversation)
1113
+ - `backend` → `tester@backend` (separate isolated conversation)
1114
+ - No context mixing between frontend and backend's testing conversations
1115
+
1116
+ **When to Use Shared Mode**
1117
+
1118
+ For agents that benefit from seeing all delegation contexts:
1119
+
1120
+ ```yaml
1121
+ agents:
1122
+ database:
1123
+ description: "Database coordination agent"
1124
+ shared_across_delegations: true # Shared mode
1125
+
1126
+ frontend:
1127
+ delegates_to: [database]
1128
+
1129
+ backend:
1130
+ delegates_to: [database]
1131
+ ```
1132
+
1133
+ Both frontend and backend share the same database agent instance and conversation history.
1134
+
1135
+ **Use shared mode for:**
1136
+ - Stateful coordination agents
1137
+ - Database agents maintaining transaction state
1138
+ - Agents that benefit from seeing all contexts
1139
+
1140
+ **Memory Sharing (Always Enabled)**
1141
+
1142
+ Regardless of isolation mode, **plugin storage is always shared** by base agent name:
1143
+ - `tester@frontend` and `tester@backend` share the same SwarmMemory storage
1144
+ - This allows delegation instances to share knowledge while maintaining separate conversations
1145
+ - Best of both worlds: isolated conversations + shared memory
1146
+
1087
1147
  ### 3.5 Markdown Agent Files
1088
1148
 
1089
1149
  Define agents in separate markdown files for better organization:
@@ -1891,29 +1951,25 @@ end
1891
1951
 
1892
1952
  **Control Flow Methods**:
1893
1953
 
1894
- NodeContext provides three methods for dynamic workflow control:
1954
+ NodeContext provides three methods for dynamic workflow control. Input and output blocks are automatically converted to lambdas, which means you can use `return` statements for clean early exits.
1895
1955
 
1896
1956
  **1. goto_node - Jump to any node**:
1897
1957
  ```ruby
1898
1958
  output do |ctx|
1899
- if needs_revision?(ctx.content)
1900
- # Jump back to revision node instead of continuing forward
1901
- ctx.goto_node(:revision, content: ctx.content)
1902
- else
1903
- ctx.content # Continue to next node normally
1904
- end
1959
+ # Using return for early exit (clean and natural)
1960
+ return ctx.goto_node(:revision, content: ctx.content) if needs_revision?(ctx.content)
1961
+
1962
+ ctx.content # Continue to next node normally
1905
1963
  end
1906
1964
  ```
1907
1965
 
1908
1966
  **2. halt_workflow - Stop entire workflow**:
1909
1967
  ```ruby
1910
1968
  output do |ctx|
1911
- if converged?(ctx.content)
1912
- # Stop workflow early with final result
1913
- ctx.halt_workflow(content: ctx.content)
1914
- else
1915
- ctx.content # Continue to next node
1916
- end
1969
+ # Using return for early exit
1970
+ return ctx.halt_workflow(content: ctx.content) if converged?(ctx.content)
1971
+
1972
+ ctx.content # Continue to next node
1917
1973
  end
1918
1974
  ```
1919
1975
 
@@ -1921,27 +1977,26 @@ end
1921
1977
  ```ruby
1922
1978
  input do |ctx|
1923
1979
  cached = check_cache(ctx.content)
1924
- if cached
1925
- # Skip expensive LLM call and use cached result
1926
- ctx.skip_execution(content: cached)
1927
- else
1928
- ctx.content # Execute node normally
1929
- end
1980
+
1981
+ # Using return for early exit when cached
1982
+ return ctx.skip_execution(content: cached) if cached
1983
+
1984
+ ctx.content # Execute node normally
1930
1985
  end
1931
1986
  ```
1932
1987
 
1988
+ **Why `return` works safely**: Input and output blocks are automatically converted to lambdas, where `return` only exits the transformer block, not your entire program. This enables natural Ruby control flow patterns.
1989
+
1933
1990
  **Creating loops with goto_node**:
1934
1991
  ```ruby
1935
1992
  node :reasoning do
1936
1993
  agent(:thinker, reset_context: false) # Preserve context across iterations
1937
1994
 
1938
1995
  output do |ctx|
1939
- # Loop until convergence
1940
- if ctx.all_results.size > 10
1941
- ctx.halt_workflow(content: "Max iterations reached")
1942
- else
1943
- ctx.goto_node(:reflection, content: ctx.content)
1944
- end
1996
+ # Using return for early exit when max iterations reached
1997
+ return ctx.halt_workflow(content: "Max iterations reached") if ctx.all_results.size > 10
1998
+
1999
+ ctx.goto_node(:reflection, content: ctx.content)
1945
2000
  end
1946
2001
  end
1947
2002
 
@@ -1961,11 +2016,10 @@ start_node :reasoning
1961
2016
 
1962
2017
  ```ruby
1963
2018
  output do |ctx|
1964
- if ctx.error
1965
- ctx.halt_workflow(content: "Error: #{ctx.error.message}")
1966
- else
1967
- ctx.goto_node(:next_node, content: ctx.content)
1968
- end
2019
+ # Using return for early exit on error
2020
+ return ctx.halt_workflow(content: "Error: #{ctx.error.message}") if ctx.error
2021
+
2022
+ ctx.goto_node(:next_node, content: ctx.content)
1969
2023
  end
1970
2024
  ```
1971
2025
 
@@ -3003,6 +3057,48 @@ Staging: Restricted access, validated outputs
3003
3057
  Production: Minimal access, extensive hooks
3004
3058
  ```
3005
3059
 
3060
+ **6. Disable filesystem tools globally (system-wide security)**:
3061
+ ```ruby
3062
+ # For multi-tenant platforms or sandboxed environments
3063
+ SwarmSDK.configure do |config|
3064
+ config.allow_filesystem_tools = false
3065
+ end
3066
+
3067
+ # Or via environment variable (recommended for production)
3068
+ ENV['SWARM_SDK_ALLOW_FILESYSTEM_TOOLS'] = 'false'
3069
+
3070
+ # Agents can now only use non-filesystem tools
3071
+ swarm = SwarmSDK.build do
3072
+ name "API Analyst"
3073
+ lead :analyst
3074
+
3075
+ agent :analyst do
3076
+ description "Analyzes data via APIs only"
3077
+ model "gpt-5"
3078
+ # These work: Think, WebFetch, Clock, TodoWrite, Scratchpad*, Memory*
3079
+ tools :Think, :WebFetch
3080
+ # These are blocked: Read, Write, Edit, MultiEdit, Grep, Glob, Bash
3081
+ end
3082
+ end
3083
+
3084
+ # Override per-swarm if needed
3085
+ restricted_swarm = SwarmSDK.build(allow_filesystem_tools: false) do
3086
+ # ... specific swarm that needs extra restriction
3087
+ end
3088
+ ```
3089
+
3090
+ **Use cases:**
3091
+ - **Multi-tenant platforms**: Prevent user-provided swarms from accessing filesystem
3092
+ - **Containerized deployments**: Read-only filesystems or restricted environments
3093
+ - **Compliance requirements**: Data analysis workloads that forbid file operations
3094
+ - **CI/CD pipelines**: Agents should only interact via APIs
3095
+
3096
+ **Key features:**
3097
+ - **Security boundary**: Cannot be overridden by swarm YAML/DSL configuration
3098
+ - **Validation**: Errors caught at build time with clear messages
3099
+ - **Priority**: Explicit parameter > Global setting > Environment variable > Default (true)
3100
+ - **Non-breaking**: Defaults to `true` for backward compatibility
3101
+
3006
3102
  ### 8.6 Cost Management
3007
3103
 
3008
3104
  **Track costs in real-time**: