claude_swarm 1.0.4 → 1.0.6
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 +24 -0
- data/Rakefile +4 -4
- data/docs/v2/CHANGELOG.swarm_cli.md +19 -0
- data/docs/v2/CHANGELOG.swarm_memory.md +19 -0
- data/docs/v2/CHANGELOG.swarm_sdk.md +92 -0
- data/docs/v2/README.md +56 -22
- data/docs/v2/guides/MEMORY_DEFRAG_GUIDE.md +811 -0
- data/docs/v2/guides/complete-tutorial.md +115 -3
- data/docs/v2/guides/getting-started.md +6 -6
- data/docs/v2/guides/rails-integration.md +6 -6
- data/docs/v2/reference/architecture-flow.md +407 -0
- data/docs/v2/reference/event_payload_structures.md +471 -0
- data/docs/v2/reference/execution-flow.md +600 -0
- data/docs/v2/reference/ruby-dsl.md +138 -5
- data/docs/v2/reference/swarm_memory_technical_details.md +2090 -0
- data/examples/v2/swarm_with_hooks.yml +1 -1
- data/lib/claude_swarm/cli.rb +9 -11
- data/lib/claude_swarm/commands/ps.rb +1 -2
- data/lib/claude_swarm/configuration.rb +2 -3
- data/lib/claude_swarm/mcp_generator.rb +4 -10
- data/lib/claude_swarm/orchestrator.rb +43 -44
- data/lib/claude_swarm/system_utils.rb +4 -4
- data/lib/claude_swarm/version.rb +1 -1
- data/lib/claude_swarm.rb +4 -9
- data/lib/swarm_cli/commands/mcp_serve.rb +2 -2
- data/lib/swarm_cli/commands/mcp_tools.rb +3 -3
- data/lib/swarm_cli/config_loader.rb +14 -13
- data/lib/swarm_cli/version.rb +1 -1
- data/lib/swarm_cli.rb +2 -0
- data/lib/swarm_memory/adapters/base.rb +4 -4
- data/lib/swarm_memory/adapters/filesystem_adapter.rb +0 -12
- data/lib/swarm_memory/core/storage.rb +66 -6
- data/lib/swarm_memory/integration/sdk_plugin.rb +14 -0
- data/lib/swarm_memory/optimization/defragmenter.rb +4 -0
- data/lib/swarm_memory/tools/memory_edit.rb +1 -0
- data/lib/swarm_memory/tools/memory_glob.rb +24 -1
- data/lib/swarm_memory/tools/memory_write.rb +2 -2
- data/lib/swarm_memory/version.rb +1 -1
- data/lib/swarm_memory.rb +2 -0
- data/lib/swarm_sdk/agent/chat.rb +1 -1
- data/lib/swarm_sdk/agent/definition.rb +18 -21
- data/lib/swarm_sdk/configuration.rb +34 -10
- data/lib/swarm_sdk/mcp.rb +16 -0
- data/lib/swarm_sdk/node/agent_config.rb +7 -2
- data/lib/swarm_sdk/node/builder.rb +130 -35
- data/lib/swarm_sdk/node_context.rb +75 -0
- data/lib/swarm_sdk/node_orchestrator.rb +219 -12
- data/lib/swarm_sdk/plugin.rb +73 -1
- data/lib/swarm_sdk/prompts/base_system_prompt.md.erb +0 -126
- data/lib/swarm_sdk/result.rb +32 -6
- data/lib/swarm_sdk/swarm/builder.rb +1 -0
- data/lib/swarm_sdk/swarm.rb +32 -50
- data/lib/swarm_sdk/tools/delegate.rb +2 -2
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_list.rb +23 -2
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb +23 -2
- data/lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb +21 -4
- data/lib/swarm_sdk/tools/stores/storage.rb +4 -4
- data/lib/swarm_sdk/tools/think.rb +4 -1
- data/lib/swarm_sdk/tools/todo_write.rb +20 -8
- data/lib/swarm_sdk/version.rb +1 -1
- data/lib/swarm_sdk.rb +332 -27
- data/swarm_sdk.gemspec +1 -1
- metadata +9 -3
data/lib/swarm_sdk/swarm.rb
CHANGED
|
@@ -4,25 +4,10 @@ module SwarmSDK
|
|
|
4
4
|
# Swarm orchestrates multiple AI agents with shared rate limiting and coordination.
|
|
5
5
|
#
|
|
6
6
|
# This is the main user-facing API for SwarmSDK. Users create swarms using:
|
|
7
|
-
# -
|
|
8
|
-
# -
|
|
9
|
-
# - YAML:
|
|
10
|
-
#
|
|
11
|
-
# ## Direct API
|
|
12
|
-
#
|
|
13
|
-
# swarm = Swarm.new(name: "Development Team")
|
|
14
|
-
#
|
|
15
|
-
# backend_agent = Agent::Definition.new(:backend, {
|
|
16
|
-
# description: "Backend developer",
|
|
17
|
-
# model: "gpt-5",
|
|
18
|
-
# system_prompt: "You build APIs and databases...",
|
|
19
|
-
# tools: [:Read, :Edit, :Bash],
|
|
20
|
-
# delegates_to: [:database]
|
|
21
|
-
# })
|
|
22
|
-
# swarm.add_agent(backend_agent)
|
|
23
|
-
#
|
|
24
|
-
# swarm.lead = :backend
|
|
25
|
-
# result = swarm.execute("Build authentication")
|
|
7
|
+
# - Ruby DSL: SwarmSDK.build { ... } (Recommended)
|
|
8
|
+
# - YAML String: SwarmSDK.load(yaml, base_dir:)
|
|
9
|
+
# - YAML File: SwarmSDK.load_file(path)
|
|
10
|
+
# - Direct API: Swarm.new + add_agent (Advanced)
|
|
26
11
|
#
|
|
27
12
|
# ## Ruby DSL (Recommended)
|
|
28
13
|
#
|
|
@@ -39,14 +24,36 @@ module SwarmSDK
|
|
|
39
24
|
# end
|
|
40
25
|
# result = swarm.execute("Build authentication")
|
|
41
26
|
#
|
|
42
|
-
# ## YAML API
|
|
27
|
+
# ## YAML String API
|
|
43
28
|
#
|
|
44
|
-
#
|
|
29
|
+
# yaml = File.read("swarm.yml")
|
|
30
|
+
# swarm = SwarmSDK.load(yaml, base_dir: "/path/to/project")
|
|
31
|
+
# result = swarm.execute("Build authentication")
|
|
32
|
+
#
|
|
33
|
+
# ## YAML File API (Convenience)
|
|
34
|
+
#
|
|
35
|
+
# swarm = SwarmSDK.load_file("swarm.yml")
|
|
36
|
+
# result = swarm.execute("Build authentication")
|
|
37
|
+
#
|
|
38
|
+
# ## Direct API (Advanced)
|
|
39
|
+
#
|
|
40
|
+
# swarm = Swarm.new(name: "Development Team")
|
|
41
|
+
#
|
|
42
|
+
# backend_agent = Agent::Definition.new(:backend, {
|
|
43
|
+
# description: "Backend developer",
|
|
44
|
+
# model: "gpt-5",
|
|
45
|
+
# system_prompt: "You build APIs and databases...",
|
|
46
|
+
# tools: [:Read, :Edit, :Bash],
|
|
47
|
+
# delegates_to: [:database]
|
|
48
|
+
# })
|
|
49
|
+
# swarm.add_agent(backend_agent)
|
|
50
|
+
#
|
|
51
|
+
# swarm.lead = :backend
|
|
45
52
|
# result = swarm.execute("Build authentication")
|
|
46
53
|
#
|
|
47
54
|
# ## Architecture
|
|
48
55
|
#
|
|
49
|
-
# All
|
|
56
|
+
# All APIs converge on Agent::Definition for validation.
|
|
50
57
|
# Swarm delegates to specialized concerns:
|
|
51
58
|
# - Agent::Definition: Validates configuration, builds system prompts
|
|
52
59
|
# - AgentInitializer: Complex 5-pass agent setup
|
|
@@ -96,39 +103,14 @@ module SwarmSDK
|
|
|
96
103
|
def apply_mcp_logging_configuration
|
|
97
104
|
return if @mcp_logging_configured
|
|
98
105
|
|
|
106
|
+
SwarmSDK::MCP.lazy_load
|
|
107
|
+
|
|
99
108
|
RubyLLM::MCP.configure do |config|
|
|
100
109
|
config.log_level = @mcp_log_level
|
|
101
110
|
end
|
|
102
111
|
|
|
103
112
|
@mcp_logging_configured = true
|
|
104
113
|
end
|
|
105
|
-
|
|
106
|
-
# Load swarm from YAML configuration file
|
|
107
|
-
#
|
|
108
|
-
# @param config_path [String] Path to YAML configuration file
|
|
109
|
-
# @return [Swarm] Configured swarm instance
|
|
110
|
-
def load(config_path)
|
|
111
|
-
config = Configuration.load(config_path)
|
|
112
|
-
swarm = config.to_swarm
|
|
113
|
-
|
|
114
|
-
# Apply hooks if any are configured (YAML-only feature)
|
|
115
|
-
if hooks_configured?(config)
|
|
116
|
-
Hooks::Adapter.apply_hooks(swarm, config)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
# Store config reference for agent hooks (applied during initialize_agents)
|
|
120
|
-
swarm.config_for_hooks = config
|
|
121
|
-
|
|
122
|
-
swarm
|
|
123
|
-
end
|
|
124
|
-
|
|
125
|
-
private
|
|
126
|
-
|
|
127
|
-
def hooks_configured?(config)
|
|
128
|
-
config.swarm_hooks.any? ||
|
|
129
|
-
config.all_agents_hooks.any? ||
|
|
130
|
-
config.agents.any? { |_, agent_def| agent_def.hooks&.any? }
|
|
131
|
-
end
|
|
132
114
|
end
|
|
133
115
|
|
|
134
116
|
# Initialize a new Swarm
|
|
@@ -433,7 +415,7 @@ module SwarmSDK
|
|
|
433
415
|
# @return [Array<Hash>] Array of warning hashes from all agent definitions
|
|
434
416
|
#
|
|
435
417
|
# @example
|
|
436
|
-
# swarm =
|
|
418
|
+
# swarm = SwarmSDK.load_file("config.yml")
|
|
437
419
|
# warnings = swarm.validate
|
|
438
420
|
# warnings.each do |warning|
|
|
439
421
|
# puts "⚠️ #{warning[:agent]}: #{warning[:model]} not found"
|
|
@@ -43,8 +43,8 @@ module SwarmSDK
|
|
|
43
43
|
@delegate_target = delegate_name.to_s
|
|
44
44
|
end
|
|
45
45
|
|
|
46
|
-
#
|
|
47
|
-
description
|
|
46
|
+
# Override description to return dynamic string based on delegate
|
|
47
|
+
def description
|
|
48
48
|
"Delegate tasks to #{@delegate_name}. #{@delegate_description}"
|
|
49
49
|
end
|
|
50
50
|
|
|
@@ -12,8 +12,29 @@ module SwarmSDK
|
|
|
12
12
|
|
|
13
13
|
description <<~DESC
|
|
14
14
|
List all entries in scratchpad with their metadata.
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
## When to Use ScratchpadList
|
|
17
|
+
|
|
18
|
+
Use ScratchpadList to:
|
|
19
|
+
- Discover what content is available in the scratchpad
|
|
20
|
+
- Check what other agents have stored
|
|
21
|
+
- Find relevant entries before reading them
|
|
22
|
+
- Review all stored outputs and analysis
|
|
23
|
+
- Check entry sizes and last update times
|
|
24
|
+
|
|
25
|
+
## Best Practices
|
|
26
|
+
|
|
27
|
+
- Use this before ScratchpadRead if you don't know what's stored
|
|
28
|
+
- Filter by prefix to narrow down results (e.g., 'notes/' lists all notes)
|
|
29
|
+
- Shows path, title, size, and last updated time for each entry
|
|
30
|
+
- Any agent can see all scratchpad entries
|
|
31
|
+
- Helps coordinate multi-agent workflows
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
- List all entries: (no prefix parameter)
|
|
36
|
+
- List notes only: prefix='notes/'
|
|
37
|
+
- List analysis results: prefix='analysis/'
|
|
17
38
|
DESC
|
|
18
39
|
|
|
19
40
|
param :prefix,
|
|
@@ -12,8 +12,29 @@ module SwarmSDK
|
|
|
12
12
|
|
|
13
13
|
description <<~DESC
|
|
14
14
|
Read content from scratchpad.
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
|
|
16
|
+
## When to Use ScratchpadRead
|
|
17
|
+
|
|
18
|
+
Use ScratchpadRead to:
|
|
19
|
+
- Retrieve previously stored content and outputs
|
|
20
|
+
- Access detailed analysis or results from earlier steps
|
|
21
|
+
- Read messages or notes left by other agents
|
|
22
|
+
- Access cached computed data
|
|
23
|
+
- Retrieve content that was too long for direct responses
|
|
24
|
+
|
|
25
|
+
## Best Practices
|
|
26
|
+
|
|
27
|
+
- Any agent can read any scratchpad content
|
|
28
|
+
- Content is returned with line numbers for easy reference
|
|
29
|
+
- Use ScratchpadList first if you don't know what's stored
|
|
30
|
+
- Scratchpad data is temporary and lost when swarm ends
|
|
31
|
+
- For persistent data, use MemoryRead instead
|
|
32
|
+
|
|
33
|
+
## Examples
|
|
34
|
+
|
|
35
|
+
- Read status: file_path='status'
|
|
36
|
+
- Read analysis: file_path='api_analysis'
|
|
37
|
+
- Read agent notes: file_path='notes/backend'
|
|
17
38
|
DESC
|
|
18
39
|
|
|
19
40
|
param :file_path,
|
|
@@ -13,12 +13,29 @@ module SwarmSDK
|
|
|
13
13
|
|
|
14
14
|
description <<~DESC
|
|
15
15
|
Store content in scratchpad for temporary cross-agent communication.
|
|
16
|
-
Use this for quick notes, intermediate results, or coordination messages.
|
|
17
|
-
Any agent can read this content. Data is lost when the swarm ends.
|
|
18
16
|
|
|
19
|
-
|
|
17
|
+
## When to Use Scratchpad
|
|
20
18
|
|
|
21
|
-
|
|
19
|
+
Use ScratchpadWrite to:
|
|
20
|
+
- Store detailed outputs, analysis, or results that are too long for direct responses
|
|
21
|
+
- Share information that would otherwise clutter your responses
|
|
22
|
+
- Store intermediate results during multi-step tasks
|
|
23
|
+
- Leave coordination messages for other agents
|
|
24
|
+
- Cache computed data for quick retrieval
|
|
25
|
+
|
|
26
|
+
## Best Practices
|
|
27
|
+
|
|
28
|
+
- Choose simple, descriptive paths: 'status', 'result', 'notes/agent_x'
|
|
29
|
+
- Use hierarchical paths for organization: 'analysis/step1', 'analysis/step2'
|
|
30
|
+
- Keep entries focused - one piece of information per entry
|
|
31
|
+
- Any agent can read scratchpad content
|
|
32
|
+
- Data is lost when the swarm ends (use MemoryWrite for persistent storage)
|
|
33
|
+
- Maximum 1MB per entry
|
|
34
|
+
|
|
35
|
+
## Examples
|
|
36
|
+
|
|
37
|
+
Good paths: 'status', 'api_analysis', 'test_results', 'notes/backend'
|
|
38
|
+
Bad paths: 'scratch/temp/file123.txt', 'output.log'
|
|
22
39
|
DESC
|
|
23
40
|
|
|
24
41
|
param :file_path,
|
|
@@ -14,11 +14,11 @@ module SwarmSDK
|
|
|
14
14
|
# - Search capabilities: Glob patterns and grep-style content search
|
|
15
15
|
# - Thread-safe: Mutex-protected operations
|
|
16
16
|
class Storage
|
|
17
|
-
# Maximum size per entry (
|
|
18
|
-
MAX_ENTRY_SIZE =
|
|
17
|
+
# Maximum size per entry (3MB)
|
|
18
|
+
MAX_ENTRY_SIZE = 3_000_000
|
|
19
19
|
|
|
20
|
-
# Maximum total storage size (
|
|
21
|
-
MAX_TOTAL_SIZE =
|
|
20
|
+
# Maximum total storage size (100GB)
|
|
21
|
+
MAX_TOTAL_SIZE = 100_000_000_000
|
|
22
22
|
|
|
23
23
|
# Represents a single storage entry with metadata
|
|
24
24
|
Entry = Struct.new(:content, :title, :updated_at, :size, keyword_init: true)
|
|
@@ -82,7 +82,10 @@ module SwarmSDK
|
|
|
82
82
|
required: true
|
|
83
83
|
|
|
84
84
|
def execute(**kwargs)
|
|
85
|
-
|
|
85
|
+
<<~RESP
|
|
86
|
+
Thought noted.
|
|
87
|
+
RESP
|
|
88
|
+
# <system-reminder>The user cannot see your thoughts. You MUST NOT stop without giving the user a response.</system-reminder>
|
|
86
89
|
end
|
|
87
90
|
|
|
88
91
|
private
|
|
@@ -8,17 +8,17 @@ module SwarmSDK
|
|
|
8
8
|
# Each agent maintains its own independent todo list.
|
|
9
9
|
class TodoWrite < RubyLLM::Tool
|
|
10
10
|
description <<~DESC
|
|
11
|
-
Use this tool to create and manage a structured task list for your current
|
|
11
|
+
Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
|
|
12
12
|
It also helps the user understand the progress of the task and overall progress of their requests.
|
|
13
13
|
|
|
14
14
|
## When to Use This Tool
|
|
15
15
|
Use this tool proactively in these scenarios:
|
|
16
16
|
|
|
17
17
|
**CRITICAL**: Follow this workflow for multi-step tasks:
|
|
18
|
-
1. FIRST: Analyze the task scope (
|
|
19
|
-
2. SECOND: Create a COMPLETE todo list with ALL known tasks BEFORE starting
|
|
18
|
+
1. FIRST: Analyze the task scope (gather information, understand requirements)
|
|
19
|
+
2. SECOND: Create a COMPLETE todo list with ALL known tasks BEFORE starting work
|
|
20
20
|
3. THIRD: Execute tasks, marking in_progress → completed as you work
|
|
21
|
-
4. ONLY add new todos if unexpected work is discovered during
|
|
21
|
+
4. ONLY add new todos if unexpected work is discovered during execution
|
|
22
22
|
|
|
23
23
|
Use the todo list when:
|
|
24
24
|
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
|
|
@@ -27,7 +27,7 @@ module SwarmSDK
|
|
|
27
27
|
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
|
|
28
28
|
5. After receiving new instructions - After analyzing scope, create complete todo list before starting work
|
|
29
29
|
6. When you start working on a task - Mark it as in_progress BEFORE beginning work. Ideally you should only have one todo as in_progress at a time
|
|
30
|
-
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during
|
|
30
|
+
7. After completing a task - Mark it as completed and add any new follow-up tasks discovered during execution
|
|
31
31
|
|
|
32
32
|
## When NOT to Use This Tool
|
|
33
33
|
|
|
@@ -73,9 +73,21 @@ module SwarmSDK
|
|
|
73
73
|
- Create specific, actionable items
|
|
74
74
|
- Break complex tasks into smaller, manageable steps
|
|
75
75
|
- Use clear, descriptive task names
|
|
76
|
-
- Always provide both forms
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
- Always provide both forms (content and activeForm)
|
|
77
|
+
|
|
78
|
+
## Examples
|
|
79
|
+
|
|
80
|
+
**Coding Tasks**:
|
|
81
|
+
- content: "Fix authentication bug in login handler"
|
|
82
|
+
- activeForm: "Fixing authentication bug in login handler"
|
|
83
|
+
|
|
84
|
+
**Non-Coding Tasks**:
|
|
85
|
+
- content: "Analyze customer feedback from Q4 survey"
|
|
86
|
+
- activeForm: "Analyzing customer feedback from Q4 survey"
|
|
87
|
+
|
|
88
|
+
**Research Tasks**:
|
|
89
|
+
- content: "Research best practices for API rate limiting"
|
|
90
|
+
- activeForm: "Researching best practices for API rate limiting"
|
|
79
91
|
|
|
80
92
|
When in doubt, use this tool. Being proactive with task management demonstrates attentiveness and ensures you complete all requirements successfully.
|
|
81
93
|
DESC
|
data/lib/swarm_sdk/version.rb
CHANGED