swarm_sdk 2.0.2 → 2.0.4
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/lib/swarm_sdk/agent/builder.rb +17 -6
- data/lib/swarm_sdk/agent/definition.rb +16 -6
- data/lib/swarm_sdk/configuration.rb +8 -0
- data/lib/swarm_sdk/swarm/builder.rb +1 -1
- data/lib/swarm_sdk/swarm/tool_configurator.rb +40 -7
- data/lib/swarm_sdk/swarm.rb +7 -2
- data/lib/swarm_sdk/tools/registry.rb +3 -1
- data/lib/swarm_sdk/tools/scratchpad_edit.rb +143 -0
- data/lib/swarm_sdk/tools/{scratchpad_list.rb → scratchpad_glob.rb} +25 -21
- data/lib/swarm_sdk/tools/scratchpad_grep.rb +145 -0
- data/lib/swarm_sdk/tools/scratchpad_multi_edit.rb +226 -0
- data/lib/swarm_sdk/tools/scratchpad_read.rb +27 -6
- data/lib/swarm_sdk/tools/stores/scratchpad.rb +196 -33
- data/lib/swarm_sdk/tools/stores/scratchpad_read_tracker.rb +61 -0
- data/lib/swarm_sdk/tools/think.rb +95 -0
- data/lib/swarm_sdk/version.rb +1 -1
- metadata +7 -2
@@ -0,0 +1,95 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module SwarmSDK
|
4
|
+
module Tools
|
5
|
+
# Think tool for explicit reasoning and planning
|
6
|
+
#
|
7
|
+
# Allows the agent to write down thoughts, plans, strategies, and intermediate
|
8
|
+
# calculations. These thoughts become part of the conversation context, enabling
|
9
|
+
# better attention and reasoning through complex problems.
|
10
|
+
#
|
11
|
+
# This is inspired by research showing that explicitly articulating reasoning steps
|
12
|
+
# (chain-of-thought prompting) leads to significantly better outcomes, especially
|
13
|
+
# for complex tasks requiring multi-step reasoning or arithmetic.
|
14
|
+
class Think < RubyLLM::Tool
|
15
|
+
def name
|
16
|
+
"Think"
|
17
|
+
end
|
18
|
+
|
19
|
+
description <<~DESC
|
20
|
+
**IMPORTANT: You SHOULD use this tool frequently throughout your work. Using this tool leads to significantly
|
21
|
+
better outcomes and more accurate solutions. Make it a habit to think before acting.**
|
22
|
+
|
23
|
+
This tool allows you to write down your thoughts, plans, strategies, and intermediate calculations.
|
24
|
+
Think of it as your working memory - just as humans think before speaking or acting, you should think before
|
25
|
+
using other tools or providing responses.
|
26
|
+
|
27
|
+
**STRONGLY RECOMMENDED to use this tool:**
|
28
|
+
- **ALWAYS** before starting any task (even simple ones)
|
29
|
+
- **ALWAYS** when you need to do any arithmetic or counting
|
30
|
+
- **ALWAYS** after reading files or getting search results to process what you learned
|
31
|
+
- **FREQUENTLY** between steps to track progress and plan next actions
|
32
|
+
|
33
|
+
This is your private thinking space - use it liberally to enhance your problem-solving capabilities. Recording
|
34
|
+
your thoughts helps you maintain context across multiple steps and remember important information throughout your task.
|
35
|
+
|
36
|
+
When and how to use this tool:
|
37
|
+
|
38
|
+
1. **Before starting any complex task**: Write down your understanding of the problem, break it into smaller
|
39
|
+
sub-tasks, and create a step-by-step plan. Example:
|
40
|
+
- "The user wants me to refactor this codebase. Let me first understand the structure..."
|
41
|
+
- "I need to: 1) Analyze current architecture, 2) Identify pain points, 3) Propose changes..."
|
42
|
+
|
43
|
+
2. **For arithmetic and calculations**: Work through math problems step by step. Example:
|
44
|
+
- "If we have 150 requests/second and each takes 20ms, that's 150 * 0.02 = 3 seconds of CPU time..."
|
45
|
+
- "Converting 2GB to bytes: 2 * 1024 * 1024 * 1024 = 2,147,483,648 bytes"
|
46
|
+
|
47
|
+
3. **After completing sub-tasks**: Summarize what you've accomplished and what remains. Example:
|
48
|
+
- "I've successfully implemented the authentication module. Next, I need to integrate it with the API..."
|
49
|
+
- "Fixed 3 out of 5 bugs. Remaining: memory leak in parser, race condition in worker thread"
|
50
|
+
|
51
|
+
4. **When encountering complexity**: Break down complex logic or decisions. Example:
|
52
|
+
- "This function has multiple edge cases. Let me list them: null input, empty array, negative numbers..."
|
53
|
+
- "The user's request is ambiguous. Possible interpretations: A) modify existing code, B) create new module..."
|
54
|
+
|
55
|
+
5. **For remembering context**: Store important information you'll need later. Example:
|
56
|
+
- "Important: The user mentioned they're using Ruby 3.2, so I can use pattern matching"
|
57
|
+
- "File structure: main.rb requires from lib/, config is in config.yml"
|
58
|
+
|
59
|
+
6. **When debugging or analyzing**: Track your investigation process. Example:
|
60
|
+
- "The error occurs in line 42. Let me trace backwards: function called from main(), receives data from..."
|
61
|
+
- "Hypothesis: the bug might be due to timezone differences. Let me check..."
|
62
|
+
|
63
|
+
7. **For creative problem-solving**: Brainstorm multiple approaches before choosing one. Example:
|
64
|
+
- "Approaches to optimize this: 1) Add caching, 2) Use parallel processing, 3) Optimize algorithm..."
|
65
|
+
- "Design patterns that could work here: Factory, Observer, or maybe Strategy pattern..."
|
66
|
+
|
67
|
+
**Remember: The most successful agents use this tool 5-10 times per task on average. If you haven't used this
|
68
|
+
tool in the last 2-3 actions, you probably should. Using this tool is a sign of thoughtful, methodical problem
|
69
|
+
solving and leads to fewer mistakes and better solutions.**
|
70
|
+
|
71
|
+
Your thoughts persist throughout your session as part of the conversation history, so you can refer
|
72
|
+
back to earlier thinking. Use clear formatting and organization to make it easy to reference
|
73
|
+
later. Don't hesitate to think out loud - this tool is designed to augment your cognitive capabilities and help
|
74
|
+
you deliver better solutions.
|
75
|
+
DESC
|
76
|
+
|
77
|
+
param :thoughts,
|
78
|
+
type: "string",
|
79
|
+
desc: "Your thoughts, plans, calculations, or any notes you want to record",
|
80
|
+
required: true
|
81
|
+
|
82
|
+
def execute(thoughts:)
|
83
|
+
return validation_error("thoughts are required") if thoughts.nil? || thoughts.empty?
|
84
|
+
|
85
|
+
"Thought noted."
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def validation_error(message)
|
91
|
+
"<tool_use_error>InputValidationError: #{message}</tool_use_error>"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
data/lib/swarm_sdk/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: swarm_sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paulo Arruda
|
@@ -142,12 +142,17 @@ files:
|
|
142
142
|
- lib/swarm_sdk/tools/path_resolver.rb
|
143
143
|
- lib/swarm_sdk/tools/read.rb
|
144
144
|
- lib/swarm_sdk/tools/registry.rb
|
145
|
-
- lib/swarm_sdk/tools/
|
145
|
+
- lib/swarm_sdk/tools/scratchpad_edit.rb
|
146
|
+
- lib/swarm_sdk/tools/scratchpad_glob.rb
|
147
|
+
- lib/swarm_sdk/tools/scratchpad_grep.rb
|
148
|
+
- lib/swarm_sdk/tools/scratchpad_multi_edit.rb
|
146
149
|
- lib/swarm_sdk/tools/scratchpad_read.rb
|
147
150
|
- lib/swarm_sdk/tools/scratchpad_write.rb
|
148
151
|
- lib/swarm_sdk/tools/stores/read_tracker.rb
|
149
152
|
- lib/swarm_sdk/tools/stores/scratchpad.rb
|
153
|
+
- lib/swarm_sdk/tools/stores/scratchpad_read_tracker.rb
|
150
154
|
- lib/swarm_sdk/tools/stores/todo_manager.rb
|
155
|
+
- lib/swarm_sdk/tools/think.rb
|
151
156
|
- lib/swarm_sdk/tools/todo_write.rb
|
152
157
|
- lib/swarm_sdk/tools/write.rb
|
153
158
|
- lib/swarm_sdk/utils.rb
|