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 ¶
- type Manager
- func (m *Manager) ExtractMemories(ctx context.Context, messages []model.Message) error
- func (m *Manager) GetUserMemories(ctx context.Context) (string, error)
- func (m *Manager) MemoryTools() []MemoryTool
- func (m *Manager) OptimizeMemories(ctx context.Context) error
- func (m *Manager) UserID() string
- func (m *Manager) WithUserID(userID string) *Manager
- type MemoryTool
- type Store
- func (s *Store) DeleteLongTerm(ctx context.Context, key string) error
- func (s *Store) ForUser(userID string) *Store
- func (s *Store) Get(ctx context.Context, key string) (any, error)
- func (s *Store) ListLongTerm(ctx context.Context) ([]*storage.MemoryRecord, error)
- func (s *Store) ListShortTerm(ctx context.Context) ([]*storage.MemoryRecord, error)
- func (s *Store) SetLongTerm(ctx context.Context, key string, value any) error
- func (s *Store) SetShortTerm(ctx context.Context, sessionID, key string, value any) error
- func (s *Store) UserID() string
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 ¶
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 ¶
ExtractMemories uses the LLM to identify memorable facts from messages and stores them.
func (*Manager) GetUserMemories ¶
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 ¶
OptimizeMemories asks the LLM to compress/deduplicate existing long-term memories.
func (*Manager) UserID ¶ added in v0.4.0
UserID reports the tenant this manager is scoped to ("" means global).
func (*Manager) WithUserID ¶ added in v0.4.0
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 ¶
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
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
DeleteLongTerm removes a long-term memory for the store's tenant by key.
func (*Store) ForUser ¶ added in v0.4.0
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 ¶
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 ¶
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 ¶
ListShortTerm returns all short-term memories for this agent.
func (*Store) SetLongTerm ¶
SetLongTerm stores a value in cross-session persistent memory, scoped to the store's tenant (agentID, userID).
func (*Store) SetShortTerm ¶
SetShortTerm stores a value in session-scoped working memory.