Class MemorySearchTool

ITool implementation that searches the agent's memory traces using FTS5.

Usage:

const tool = new MemorySearchTool(brain);
const result = await tool.execute(
{ query: 'dark mode preference', scope: 'user', limit: 5 },
context,
);
// result.output.results → [{ id, content, type, scope, strength, tags }, ...]

Implements

  • ITool<MemorySearchInput, MemorySearchOutput>

Constructors

Methods

  • Run a full-text search against memory_traces_fts and join back to memory_traces for metadata.

    The SQL pattern:

    SELECT mt.id, mt.content, mt.type, mt.scope, mt.strength, mt.tags
    FROM memory_traces_fts fts
    JOIN memory_traces mt ON mt.rowid = fts.rowid
    WHERE fts.memory_traces_fts MATCH ?
    AND mt.deleted = 0
    [AND mt.type = ?] -- when type filter provided
    [AND mt.scope = ?] -- when scope filter provided
    ORDER BY rank -- FTS5 BM25 relevance (lower = more relevant)
    LIMIT ?

    Tags are stored as JSON arrays; they are parsed and returned as string[]. Malformed tag JSON returns an empty array rather than throwing.

    Parameters

    • args: MemorySearchInput

      Search input (query, optional type/scope/limit).

    • context: ToolExecutionContext

      Tool execution context used to resolve scoped searches.

    Returns Promise<ToolExecutionResult<MemorySearchOutput>>

    { results } array on success, or an error result.

Properties

id: "memory-search-v1" = 'memory-search-v1'

Globally unique tool identifier.

name: "memory_search" = 'memory_search'

LLM-facing tool name.

displayName: "Search Memory" = 'Search Memory'

Human-readable display name.

description: string = ...

LLM-facing description.

category: "memory" = 'memory'

Logical category for discovery and grouping.

hasSideEffects: false = false

This tool only reads from the database — no side effects.

inputSchema: JSONSchemaObject = ...

JSON schema for input validation and LLM tool-call construction.