Documentation
¶
Index ¶
- Constants
- Variables
- func MustRegisterPlugin(plugin *Plugin)
- func RegisterPlugin(plugin *Plugin) error
- type CleanupConfig
- type ConversationMessage
- type HookEvent
- type HookHandler
- type HookableProvider
- type MemorizeRequest
- type MemoryConfig
- type MemoryMiddleware
- func (m *MemoryMiddleware) AfterModelRewriteState(ctx context.Context, state *adk.ChatModelAgentState, mc *adk.ModelContext) (context.Context, *adk.ChatModelAgentState, error)
- func (m *MemoryMiddleware) BeforeAgent(ctx context.Context, runCtx *adk.ChatModelAgentContext) (context.Context, *adk.ChatModelAgentContext, error)
- func (m *MemoryMiddleware) BeforeModelRewriteState(ctx context.Context, state *adk.ChatModelAgentState, mc *adk.ModelContext) (context.Context, *adk.ChatModelAgentState, error)
- type MemoryProvider
- type MemoryRetrieval
- type MemoryStorage
- type Plugin
- type ProviderFactory
- type Registry
- type RetrieveRequest
- type RetrieveResult
- type SessionSummary
- type SummaryTriggerConfig
- type SummaryTriggerStrategy
- type TaskQueueStats
- type UserMemory
- type UserMemoryAnalyzerParam
Constants ¶
const ( RetrievalLastN = builtin.RetrievalLastN RetrievalFirstN = builtin.RetrievalFirstN RetrievalSemantic = builtin.RetrievalSemantic UserMemoryOpUpdate = builtin.UserMemoryOpUpdate UserMemoryOpNoop = builtin.UserMemoryOpNoop TriggerAlways = builtin.TriggerAlways TriggerByMessages = builtin.TriggerByMessages TriggerByTime = builtin.TriggerByTime TriggerSmart = builtin.TriggerSmart )
Variables ¶
var ( NewMemoryManager = builtin.NewMemoryManager DefaultMemoryConfig = builtin.DefaultMemoryConfig )
Functions ¶
func MustRegisterPlugin ¶ added in v0.2.0
func MustRegisterPlugin(plugin *Plugin)
MustRegisterPlugin registers a plugin with the global registry, panicking on error.
func RegisterPlugin ¶ added in v0.2.0
RegisterPlugin registers a plugin with the global registry.
Types ¶
type CleanupConfig ¶ added in v0.2.0
type CleanupConfig = builtin.CleanupConfig
type ConversationMessage ¶
type ConversationMessage = builtin.ConversationMessage
type HookEvent ¶ added in v0.2.0
type HookEvent string
HookEvent represents a lifecycle event in the memory provider.
const ( // HookBeforeRetrieve fires before the Retrieve operation. HookBeforeRetrieve HookEvent = "before_retrieve" // HookAfterRetrieve fires after the Retrieve operation. HookAfterRetrieve HookEvent = "after_retrieve" // HookBeforeMemorize fires before the Memorize operation. HookBeforeMemorize HookEvent = "before_memorize" // HookAfterMemorize fires after the Memorize operation. HookAfterMemorize HookEvent = "after_memorize" )
type HookHandler ¶ added in v0.2.0
HookHandler is a callback function invoked when a lifecycle event fires.
type HookableProvider ¶ added in v0.2.0
type HookableProvider interface {
MemoryProvider
// RegisterHook registers a handler for the given lifecycle event.
RegisterHook(event HookEvent, handler HookHandler)
}
HookableProvider is an optional extension of MemoryProvider for providers that support lifecycle hooks.
type MemorizeRequest ¶ added in v0.2.0
type MemorizeRequest struct {
// UserID identifies the user whose conversation to store.
UserID string
// SessionID identifies the conversation session.
SessionID string
// Messages are the conversation turn(s) to store.
Messages []*schema.Message
}
MemorizeRequest is the input for the Memorize operation.
type MemoryConfig ¶
type MemoryConfig = builtin.MemoryConfig
type MemoryMiddleware ¶ added in v0.2.0
type MemoryMiddleware struct {
*adk.BaseChatModelAgentMiddleware
// contains filtered or unexported fields
}
MemoryMiddleware implements adk.ChatModelAgentMiddleware. It delegates to a MemoryProvider for retrieval and memorization.
func NewMemoryMiddleware ¶ added in v0.2.0
func NewMemoryMiddleware(provider MemoryProvider) *MemoryMiddleware
NewMemoryMiddleware creates a MemoryMiddleware with a MemoryProvider.
func (*MemoryMiddleware) AfterModelRewriteState ¶ added in v0.2.0
func (m *MemoryMiddleware) AfterModelRewriteState(ctx context.Context, state *adk.ChatModelAgentState, mc *adk.ModelContext) (context.Context, *adk.ChatModelAgentState, error)
AfterModelRewriteState stores assistant response after a model call.
func (*MemoryMiddleware) BeforeAgent ¶ added in v0.2.0
func (m *MemoryMiddleware) BeforeAgent(ctx context.Context, runCtx *adk.ChatModelAgentContext) (context.Context, *adk.ChatModelAgentContext, error)
BeforeAgent is called before the agent runs.
func (*MemoryMiddleware) BeforeModelRewriteState ¶ added in v0.2.0
func (m *MemoryMiddleware) BeforeModelRewriteState(ctx context.Context, state *adk.ChatModelAgentState, mc *adk.ModelContext) (context.Context, *adk.ChatModelAgentState, error)
BeforeModelRewriteState injects memory context before a model call.
type MemoryProvider ¶ added in v0.2.0
type MemoryProvider interface {
// Retrieve fetches relevant memory context before a model call.
Retrieve(ctx context.Context, req *RetrieveRequest) (*RetrieveResult, error)
// Memorize persists a conversation turn after a model call.
Memorize(ctx context.Context, req *MemorizeRequest) error
// Close releases any resources held by the provider.
Close() error
}
MemoryProvider defines the interface that all memory backends must implement. It provides the core operations for retrieving relevant context before a model call and persisting conversation turns after a model call.
type MemoryRetrieval ¶
type MemoryRetrieval = builtin.MemoryRetrieval
type MemoryStorage ¶
type MemoryStorage = builtin.MemoryStorage
type Plugin ¶ added in v0.2.0
type Plugin struct {
// ID is the unique identifier for the plugin (e.g. "builtin", "memu", "mem0").
ID string
// Factory creates a new MemoryProvider instance for this plugin.
Factory ProviderFactory
}
Plugin represents a memory backend plugin that can be registered with the registry.
type ProviderFactory ¶ added in v0.2.0
type ProviderFactory func(config any) (MemoryProvider, error)
ProviderFactory creates a new MemoryProvider instance from the given config.
type Registry ¶ added in v0.2.0
type Registry struct {
// contains filtered or unexported fields
}
Registry manages registered memory backend plugins.
func GlobalRegistry ¶ added in v0.2.0
func GlobalRegistry() *Registry
GlobalRegistry returns the global registry instance.
func NewRegistry ¶ added in v0.2.0
func NewRegistry() *Registry
NewRegistry creates a new empty Registry.
func (*Registry) CreateProvider ¶ added in v0.2.0
func (r *Registry) CreateProvider(pluginID string, config any) (MemoryProvider, error)
CreateProvider creates a new MemoryProvider using the plugin identified by pluginID.
func (*Registry) Get ¶ added in v0.2.0
Get returns the plugin with the given ID, or false if not found.
func (*Registry) ListPlugins ¶ added in v0.2.0
ListPlugins returns the IDs of all registered plugins.
func (*Registry) MustRegister ¶ added in v0.2.0
MustRegister registers a plugin and panics if registration fails.
type RetrieveRequest ¶ added in v0.2.0
type RetrieveRequest struct {
// UserID identifies the user whose memory to search.
UserID string
// SessionID identifies the current conversation session.
SessionID string
// Messages are the current conversation messages used as context for retrieval.
Messages []*schema.Message
// Limit is the maximum number of memory items to return.
// A value of 0 means the provider should use its own default.
Limit int
}
RetrieveRequest is the input for the Retrieve operation.
type RetrieveResult ¶ added in v0.2.0
type RetrieveResult struct {
// SystemMessages are injected as system context before the conversation.
SystemMessages []*schema.Message
// HistoryMessages are injected as conversation history.
HistoryMessages []*schema.Message
// Metadata holds provider-specific data.
Metadata map[string]any
}
RetrieveResult is the output of the Retrieve operation.
type SessionSummary ¶
type SessionSummary = builtin.SessionSummary
type SummaryTriggerConfig ¶
type SummaryTriggerConfig = builtin.SummaryTriggerConfig
type SummaryTriggerStrategy ¶
type SummaryTriggerStrategy = builtin.SummaryTriggerStrategy
type TaskQueueStats ¶ added in v0.0.10
type TaskQueueStats = builtin.TaskQueueStats
type UserMemory ¶
type UserMemory = builtin.UserMemory
type UserMemoryAnalyzerParam ¶
type UserMemoryAnalyzerParam = builtin.UserMemoryAnalyzerParam