memory

package
v1.3.24 Latest Latest
Warning

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

Go to latest
Published: Mar 29, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package memory defines interfaces and types for agentic memory — cross-session knowledge that persists beyond a single conversation.

PromptKit defines interfaces and an in-memory test store. Production implementations (vector search, graph retrieval, compliance) are provided by platform layers like Omnia.

Index

Constants

View Source
const (
	RecallToolName   = "memory__recall"
	RememberToolName = "memory__remember"
	ListToolName     = "memory__list"
	ForgetToolName   = "memory__forget"
)

Tool names in the memory namespace.

View Source
const ExecutorMode = "memory"

ExecutorMode is the executor name for Mode-based routing.

Variables

This section is empty.

Functions

func RegisterMemoryTools

func RegisterMemoryTools(registry *tools.Registry)

RegisterMemoryTools registers the four base memory tools with executor routing.

Types

type Executor

type Executor struct {
	// contains filtered or unexported fields
}

Executor implements tools.Executor for all memory tools. It routes by tool name to the appropriate Store method.

func NewExecutor

func NewExecutor(store Store, scope map[string]string) *Executor

NewExecutor creates a Executor for the given store and scope.

func (*Executor) Execute

func (e *Executor) Execute(
	ctx context.Context, desc *tools.ToolDescriptor, args json.RawMessage,
) (json.RawMessage, error)

Execute implements tools.Executor. Routes by tool name.

func (*Executor) Name

func (e *Executor) Name() string

Name implements tools.Executor.

type Extractor

type Extractor interface {
	Extract(ctx context.Context, scope map[string]string, messages []types.Message) ([]*Memory, error)
}

Extractor derives memories from conversation messages. PromptKit defines the interface only. Implementations are provided by platform layers (Omnia) or SDK examples.

type InMemoryStore

type InMemoryStore struct {
	// contains filtered or unexported fields
}

InMemoryStore is a test/development memory store. Substring matching for retrieval, no vector search. Not for production use.

func NewInMemoryStore

func NewInMemoryStore() *InMemoryStore

NewInMemoryStore creates a new in-memory store.

func (*InMemoryStore) Delete

func (s *InMemoryStore) Delete(_ context.Context, scope map[string]string, memoryID string) error

Delete removes a specific memory by ID.

func (*InMemoryStore) DeleteAll

func (s *InMemoryStore) DeleteAll(_ context.Context, scope map[string]string) error

DeleteAll removes all memories for a scope.

func (*InMemoryStore) List

func (s *InMemoryStore) List(
	_ context.Context, scope map[string]string, opts ListOptions,
) ([]*Memory, error)

List returns memories matching the scope and filters.

func (*InMemoryStore) Retrieve

func (s *InMemoryStore) Retrieve(
	_ context.Context, scope map[string]string, query string, opts RetrieveOptions,
) ([]*Memory, error)

Retrieve searches memories by substring matching on content.

func (*InMemoryStore) Save

func (s *InMemoryStore) Save(_ context.Context, m *Memory) error

Save stores a memory. Generates an ID if empty.

type ListOptions

type ListOptions struct {
	Types  []string
	Limit  int
	Offset int
}

ListOptions configures a memory list query.

type Memory

type Memory struct {
	ID         string            `json:"id"`
	Type       string            `json:"type"`               // Free-form: "preference", "episodic", "code_symbol", etc.
	Content    string            `json:"content"`            // Natural language summary
	Metadata   map[string]any    `json:"metadata,omitempty"` // Structured data, store-specific extensions
	Confidence float64           `json:"confidence"`         // 0.0-1.0
	Scope      map[string]string `json:"scope"`              // Scoping keys: {"user_id": "x", "workspace_id": "y"}
	SessionID  string            `json:"session_id,omitempty"`
	TurnRange  [2]int            `json:"turn_range,omitempty"`
	CreatedAt  time.Time         `json:"created_at"`
	AccessedAt time.Time         `json:"accessed_at"`
	ExpiresAt  *time.Time        `json:"expires_at,omitempty"`
}

Memory represents a single memory unit. Deliberately thin — domain-specific concerns (purpose, trust model, sensitivity) belong in the store implementation, not the type.

type RetrieveOptions

type RetrieveOptions struct {
	Types         []string // Filter by memory type (empty = all)
	Limit         int      // Max results (0 = store default)
	MinConfidence float64  // Minimum confidence threshold (0 = no filter)
}

RetrieveOptions configures a memory retrieval query.

type Retriever

type Retriever interface {
	RetrieveContext(ctx context.Context, scope map[string]string, messages []types.Message) ([]*Memory, error)
}

Retriever finds relevant memories given conversation context. Used by the retrieval pipeline stage for automatic RAG injection. Different from Store.Retrieve() which is tool-facing (specific query). Retriever sees the full conversation context and decides what's relevant.

type Store

type Store interface {
	Save(ctx context.Context, memory *Memory) error
	Retrieve(ctx context.Context, scope map[string]string, query string, opts RetrieveOptions) ([]*Memory, error)
	List(ctx context.Context, scope map[string]string, opts ListOptions) ([]*Memory, error)
	Delete(ctx context.Context, scope map[string]string, memoryID string) error
	DeleteAll(ctx context.Context, scope map[string]string) error
}

Store is the core memory persistence interface.

type ToolProvider

type ToolProvider interface {
	RegisterTools(registry *tools.Registry)
}

ToolProvider is optionally implemented by stores that want to register additional tools beyond the base recall/remember/list/forget. Custom tools are registered in the "memory" namespace.

Jump to

Keyboard shortcuts

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