Class: Ask::Agent::MemorySearch

Inherits:
Tool
  • Object
show all
Defined in:
lib/ask/agent/memory_search.rb

Overview

Tool that searches the session's durable memory (Memory). Injected into the session by Session.new(memory: memory).

Instance Method Summary collapse

Constructor Details

#initialize(memory:) ⇒ MemorySearch

Returns a new instance of MemorySearch.

Parameters:



19
20
21
22
# File 'lib/ask/agent/memory_search.rb', line 19

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

Instance Method Details

#execute(query:, limit: 5) ⇒ Object



24
25
26
27
28
29
# File 'lib/ask/agent/memory_search.rb', line 24

def execute(query:, limit: 5)
  hits = @memory.search(query, limit: limit)
  return Ask::Result.ok(data: "(no matching memories)") if hits.empty?

  Ask::Result.ok(data: hits.map { |e| "- #{e.content}" }.join("\n"))
end