Class: Protege::SearchEmailsTool
- Inherits:
-
Tool
- Object
- Tool
- Protege::SearchEmailsTool
- Defined in:
- app/tools/protege/search_emails_tool.rb
Overview
Built-in archive-search tool — the way an agent looks back across its own correspondence beyond
the current thread. Subclasses Protege::Tool, so the harness publishes it in the LLM's tool
catalog (id :search_emails); when the model emits a search_emails call, the harness routes the
arguments to #use.
The search is always scoped to the active persona's own messages (via Persona#messages) — an
agent can never read another persona's mail. A single free-text query is matched, case-insensitively,
against both the participants (from/to/cc) and the content (subject/body); results come back newest
first. Each result carries the message's full body — a truncated body could cut the very text that
matched, so it is returned whole. The caller may cap the result count with limit (default
DEFAULT_LIMIT, hard-capped at MAX_LIMIT); the default is small precisely because bodies are full.
Constant Summary collapse
- DEFAULT_LIMIT =
Result count when the caller does not specify a
limit. Kept small because each result carries the full message body. 5- MAX_LIMIT =
Absolute ceiling on the result count, regardless of the requested
limit. 50- SEARCHABLE_COLUMNS =
Columns scanned by the query: the participant addresses first, then the subject and bodies.
%w[ from_address to_addresses cc_addresses subject text_body html_body ].freeze
Instance Method Summary collapse
-
#use(context:, query:, limit: nil) ⇒ Protege::Result
Search the active persona's archive and return the matching messages as concise summaries.
Instance Method Details
#use(context:, query:, limit: nil) ⇒ Protege::Result
Search the active persona's archive and return the matching messages as concise summaries.
68 69 70 71 72 73 74 |
# File 'app/tools/protege/search_emails_tool.rb', line 68 def use(context:, query:, limit: nil) return failure(reason: 'query cannot be empty') if query.to_s.strip.empty? hits = matches(persona: context.persona, query:, limit:) success(count: hits.size, results: hits.map { result_hash(_1) }) end |