Class: SwarmMemory::Tools::MemoryGrep
- Inherits:
-
RubyLLM::Tool
- Object
- RubyLLM::Tool
- SwarmMemory::Tools::MemoryGrep
- 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
-
#execute(pattern:, path: nil, case_insensitive: false, output_mode: "files_with_matches") ⇒ String
Execute the tool.
-
#initialize(storage:) ⇒ MemoryGrep
constructor
Initialize with storage instance.
-
#name ⇒ Object
Override name to return simple "MemoryGrep".
Constructor Details
#initialize(storage:) ⇒ MemoryGrep
Initialize with storage instance
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
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.) rescue RegexpError => e validation_error("Invalid regex pattern: #{e.}") end |
#name ⇒ Object
Override name to return simple "MemoryGrep"
137 138 139 |
# File 'lib/swarm_memory/tools/memory_grep.rb', line 137 def name "MemoryGrep" end |