Class: SwarmMemory::Tools::MemoryGrep

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/swarm_memory/tools/memory_grep.rb

Overview

Tool for searching memory content by pattern

Searches content stored in memory entries using regex patterns. Each agent has its own isolated memory storage.

Instance Method Summary collapse

Constructor Details

#initialize(storage:) ⇒ MemoryGrep

Initialize with storage instance

Parameters:



131
132
133
134
# File 'lib/swarm_memory/tools/memory_grep.rb', line 131

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

Instance Method Details

#execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches") ⇒ String

Execute the tool

Parameters:

  • pattern (String)

    Regex pattern to search for

  • path (String, nil) (defaults to: nil)

    Optional path filter

  • case_insensitive (Boolean) (defaults to: false)

    Whether to perform case-insensitive search

  • output_mode (String) (defaults to: "files_with_matches")

    Output mode

Returns:

  • (String)

    Formatted search results



148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'lib/swarm_memory/tools/memory_grep.rb', line 148

def execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches")
  results = @storage.grep(
    pattern: pattern,
    path: path,
    case_insensitive: case_insensitive,
    output_mode: output_mode,
  )

  format_results(results, pattern, output_mode, path)
rescue ArgumentError => e
  validation_error(e.message)
rescue RegexpError => e
  validation_error("Invalid regex pattern: #{e.message}")
end

#nameObject

Override name to return simple "MemoryGrep"



137
138
139
# File 'lib/swarm_memory/tools/memory_grep.rb', line 137

def name
  "MemoryGrep"
end