Class: Tools::SearchMessages

Inherits:
Base
  • Object
show all
Defined in:
lib/tools/search_messages.rb

Overview

Keyword search across long-term memory — every message Anima has ever seen, across every session, except what the agent is already looking at right now. Results sit below her current viewport; anything still in front of her is excluded, so every slot the search returns is new information.

Two-step memory workflow:

1. `search_messages(query: "auth flow")` → discovers relevant messages
2. `view_messages(message_id: 42)` → fractal zoom into full context

Same FTS5 engine Mneme uses for passive recall — this variant fires on demand when Aoide reaches for a memory herself.

Examples:

search_messages(query: "authentication flow")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

prompt_guidelines, prompt_snippet, schema, truncation_threshold

Constructor Details

#initialize(session:) ⇒ SearchMessages

Returns a new instance of SearchMessages.

Parameters:

  • session (Session)

    the calling session — drives viewport exclusion



35
36
37
# File 'lib/tools/search_messages.rb', line 35

def initialize(session:, **)
  @session = session
end

Class Method Details

.descriptionObject



22
# File 'lib/tools/search_messages.rb', line 22

def self.description = "Search long-term memory (past conversations outside your current viewport) by keyword. Returns ranked message snippets with IDs — pass any ID to view_messages to see the full context around it."

.input_schemaObject



24
25
26
27
28
29
30
31
32
# File 'lib/tools/search_messages.rb', line 24

def self.input_schema
  {
    type: "object",
    properties: {
      query: {type: "string"}
    },
    required: ["query"]
  }
end

.tool_nameObject



20
# File 'lib/tools/search_messages.rb', line 20

def self.tool_name = "search_messages"

Instance Method Details

#execute(input) ⇒ String, Hash

Parameters:

  • input (Hash)

    with “query”

Returns:

  • (String)

    formatted search results with message IDs

  • (Hash)

    with :error key when query is blank



42
43
44
45
46
47
48
49
50
51
# File 'lib/tools/search_messages.rb', line 42

def execute(input)
  query = input["query"].to_s.strip
  return {error: "Query cannot be blank"} if query.empty?

  results = Mneme::Search.query(query, caller_session: @session)

  return "No results found for \"#{query}\"." if results.empty?

  format_results(query, results)
end