Class MemoryMergeTool

ITool implementation that merges multiple memory traces into one.

Usage:

const tool = new MemoryMergeTool(brain);
const result = await tool.execute(
{
traceIds: ['mt_1_0', 'mt_2_0', 'mt_3_0'],
mergedContent: 'Consolidated insight from three related observations.',
},
context,
);
// result.output → { survivorId: 'mt_1_0', deletedIds: ['mt_2_0', 'mt_3_0'] }

Implements

  • ITool<MemoryMergeInput, MemoryMergeOutput>

Constructors

Methods

  • Merge the specified traces into one survivor.

    Steps:

    1. Validate that at least 2 trace IDs were supplied.
    2. Load all matching, non-deleted traces from the database.
    3. Pick survivor by highest retrieval_count; fallback to first found.
    4. Compute merged content (provided or concatenated).
    5. Union all tags, deduplicate.
    6. Update survivor: new content, cleared embedding, unioned tags.
    7. Soft-delete all non-survivor traces.

    Parameters

    • args: MemoryMergeInput

      Merge input (traceIds, optional mergedContent).

    • _context: ToolExecutionContext

      Tool execution context (not used by this tool).

    Returns Promise<ToolExecutionResult<MemoryMergeOutput>>

    { survivorId, deletedIds } on success, or an error result.

Properties

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

Globally unique tool identifier.

name: "memory_merge" = 'memory_merge'

LLM-facing tool name.

displayName: "Merge Memories" = 'Merge Memories'

Human-readable display name.

description: string = ...

LLM-facing description.

category: "memory" = 'memory'

Logical category for discovery and grouping.

hasSideEffects: true = true

This tool writes to the database.

inputSchema: JSONSchemaObject = ...

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