memory

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package memory — manager.go provides an LLM-powered memory manager inspired by Agno's MemoryManager.

Package memory provides short-term and long-term memory APIs for agents.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Manager

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

Manager uses an LLM to autonomously decide what to remember from conversations.

func NewManager

func NewManager(agentID, userID string, store *Store, provider model.Provider) *Manager

NewManager creates an LLM-powered memory manager. The underlying store is scoped to userID so that all reads and writes are isolated per tenant. An empty userID uses the global/tenantless bucket.

func (*Manager) ExtractMemories

func (m *Manager) ExtractMemories(ctx context.Context, messages []model.Message) error

ExtractMemories uses the LLM to identify memorable facts from messages and stores them.

func (*Manager) GetUserMemories

func (m *Manager) GetUserMemories(ctx context.Context) (string, error)

GetUserMemories returns all long-term memories, formatted for context injection.

func (*Manager) MemoryTools

func (m *Manager) MemoryTools() []MemoryTool

MemoryTools returns tool definitions that let the model manage memory directly (agentic memory).

func (*Manager) OptimizeMemories

func (m *Manager) OptimizeMemories(ctx context.Context) error

OptimizeMemories asks the LLM to compress/deduplicate existing long-term memories.

func (*Manager) UserID added in v0.4.0

func (m *Manager) UserID() string

UserID reports the tenant this manager is scoped to ("" means global).

func (*Manager) WithUserID added in v0.4.0

func (m *Manager) WithUserID(userID string) *Manager

WithUserID returns a copy of the manager scoped to a different tenant, re-scoping the underlying store as well. The original manager is unchanged, so a shared agent-level manager can be safely re-scoped per request.

type MemoryTool

type MemoryTool struct {
	Name        string
	Description string
	Handler     func(ctx context.Context, args map[string]any) (any, error)
}

MemoryTool is a tool definition for agentic memory management.

type Store

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

Store provides a high-level memory API on top of storage.Storage.

Long-term memory is multi-tenant: it is keyed by (agentID, userID) so that different users served by the same agent never observe each other's memories. When userID is empty, long-term memory falls back to a documented global/tenantless bucket.

func NewStore

func NewStore(agentID string, backend storage.Storage) *Store

NewStore creates a memory store for the given agent. The store is scoped to the global/tenantless long-term bucket; use NewStoreForUser or ForUser to scope it to a specific tenant.

func NewStoreForUser added in v0.4.0

func NewStoreForUser(agentID, userID string, backend storage.Storage) *Store

NewStoreForUser creates a memory store scoped to a specific user (tenant). An empty userID selects the global/tenantless long-term bucket.

func (*Store) DeleteLongTerm added in v0.4.0

func (s *Store) DeleteLongTerm(ctx context.Context, key string) error

DeleteLongTerm removes a long-term memory for the store's tenant by key.

func (*Store) ForUser added in v0.4.0

func (s *Store) ForUser(userID string) *Store

ForUser returns a shallow copy of the store scoped to the given user. The original store is left unchanged, so a shared agent-level store can be safely re-scoped per request. An empty userID selects the global/tenantless bucket.

func (*Store) Get

func (s *Store) Get(ctx context.Context, key string) (any, error)

Get retrieves a memory value by logical key. It resolves the tenant-scoped long-term key first and falls back to the raw key for short-term or legacy records.

func (*Store) ListLongTerm

func (s *Store) ListLongTerm(ctx context.Context) ([]*storage.MemoryRecord, error)

ListLongTerm returns the long-term memories that belong to the store's tenant. Records are returned with their logical (un-namespaced) key restored.

func (*Store) ListShortTerm

func (s *Store) ListShortTerm(ctx context.Context) ([]*storage.MemoryRecord, error)

ListShortTerm returns all short-term memories for this agent.

func (*Store) SetLongTerm

func (s *Store) SetLongTerm(ctx context.Context, key string, value any) error

SetLongTerm stores a value in cross-session persistent memory, scoped to the store's tenant (agentID, userID).

func (*Store) SetShortTerm

func (s *Store) SetShortTerm(ctx context.Context, sessionID, key string, value any) error

SetShortTerm stores a value in session-scoped working memory.

func (*Store) UserID added in v0.4.0

func (s *Store) UserID() string

UserID reports the tenant this store is scoped to ("" means global).

Jump to

Keyboard shortcuts

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