Skip to content

Integrate memory system into Ghost #239

@theantichris

Description

@theantichris

Summary

Wire the memory storage engine and tools into Ghost's config, registry, and command flow. After this issue, memory is fully functional in both single-shot and chat modes.

Details

Memory is core to Ghost — always on, not a feature flag. The embedding model is a required config value (like the chat model). Configuration is via config file and env vars only, no CLI flags.

Modified files:

cmd/config.go

  • Add config bindings (config file + env vars only, no CLI flags):
    • memory.embedding-modelrequired (like model)
    • memory.dir — optional, default ~/.config/ghost/memory
  • Validation: if memory.embedding-model is empty, return error
  • New error: ErrNoEmbeddingModel = errors.New("memory cortex requires an embedding model (set via config file or GHOST_MEMORY*EMBEDDING_MODEL environment)")
  • Env vars: GHOST_MEMORY*EMBEDDING_MODEL, GHOST_MEMORY*DIR

cmd/memory.go (new)

  • Shared helper: initMemoryStore(ollamaURL string, logger *log.Logger) (*memory.Store, error)
  • Reads memory.embedding-model and memory.dir from viper
  • Creates EmbedFunc closure wrapping llm.Embed()
  • Returns initialized *memory.Store

internal/agent/prompt.go

  • Add MemoryPrompt constant with instructions for using memory tools
  • Add FullSystemPrompt that combines base SystemPrompt + MemoryPrompt

internal/tool/registry.go

  • Update NewRegistry signature to accept memoryStore *memory.Store
  • Always register MemorySearch and MemorySave tools

internal/tool/registry_test.go

  • Update existing NewRegistry calls for new parameter
  • Add test for memory tool registration

cmd/root.go

  • In run(): call initMemoryStore(), use agent.FullSystemPrompt, pass store to NewRegistry()
  • defer memoryStore.Close()
  • No new CLI flags

cmd/chat.go

  • In runChat(): same wiring — initMemoryStore(), agent.FullSystemPrompt for config.System, store to NewRegistry()
  • defer memoryStore.Close()

Config example:

# ~/.config/ghost/config.toml
model = "qwen3:8b"

[memory]
embedding-model = "nomic-embed-text"  # required
# dir = "/custom/path"               # optional

Dependencies

Acceptance Criteria

  • Ghost requires memory.embedding-model in config (clear error if missing)
  • Memory store initializes on startup in both root and chat commands
  • Memory tools registered in tool registry
  • System prompt includes memory usage instructions
  • ghost "Remember my favorite color is blue" → saves to daily log
  • ghost "What's my favorite color?" → searches memory and recalls
  • ghost chat → memory works across chat turns
  • All existing tests updated and passing
  • go test ./... passes

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