Class: SwarmMemory::Tools::MemoryGlob
- Inherits:
-
SwarmSDK::Tools::Base
- Object
- SwarmSDK::Tools::Base
- SwarmMemory::Tools::MemoryGlob
- Defined in:
- lib/swarm_memory/tools/memory_glob.rb
Overview
Tool for searching memory entries by glob pattern
Finds memory entries matching a glob pattern (like filesystem glob). Each agent has its own isolated memory storage.
Constant Summary collapse
- MAX_RESULTS =
Limit results to prevent overwhelming output
50
Instance Method Summary collapse
-
#execute(pattern:) ⇒ String
Execute the tool.
-
#initialize(storage:) ⇒ MemoryGlob
constructor
Initialize with storage instance.
-
#name ⇒ Object
Override name to return simple "MemoryGlob".
Constructor Details
#initialize(storage:) ⇒ MemoryGlob
Initialize with storage instance
98 99 100 101 |
# File 'lib/swarm_memory/tools/memory_glob.rb', line 98 def initialize(storage:) super() @storage = storage end |
Instance Method Details
#execute(pattern:) ⇒ String
Execute the tool
112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/swarm_memory/tools/memory_glob.rb', line 112 def execute(pattern:) entries = @storage.glob(pattern: pattern) if entries.empty? return "No entries found matching pattern '#{pattern}'" end # Limit results if entries.count > MAX_RESULTS entries = entries.take(MAX_RESULTS) truncated = true else truncated = false end result = [] result << "Memory entries matching '#{pattern}' (#{entries.size} #{entries.size == 1 ? "entry" : "entries"}):" entries.each do |entry| result << "- memory://#{entry[:path]} \"#{entry[:title]}\" (#{format_bytes(entry[:size])})" end output = result.join("\n") # Add system reminder if truncated if truncated output += "\n <system-reminder>\n Results limited to first \#{MAX_RESULTS} matches (sorted by most recently modified).\n Consider using a more specific pattern to narrow your search.\n </system-reminder>\n REMINDER\n end\n\n output\nrescue ArgumentError => e\n validation_error(e.message)\nend\n" |
#name ⇒ Object
Override name to return simple "MemoryGlob"
104 105 106 |
# File 'lib/swarm_memory/tools/memory_glob.rb', line 104 def name "MemoryGlob" end |