Class: SwarmSDK::Tools::Scratchpad::ScratchpadRead

Inherits:
Base
  • Object
show all
Defined in:
lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb

Overview

Tool for reading content from scratchpad storage

Retrieves content stored by any agent using scratchpad_write. All agents in the swarm share the same scratchpad.

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

removable, removable?, #removable?

Constructor Details

#initialize(scratchpad_storage) ⇒ ScratchpadRead

Initialize with scratchpad storage instance



57
58
59
60
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb', line 57

def initialize(scratchpad_storage)
  super() # Call RubyLLM::Tool's initialize
  @scratchpad_storage = scratchpad_storage
end

Class Method Details

.create_for_scratchpad(scratchpad_storage) ⇒ ScratchpadRead

Create a ScratchpadRead tool for a specific scratchpad storage instance



49
50
51
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb', line 49

def create_for_scratchpad(scratchpad_storage)
  new(scratchpad_storage)
end

Instance Method Details

#execute(file_path:) ⇒ String

Execute the tool



66
67
68
69
70
71
# File 'lib/swarm_sdk/tools/scratchpad/scratchpad_read.rb', line 66

def execute(file_path:)
  content = scratchpad_storage.read(file_path: file_path)
  format_with_line_numbers(content)
rescue ArgumentError => e
  validation_error(e.message)
end