Class: SwarmSDK::Tools::Scratchpad::ScratchpadWrite
- Defined in:
- lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb
Overview
Tool for writing content to scratchpad storage
Stores content in volatile, shared storage for temporary communication. All agents in the swarm share the same scratchpad. Data is lost when the process ends (not persisted).
Class Method Summary collapse
-
.create_for_scratchpad(scratchpad_storage) ⇒ ScratchpadWrite
Create a ScratchpadWrite tool for a specific scratchpad storage instance.
Instance Method Summary collapse
-
#execute(file_path:, content:, title:) ⇒ String
Execute the tool.
-
#initialize(scratchpad_storage) ⇒ ScratchpadWrite
constructor
Initialize with scratchpad storage instance.
Methods inherited from Base
removable, removable?, #removable?
Constructor Details
#initialize(scratchpad_storage) ⇒ ScratchpadWrite
Initialize with scratchpad storage instance
66 67 68 69 |
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb', line 66 def initialize(scratchpad_storage) super() # Call RubyLLM::Tool's initialize @scratchpad_storage = scratchpad_storage end |
Class Method Details
.create_for_scratchpad(scratchpad_storage) ⇒ ScratchpadWrite
Create a ScratchpadWrite tool for a specific scratchpad storage instance
58 59 60 |
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb', line 58 def create_for_scratchpad(scratchpad_storage) new(scratchpad_storage) end |
Instance Method Details
#execute(file_path:, content:, title:) ⇒ String
Execute the tool
77 78 79 80 81 82 |
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_write.rb', line 77 def execute(file_path:, content:, title:) entry = scratchpad_storage.write(file_path: file_path, content: content, title: title) "Stored at scratchpad://#{file_path} (#{format_bytes(entry.size)})" rescue ArgumentError => e validation_error(e.) end |