Class: SwarmMemory::Tools::MemoryRead
- Inherits:
-
SwarmSDK::Tools::Base
- Object
- SwarmSDK::Tools::Base
- SwarmMemory::Tools::MemoryRead
- Includes:
- TitleLookup
- 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".
Methods included from TitleLookup
#format_memory_path_with_title, #lookup_title
Constructor Details
#initialize(storage:, agent_name:) ⇒ MemoryRead
Initialize with storage instance and agent name
55 56 57 58 59 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 55 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
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 70 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) # Return plain text with line numbers result = format_with_line_numbers(entry.content) # Append related memories reminder if present = entry.&.dig("related") || [] result += () if .any? result rescue ArgumentError => e validation_error(e.) end |
#name ⇒ Object
Override name to return simple "MemoryRead"
62 63 64 |
# File 'lib/swarm_memory/tools/memory_read.rb', line 62 def name "MemoryRead" end |