memory

package
v0.4.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 4, 2026 License: AGPL-3.0, Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package memory gives the agent persistent, file-backed long-term memory. Each memory is a markdown file with YAML frontmatter (name / description / type) in a memory directory; a MEMORY.md index lists them. The agent recalls memories relevant to a query and records new ones via tools, and relevant memories can be auto-injected into the conversation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Age

func Age(m Memory, now time.Time) string

Age renders a human age like "today" / "yesterday" / "5 days ago".

func RecallTool

func RecallTool(s *Store) tool.CoreTool

RecallTool lets the agent read memories relevant to a query.

func RecordTool

func RecordTool(s *Store) tool.CoreTool

RecordTool lets the agent persist a durable fact to memory.

func RenderForInjection

func RenderForInjection(mems []Memory, now time.Time) string

RenderForInjection formats memories as context to inject before a user turn.

func Tools

func Tools(s *Store) []tool.CoreTool

Tools returns the RecallMemory and RecordMemory tools bound to a store.

Types

type Memory

type Memory struct {
	Name        string
	Description string
	Type        Type
	Content     string
	Path        string
	ModTime     time.Time
}

Memory is a single stored fact.

type Store

type Store struct {
	Dir string
}

Store is a memory directory.

func NewStore

func NewStore(dir string) *Store

NewStore roots a store at dir (created on first write).

func (*Store) Index

func (s *Store) Index() string

Index returns the MEMORY.md content (an index of memories), building it from a scan if the file is absent.

func (*Store) Read

func (s *Store) Read(name string) (Memory, error)

Read returns the memory with the given name (or its slug).

func (*Store) Relevant

func (s *Store) Relevant(query string, max int) []Memory

Relevant returns up to max memories scored against the query (keyword match on name/description/content), most relevant first, recency breaking ties.

func (*Store) Save

func (s *Store) Save(m Memory) error

Save writes a memory file and rebuilds the MEMORY.md index.

func (*Store) Scan

func (s *Store) Scan() ([]Memory, error)

Scan reads every memory file (excluding the index), newest first.

func (*Store) SystemSegment

func (s *Store) SystemSegment() string

SystemSegment renders the memory index for inclusion in the system prompt so the agent knows what it remembers and can RecallMemory for details.

type Type

type Type string

Type classifies a memory.

const (
	TypeUser      Type = "user"      // facts about the user (role, preferences)
	TypeFeedback  Type = "feedback"  // guidance on how the agent should work
	TypeProject   Type = "project"   // ongoing work, goals, constraints
	TypeReference Type = "reference" // pointers to external resources
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL