Class: SwarmMemory::Tools::MemoryRead
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SwarmMemory::Tools::MemoryRead
- Defined in:
- lib/swarm_memory/tools/memory_read.rb
Overview
Tool for reading content from memory storage
Retrieves content stored by this agent using memory_write. Each agent has its own isolated memory storage.
Instance Method Summary collapse
-
#execute(file_path:) ⇒ String
Execute the tool.
-
#initialize(storage:, agent_name:) ⇒ MemoryRead
constructor
Initialize with storage instance and agent name.
-
#name ⇒ Object
Override name to return simple "MemoryRead".
Constructor Details
#initialize(storage:, agent_name:) ⇒ MemoryRead
Initialize with storage instance and agent name
51 52 53 54 55 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 51 def initialize(storage:, agent_name:) super() @storage = storage @agent_name = agent_name.to_sym end |
Instance Method Details
#execute(file_path:) ⇒ String
Execute the tool
66 67 68 69 70 71 72 73 74 75 76 77 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 66 def execute(file_path:) # Read full entry with metadata entry = @storage.read_entry(file_path: file_path) # Register this read in the tracker with content digest Core::StorageReadTracker.register_read(@agent_name, file_path, entry.content) # Always return JSON format (metadata always exists - at minimum title) format_as_json(entry) rescue ArgumentError => e validation_error(e.) end |
#name ⇒ Object
Override name to return simple "MemoryRead"
58 59 60 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 58 def name "MemoryRead" end |