Skip to content

Add memory_search tool #238

@theantichris

Description

@theantichris

Summary

Add a memory_search tool that allows the LLM to search Ghost's persistent memory using hybrid retrieval. Follows the same tool.Tool interface pattern as search.go.

Details

New files:

  • internal/tool/memory_search.go
  • internal/tool/memory_search_test.go

Type:

type MemorySearch struct {
    Store *memory.Store
}

Tool definition:

  • Name: memory_search
  • Description: "search your persistent memory for relevant information from past conversations and saved knowledge"
  • Parameters:
    • query (string, required): the search query
    • max_results (integer, optional): maximum results to return (default 5)

Execute:

  • Parse args JSON (same pattern as search.go)
  • Call Store.Search(ctx, query, maxResults)
  • Format results:
    Memory Result 1: [source: daily/2026-02-07.md]
    <chunk content>
    
    Memory Result 2: [source: MEMORY.md]
    <chunk content>
    

Errors:

  • ErrMemorySearchArgs — failed to parse arguments
  • ErrMemorySearchFail — search operation failed

Testing:

  • Table-driven tests following search_test.go pattern
  • Use real memory.Store with temp dir and mock EmbedFunc

Note: This tool is not registered in the registry yet — that happens in the integration issue.

Dependencies

Acceptance Criteria

  • Implements tool.Tool interface (Definition() + Execute())
  • Returns formatted search results with source attribution
  • Defaults to 5 results when max_results not specified
  • Handles empty results gracefully
  • Proper error handling for invalid args and search failures
  • Table-driven tests pass

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    Status

    Backlog

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions