Documentation
¶
Overview ¶
Package memory provides structured, inspectable long-term memory.
Index ¶
- Constants
- func FormatHydration(entries []Entry) string
- func IsMemoryTool(name string) bool
- func ToolDefs() []provider.ToolDef
- func ValidateKind(kind string) error
- type Builtin
- func (b *Builtin) ApplyConsolidation(ctx context.Context, episodeIDs []int64, items []consolidateItem, ...) (int, error)
- func (b *Builtin) Close() error
- func (b *Builtin) Forget(ctx context.Context, id int64) error
- func (b *Builtin) ForgetQuery(ctx context.Context, query string) (int, error)
- func (b *Builtin) Hydrate(ctx context.Context, query string, limit int) ([]Entry, error)
- func (b *Builtin) ListUnconsolidatedEpisodes(ctx context.Context, limit int) ([]Entry, error)
- func (b *Builtin) MarkConsolidated(ctx context.Context, ids []int64) error
- func (b *Builtin) Recall(ctx context.Context, query string, limit int) ([]Entry, error)
- func (b *Builtin) RecordConsolidateFailure(ctx context.Context, ids []int64, maxAttempts int) error
- func (b *Builtin) Store(ctx context.Context, kind, subject, content string) (Entry, error)
- func (b *Builtin) StoreConsolidated(ctx context.Context, kind, subject, content string) (Entry, error)
- func (b *Builtin) Supersede(ctx context.Context, oldID, newID int64) error
- type Composite
- type Consolidator
- type Entry
- type MCPAdapter
- func (a *MCPAdapter) Close() error
- func (a *MCPAdapter) Forget(ctx context.Context, id int64) error
- func (a *MCPAdapter) ForgetQuery(ctx context.Context, query string) (int, error)
- func (a *MCPAdapter) Hydrate(ctx context.Context, query string, limit int) ([]Entry, error)
- func (a *MCPAdapter) Recall(ctx context.Context, query string, limit int) ([]Entry, error)
- func (a *MCPAdapter) Store(ctx context.Context, kind, subject, content string) (Entry, error)
- type MCPCaller
- type Memory
- type ToolRunner
- type Tools
Constants ¶
const ( KindFact = "fact" KindPreference = "preference" KindPerson = "person" KindEpisode = "episode" KindInsight = "insight" )
Kind values for typed memory rows.
const ( SourceChat = "chat" SourceConsolidation = "consolidation" SourceOperator = "operator" )
Source values.
const ( ToolStore = "memory_store" ToolRecall = "memory_recall" ToolForget = "memory_forget" )
Tool names exposed to the model (builtin, not MCP-prefixed).
const PersonaPrecedenceNote = `` /* 373-byte string literal not displayed */
PersonaPrecedenceNote is appended to the system prompt when memory is enabled.
Variables ¶
This section is empty.
Functions ¶
func FormatHydration ¶
FormatHydration renders entries as the compact prompt block.
func IsMemoryTool ¶
IsMemoryTool reports whether name is a builtin memory tool.
Types ¶
type Builtin ¶
type Builtin struct {
// contains filtered or unexported fields
}
Builtin is the SQLite + FTS5 memory backend in gantry.db.
func (*Builtin) ApplyConsolidation ¶ added in v0.1.12
func (b *Builtin) ApplyConsolidation(ctx context.Context, episodeIDs []int64, items []consolidateItem, allowedSupersede map[int64]bool) (int, error)
ApplyConsolidation stores durable rows and marks episodes in one transaction. allowedSupersede restricts supersede targets to the prompted episode batch.
func (*Builtin) ForgetQuery ¶
ForgetQuery deletes FTS matches for query (correctability).
func (*Builtin) ListUnconsolidatedEpisodes ¶
ListUnconsolidatedEpisodes returns episode rows awaiting consolidation.
func (*Builtin) MarkConsolidated ¶
MarkConsolidated marks episode ids as processed by the consolidator.
func (*Builtin) RecordConsolidateFailure ¶ added in v0.1.12
RecordConsolidateFailure bumps attempts; quarantines after maxAttempts.
type Composite ¶
type Composite struct {
Memory Tools
Other ToolRunner
HideMCPServer string // optional: strip {server}__memory_* from Other.Tools()
}
Composite merges builtin memory tools with an optional MCP/other runner. When HideMCPServer is set (mcp memory backend), that server's memory_* tools are omitted from the listing so the model only sees the unprefixed names.
func (Composite) Call ¶
func (c Composite) Call(ctx context.Context, name string, arguments json.RawMessage) (string, error)
Call routes memory_* to the memory backend; everything else to Other.
type Consolidator ¶
type Consolidator struct {
Store *Builtin
Completer provider.Completer
Interval time.Duration
BatchSize int
Logger *slog.Logger
}
Consolidator runs the cheap "sleep cycle" over unconsolidated episodes. Builtin backend only.
func (*Consolidator) Pass ¶
func (c *Consolidator) Pass(ctx context.Context)
Pass runs one consolidation cycle (bounded batch).
func (*Consolidator) Start ¶
func (c *Consolidator) Start(ctx context.Context)
Start runs consolidation passes on Interval until ctx is cancelled. Interval <= 0 means disabled (returns immediately).
type Entry ¶
type Entry struct {
ID int64
Kind string
Subject string
Content string
Source string
Confidence float64
CreatedAt time.Time
UpdatedAt time.Time
ExpiresAt *time.Time
SupersededBy *int64
}
Entry is one structured memory row.
type MCPAdapter ¶
MCPAdapter routes memory tools to an MCP server from the manifest (MEMORY_BACKEND=mcp:<server-name>). Expected remote tools:
{server}__memory_store | {server}__memory_recall | {server}__memory_forget
func NewMCPAdapter ¶
func NewMCPAdapter(caller MCPCaller, server string) (*MCPAdapter, error)
NewMCPAdapter builds an adapter for server name (without mcp: prefix).
func (*MCPAdapter) Close ¶
func (a *MCPAdapter) Close() error
Close is a no-op (MCP host owns the connection).
func (*MCPAdapter) Forget ¶
func (a *MCPAdapter) Forget(ctx context.Context, id int64) error
Forget calls remote memory_forget by id.
func (*MCPAdapter) ForgetQuery ¶
ForgetQuery calls remote memory_forget by query.
type MCPCaller ¶
type MCPCaller interface {
Call(ctx context.Context, toolName string, arguments json.RawMessage) (string, error)
}
MCPCaller is the subset of mcp.Host needed by the memory adapter.
type Memory ¶
type Memory interface {
Store(ctx context.Context, kind, subject, content string) (Entry, error)
Recall(ctx context.Context, query string, limit int) ([]Entry, error)
Forget(ctx context.Context, id int64) error
ForgetQuery(ctx context.Context, query string) (int, error)
Hydrate(ctx context.Context, query string, limit int) ([]Entry, error)
Close() error
}
Memory is the swappable memory backend surface (tools + hydration).