Class: SwarmSDK::Tools::Scratchpad::ScratchpadWrite

Inherits:
Base
  • Object
show all
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

Instance Method Summary collapse

Methods inherited from Base

removable, removable?, #removable?

Constructor Details

#initialize(scratchpad_storage) ⇒ ScratchpadWrite

Initialize with scratchpad storage instance

Parameters:



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

Parameters:

Returns:



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

Parameters:

  • file_path (String)

    Path to store content

  • content (String)

    Content to store

  • title (String)

    Brief title

Returns:

  • (String)

    Success message with path and size



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.message)
end