Class: Rubino::Tools::SessionSearchTool

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

Overview

Full-text search across the agent’s own message history, backed by the ‘messages_fts` FTS5 index. Lets the model recall prior conversations without forcing the user to paste them back in.

Returns a JSON array of match hits with a highlighted snippet so the model can decide whether to follow up with /v1/sessions/:id.

Constant Summary collapse

DEFAULT_LIMIT =
20
MAX_LIMIT =
100

Instance Attribute Summary

Attributes inherited from Base

#cancel_token, #read_tracker, #stream_chunk

Instance Method Summary collapse

Methods inherited from Base

#cancellation_requested?, #config_key, #emit_chunk, #risky?, #to_tool_definition, workspace_root, workspace_roots

Instance Method Details

#call(arguments) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/rubino/tools/session_search_tool.rb', line 65

def call(arguments)
  query = arguments["query"] || arguments[:query]
  return "Error: query is required" if query.nil? || query.to_s.strip.empty?

  limit = (arguments["limit"] || arguments[:limit] || DEFAULT_LIMIT).to_i
  limit = DEFAULT_LIMIT if limit <= 0
  limit = MAX_LIMIT if limit > MAX_LIMIT

  rows = store.search(
    query: query,
    since: arguments["since"] || arguments[:since],
    until_: arguments["until"] || arguments[:until],
    role: arguments["role"] || arguments[:role],
    tool: arguments["tool"] || arguments[:tool],
    limit: limit
  )

  results = rows.map do |row|
    {
      session_id: row[:session_id],
      run_id: row[:run_id],
      message_id: row[:message_id],
      role: row[:role],
      snippet: row[:snippet],
      created_at: row[:created_at]
    }
  end

  JSON.generate(results)
end

#descriptionObject



21
22
23
24
25
# File 'lib/rubino/tools/session_search_tool.rb', line 21

def description
  "Full-text search across past session messages. " \
    "Returns matched messages with highlighted snippets and the owning session id. " \
    "Use to recall earlier conversations or look up what a tool returned previously."
end

#input_schemaObject



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/rubino/tools/session_search_tool.rb', line 27

def input_schema
  {
    type: "object",
    properties: {
      query: {
        type: "string",
        description: "Free-text search query (FTS5 MATCH)."
      },
      since: {
        type: "string",
        description: "ISO8601 lower bound on message created_at."
      },
      until: {
        type: "string",
        description: "ISO8601 upper bound on message created_at."
      },
      role: {
        type: "string",
        enum: %w[user assistant tool],
        description: "Restrict to a single message role."
      },
      tool: {
        type: "string",
        description: "Restrict to a specific tool_name (when role=tool)."
      },
      limit: {
        type: "integer",
        description: "Max results to return (default 20, max 100)."
      }
    },
    required: %w[query]
  }
end

#nameObject



17
18
19
# File 'lib/rubino/tools/session_search_tool.rb', line 17

def name
  "session_search"
end

#risk_levelObject



61
62
63
# File 'lib/rubino/tools/session_search_tool.rb', line 61

def risk_level
  :low
end