Documentation
¶
Overview ¶
Package memory defines implementation-neutral capabilities for supplying and accepting agent memory.
The package deliberately exposes three small SPIs:
- ContextProvider supplies structured, hydrated context.
- TurnSink commits canonical conversation messages.
- DocumentSink stores normalized documents and provenance.
Canonical sources, derived views, retrieval projections, lifecycle workers, and context-packing algorithms belong to implementations. In particular, vector, lexical, and entity indexes are not SDK interfaces: they are replaceable projections behind ContextProvider.
Scope always enforces the runtime and tenant partition. Request-specific conversation and dataset addresses never widen that boundary.
Index ¶
- Constants
- func IsKind(err error, want ErrorKind) bool
- type Assembly
- type Budget
- type ContextAddress
- type ContextItem
- type ContextItemKind
- type ContextProvider
- type ContextRange
- type ContextRenderer
- type ContextRendererFunc
- type ContextRequest
- type ContextResult
- type ContextSourceClass
- type Document
- type DocumentSink
- type Error
- type ErrorKind
- type ExpandHint
- type Metadata
- type RecallEvent
- type Scope
- type SourceKind
- type SourceRef
- type Turn
- type TurnSink
Constants ¶
const AssemblyKind = "memory.Assembly"
AssemblyKind is the deployment resource kind of a memory assembly. The implementation module (flowcraft memory) registers its factory under this kind; core only owns the contract.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Assembly ¶
type Assembly interface {
ContextProvider
TurnSink
DocumentSink
}
Assembly is the memory capability contract a deployment binds to: agent lifecycle hooks consume it as a context provider and turn sink, and applications can push documents. Implementations (such as the flowcraft memory module) build one through their config.Factory implementation and may expose implementation-specific services (like background workers) through their own types; this package knows nothing about them.
type ContextAddress ¶
type ContextAddress struct {
Kind ContextItemKind
ConversationID string
DatasetID string
DocumentID string
ItemID string
}
ContextAddress qualifies a view-local item ID within one hard scope. Conversation and document coordinates are explicit so equal local IDs in different conversations or datasets remain distinct.
func (ContextAddress) Identity ¶
func (address ContextAddress) Identity(scope Scope) string
Identity returns an opaque identity qualified by the complete hard scope.
func (ContextAddress) IsZero ¶
func (address ContextAddress) IsZero() bool
func (ContextAddress) Key ¶
func (address ContextAddress) Key() string
Key is a collision-free identity within a single hard scope.
func (ContextAddress) Validate ¶
func (address ContextAddress) Validate() error
type ContextItem ¶
type ContextItem struct {
ID string
Address ContextAddress
Kind ContextItemKind
Content message.Content
Score float64
Sources []SourceRef
Metadata Metadata
TokenCount int
SourceClass ContextSourceClass
MessageRole message.Role
Sequence uint64
Timestamp time.Time
ParentID string
Level int
Ordinal uint64
Title string
Hint *ExpandHint
}
ContextItem is a hydrated, scored memory item. Score has one portable meaning across implementations: larger is more relevant and values are in [0,1]. Scores from individual retrieval lanes are implementation details.
func (ContextItem) Clone ¶
func (i ContextItem) Clone() ContextItem
Clone returns an independent copy of the item's mutable data.
func (ContextItem) Identity ¶
func (i ContextItem) Identity(scope Scope) string
Identity returns the hard-scope-qualified identity used by lifecycle reinforcement and visibility overlays. ID remains the view-local ID.
func (ContextItem) Validate ¶
func (i ContextItem) Validate() error
type ContextItemKind ¶
type ContextItemKind string
ContextItemKind identifies a hydrated memory view.
const ( ContextRawMessage ContextItemKind = "raw_message" ContextFact ContextItemKind = "fact" ContextDocumentResource ContextItemKind = "document_resource" ContextDocumentSection ContextItemKind = "document_section" ContextDocumentChunk ContextItemKind = "document_chunk" ContextDocumentSummary ContextItemKind = "document_summary" ContextSummary ContextItemKind = "summary" )
func (ContextItemKind) Validate ¶
func (kind ContextItemKind) Validate() error
type ContextProvider ¶
type ContextProvider interface {
Context(context.Context, ContextRequest) (ContextResult, error)
}
ContextProvider selects, hydrates, and packs memory for an agent turn. Retrieval indexes and fusion strategies remain implementation details.
type ContextRange ¶
type ContextRange struct {
StartSequence uint64
EndSequence uint64
StartTime time.Time
EndTime time.Time
}
ContextRange identifies the canonical sequence/time interval represented by a compressed item.
func (ContextRange) Validate ¶
func (value ContextRange) Validate() error
type ContextRenderer ¶
ContextRenderer projects a structured context result into content suitable for an agent prompt. It is a consumer-side SPI: memory providers remain responsible only for selecting, hydrating, and packing ContextItems.
type ContextRendererFunc ¶
ContextRendererFunc adapts a function to ContextRenderer.
func (ContextRendererFunc) Render ¶
func (function ContextRendererFunc) Render(ctx context.Context, result ContextResult) (message.Content, error)
type ContextRequest ¶
type ContextRequest struct {
Scope Scope
ConversationID string
DatasetIDs []string
Query string
Budget Budget
RecentLimit int
RecentMaxTokens int
MinScore float64
Metadata Metadata
// RecallEventID is a stable invocation/event identity. Providers must not
// reinforce retrieval when it is empty.
RecallEventID string
}
func (ContextRequest) Validate ¶
func (r ContextRequest) Validate() error
type ContextResult ¶
type ContextResult struct {
Items []ContextItem
TokenCount int
Truncated bool
RecallEventID string
}
func (ContextResult) Clone ¶
func (r ContextResult) Clone() ContextResult
func (ContextResult) Validate ¶
func (r ContextResult) Validate() error
type ContextSourceClass ¶
type ContextSourceClass string
ContextSourceClass identifies the fixed read-path source without relying on metadata markers.
const ( ContextSourceRecent ContextSourceClass = "recent" ContextSourceLongTerm ContextSourceClass = "long_term" ContextSourceSummary ContextSourceClass = "summary" )
func (ContextSourceClass) Validate ¶
func (class ContextSourceClass) Validate() error
type Document ¶
type DocumentSink ¶
DocumentSink durably stores normalized document content and provenance. URI fetching, parsing, and media extraction happen before this boundary.
type Error ¶
Error is the implementation-neutral memory error. Capability identifies the narrow SPI surface ("context", "turn", or "document") without exposing implementation stages or storage details.
type ErrorKind ¶
type ErrorKind string
ErrorKind classifies failures shared by memory capability implementations.
type ExpandHint ¶
type ExpandHint struct {
Topics []string
SourceRefs []SourceRef
Range ContextRange
PreferredLevel int
}
ExpandHint is structured navigation metadata. Consumers must resolve its provenance through hydration APIs; it is never prompt text.
func (ExpandHint) Clone ¶
func (hint ExpandHint) Clone() ExpandHint
func (ExpandHint) Validate ¶
func (hint ExpandHint) Validate() error
type Metadata ¶
Metadata is opaque, serializable annotation data. Capability implementations must not use it to weaken Scope's tenant boundary.
type RecallEvent ¶
RecallEvent records only items actually returned from long-term or summary retrieval. ItemIDs and Scores are parallel canonical arrays.
func (RecallEvent) Validate ¶
func (event RecallEvent) Validate() error
type Scope ¶
type Scope struct {
// RuntimeID names the configured memory resource.
RuntimeID string
// UserID is the tenant partition. Empty selects a documented global scope.
UserID string
// AgentID is part of the hard partition. Empty selects the explicit
// global-agent partition; it never widens reads to other agents.
AgentID string
}
Scope identifies a memory instance and its tenant. Conversation and dataset addresses intentionally live on individual requests so there is only one source of truth for each address.
func (Scope) HardPartitionKey ¶
HardPartitionKey returns the collision-free runtime, tenant, and agent key. An empty AgentID is an explicit global-agent partition.
type SourceKind ¶
type SourceKind string
SourceKind names a canonical source type.
const ( SourceMessage SourceKind = "message" SourceDocument SourceKind = "document" SourceExternal SourceKind = "external" )
func (SourceKind) Validate ¶
func (kind SourceKind) Validate() error
type SourceRef ¶
type SourceRef struct {
Kind SourceKind
ID string
Revision string
Locator string
}
SourceRef preserves provenance without exposing a storage backend.
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
Package hook adapts memory capabilities to agent lifecycle hooks.
|
Package hook adapts memory capabilities to agent lifecycle hooks. |
|
Package render projects structured memory context into prompt content.
|
Package render projects structured memory context into prompt content. |