Class: SwarmMemory::Tools::MemoryGlob

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

500

Instance Method Summary collapse

Constructor Details

#initialize(storage:) ⇒ MemoryGlob

Initialize with storage instance

Parameters:



108
109
110
111
# File 'lib/swarm_memory/tools/memory_glob.rb', line 108

def initialize(storage:)
  super()
  @storage = storage
end

Instance Method Details

#execute(pattern:) ⇒ String

Execute the tool

Parameters:

  • pattern (String)

    Glob pattern to match

Returns:

  • (String)

    Formatted list of matching entries



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
151
152
153
154
155
156
157
158
159
160
# File 'lib/swarm_memory/tools/memory_glob.rb', line 122

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 += <<~REMINDER

      <system-reminder>
      Results limited to first #{MAX_RESULTS} matches (sorted by most recently modified).
      Consider using a more specific pattern to narrow your search.
      </system-reminder>
    REMINDER
  end

  output
rescue ArgumentError => e
  validation_error(e.message)
end

#nameObject

Override name to return simple "MemoryGlob"



114
115
116
# File 'lib/swarm_memory/tools/memory_glob.rb', line 114

def name
  "MemoryGlob"
end