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
- func DefaultContextFormatter(memories []*Memory) string
- func IsKnownCategory(s string) bool
- func RegisterMemoryTools(registry *tools.Registry)
- type ConsentCategory
- type ContextFormatter
- type Executor
- type Extractor
- type InMemoryStore
- func (s *InMemoryStore) Delete(_ context.Context, scope map[string]string, memoryID string) error
- func (s *InMemoryStore) DeleteAll(_ context.Context, scope map[string]string) error
- func (s *InMemoryStore) List(_ context.Context, scope map[string]string, opts ListOptions) ([]*Memory, error)
- func (s *InMemoryStore) Retrieve(_ context.Context, scope map[string]string, query string, opts RetrieveOptions) ([]*Memory, error)
- func (s *InMemoryStore) Save(_ context.Context, m *Memory) error
- type ListOptions
- type Memory
- type Provenance
- type RetrieveOptions
- type Retriever
- type Store
- type ToolProvider
Constants ¶
const ( RecallToolName = "memory__recall" RememberToolName = "memory__remember" ListToolName = "memory__list" ForgetToolName = "memory__forget" )
Tool names in the memory namespace.
const CategoryRubric = `` /* 551-byte string literal not displayed */
CategoryRubric is a prompt fragment that consumer extractors splice into their extraction prompt so the extracting LLM tags each memory with one of the canonical categories. PromptKit owns the rubric so all consumers see the same vocabulary and downstream platforms can apply uniform rules.
Usage:
prompt := basePrompt + "\n" + memory.CategoryRubric
const ExecutorMode = "memory"
ExecutorMode is the executor name for Mode-based routing.
Variables ¶
This section is empty.
Functions ¶
func DefaultContextFormatter ¶ added in v1.4.7
DefaultContextFormatter is the formatter the retrieval stage uses when no override is supplied. It renders each memory on its own line as "[type] content (confidence: N.N)" — matching the historical hardcoded behavior. Callers should treat the output as opaque text suitable for direct injection into a system prompt.
func IsKnownCategory ¶ added in v1.4.7
IsKnownCategory reports whether s exactly matches one of the canonical category strings. Unknown values are not rejected by the storage layer — this helper exists for consumer validation only.
func RegisterMemoryTools ¶
RegisterMemoryTools registers the four base memory tools with executor routing.
Types ¶
type ConsentCategory ¶ added in v1.4.7
type ConsentCategory string
ConsentCategory is the well-known taxonomy used by consent-aware consumers (e.g. Omnia) to apply per-category retention, opt-outs, and PII rules at memory-write time. Values are stored in Memory.Metadata under the key MetaKeyConsentCategory regardless of which path produced the memory: the explicit `memory__remember` tool (LLM-supplied category arg) or an extractor stage that classifies and tags during write.
PromptKit defines the vocabulary and helpers; semantics (retention, access control, redaction) are owned by the consumer.
const ( CategoryIdentity ConsentCategory = "memory:identity" // Names, IDs, pronouns, contact details. CategoryPreferences ConsentCategory = "memory:preferences" // Likes, dislikes, settings, configuration. CategoryContext ConsentCategory = "memory:context" // Work / project context, domain knowledge, current task. CategoryLocation ConsentCategory = "memory:location" // Geographic info, addresses, IP. CategoryHealth ConsentCategory = "memory:health" // Health, dietary, medical, accessibility info. CategoryHistory ConsentCategory = "memory:history" // Past conversations, decisions, what was said before. )
Known consent categories. The string values are the wire format consumers match against — do not change them without coordinating with downstream platforms.
func KnownCategories ¶ added in v1.4.7
func KnownCategories() []ConsentCategory
KnownCategories returns the canonical set of categories in a stable order. Useful for filling option lists, validation tables, or rubric expansion.
type ContextFormatter ¶ added in v1.4.7
ContextFormatter renders a slice of retrieved memories into the string that gets written onto TurnState.Variables["memory_context"] by the retrieval pipeline stage. Hosts implement this to control how categories, dedup keys, confidence, or other metadata are surfaced to the LLM. See DefaultContextFormatter for the built-in behavior.
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 ¶
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.
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) List ¶
func (s *InMemoryStore) List( _ context.Context, scope map[string]string, opts ListOptions, ) ([]*Memory, error)
List returns memories matching the scope and filters.
type ListOptions ¶
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.
func (*Memory) GetConsentCategory ¶ added in v1.4.7
func (m *Memory) GetConsentCategory() ConsentCategory
GetConsentCategory returns the consent category previously written via Memory.SetConsentCategory or the `memory__remember` tool, or empty string when unset.
func (*Memory) GetProvenance ¶ added in v1.3.29
func (m *Memory) GetProvenance() Provenance
GetProvenance returns the provenance from metadata, or empty string if unset.
func (*Memory) SetConsentCategory ¶ added in v1.4.7
func (m *Memory) SetConsentCategory(c ConsentCategory)
SetConsentCategory writes a category onto m.Metadata[MetaKeyConsentCategory], initializing the map when nil. Empty input is a no-op so callers can pass LLM output unconditionally without checking first. Unknown (non-canonical) values are accepted as-is — see IsKnownCategory for validation.
func (*Memory) SetProvenance ¶ added in v1.3.29
func (m *Memory) SetProvenance(p Provenance)
SetProvenance sets the provenance metadata on a Memory, initializing the Metadata map if nil. This always overwrites any existing provenance value to prevent callers from spoofing provenance.
type Provenance ¶ added in v1.3.29
type Provenance string
Provenance indicates how a memory was created. Downstream systems (PII redaction, audit, retention) use this to apply context-appropriate policies. Stored in Memory.Metadata[MetaKeyProvenance].
const ( // MetaKeyProvenance is the well-known Metadata key for provenance. MetaKeyProvenance = "provenance" // MetaKeyConsentCategory is the well-known Metadata key for the // consent category attached to a memory. Two write paths populate it: // // - Explicit: the LLM calls memory__remember with a category arg, // which the executor stashes here verbatim. // - Implicit: an Extractor stage classifies and tags during write, // typically via [Memory.SetConsentCategory] driven by the // extracting LLM's structured output ([CategoryRubric] supplies // the prompt fragment). // // Consumers that classify server-side may fall back to their own // classifier when this is absent. Values are not validated by // PromptKit — see [IsKnownCategory] for an opt-in check against the // canonical [ConsentCategory] taxonomy. MetaKeyConsentCategory = "consent_category" // ProvenanceUserRequested — user explicitly asked the agent to remember this. ProvenanceUserRequested Provenance = "user_requested" // ProvenanceAgentExtracted — the agent/pipeline extracted this from // conversation without an explicit user request (safe default). ProvenanceAgentExtracted Provenance = "agent_extracted" // ProvenanceSystemGenerated — created by system logic, not from user content. ProvenanceSystemGenerated Provenance = "system_generated" // ProvenanceOperatorCurated — manually created/edited by an operator. ProvenanceOperatorCurated Provenance = "operator_curated" )
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 ¶
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.