Documentation
¶
Overview ¶
Package inmemory provides in-memory memory service implementation.
Package inmemory provides in-memory memory service implementation.
Index ¶
- type MemoryService
- func (s *MemoryService) AddMemory(ctx context.Context, userKey memory.UserKey, memoryStr string, topics []string) error
- func (s *MemoryService) ClearMemories(ctx context.Context, userKey memory.UserKey) error
- func (s *MemoryService) Close() error
- func (s *MemoryService) DeleteMemory(ctx context.Context, memoryKey memory.Key) error
- func (s *MemoryService) EnqueueAutoMemoryJob(ctx context.Context, sess *session.Session) error
- func (s *MemoryService) ReadMemories(ctx context.Context, userKey memory.UserKey, limit int) ([]*memory.Entry, error)
- func (s *MemoryService) SearchMemories(ctx context.Context, userKey memory.UserKey, query string) ([]*memory.Entry, error)
- func (s *MemoryService) Tools() []tool.Tool
- func (s *MemoryService) UpdateMemory(ctx context.Context, memoryKey memory.Key, memoryStr string, topics []string) error
- type ServiceOpt
- func WithAsyncMemoryNum(num int) ServiceOpt
- func WithCustomTool(toolName string, creator memory.ToolCreator) ServiceOpt
- func WithExtractor(e extractor.MemoryExtractor) ServiceOpt
- func WithMemoryJobTimeout(timeout time.Duration) ServiceOpt
- func WithMemoryLimit(limit int) ServiceOpt
- func WithMemoryQueueSize(size int) ServiceOpt
- func WithToolEnabled(toolName string, enabled bool) ServiceOpt
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type MemoryService ¶
type MemoryService struct {
// contains filtered or unexported fields
}
MemoryService is an in-memory implementation of memory.Service.
func NewMemoryService ¶
func NewMemoryService(options ...ServiceOpt) *MemoryService
NewMemoryService creates a new in-memory memory service.
func (*MemoryService) AddMemory ¶
func (s *MemoryService) AddMemory(ctx context.Context, userKey memory.UserKey, memoryStr string, topics []string) error
AddMemory adds or updates a memory for a user (idempotent).
func (*MemoryService) ClearMemories ¶
ClearMemories clears all memories for a user.
func (*MemoryService) Close ¶ added in v1.2.0
func (s *MemoryService) Close() error
Close stops the async memory workers and cleans up resources.
func (*MemoryService) DeleteMemory ¶
DeleteMemory deletes a memory for a user.
func (*MemoryService) EnqueueAutoMemoryJob ¶ added in v1.2.0
EnqueueAutoMemoryJob enqueues an auto memory extraction job for async processing. The session contains the full transcript and state for incremental extraction.
func (*MemoryService) ReadMemories ¶
func (s *MemoryService) ReadMemories(ctx context.Context, userKey memory.UserKey, limit int) ([]*memory.Entry, error)
ReadMemories reads memories for a user.
func (*MemoryService) SearchMemories ¶
func (s *MemoryService) SearchMemories(ctx context.Context, userKey memory.UserKey, query string) ([]*memory.Entry, error)
SearchMemories searches memories for a user.
func (*MemoryService) Tools ¶
func (s *MemoryService) Tools() []tool.Tool
Tools returns the list of available memory tools. In auto memory mode (extractor is set), only front-end tools are returned. By default, only Search is enabled; Load can be enabled explicitly. In agentic mode, all enabled tools are returned. The tools list is pre-computed at service creation time.
func (*MemoryService) UpdateMemory ¶
func (s *MemoryService) UpdateMemory(ctx context.Context, memoryKey memory.Key, memoryStr string, topics []string) error
UpdateMemory updates an existing memory for a user.
type ServiceOpt ¶
type ServiceOpt func(*serviceOpts)
ServiceOpt is the option for the in-memory memory service.
func WithAsyncMemoryNum ¶ added in v1.2.0
func WithAsyncMemoryNum(num int) ServiceOpt
WithAsyncMemoryNum sets the number of async memory workers.
func WithCustomTool ¶
func WithCustomTool(toolName string, creator memory.ToolCreator) ServiceOpt
WithCustomTool sets a custom memory tool implementation. The tool will be enabled by default. If the tool name is invalid or creator is nil, this option will do nothing.
func WithExtractor ¶ added in v1.2.0
func WithExtractor(e extractor.MemoryExtractor) ServiceOpt
WithExtractor sets the memory extractor for auto memory mode. When enabled, auto mode defaults are applied to enabledTools, but user settings via WithToolEnabled (before or after) take precedence.
func WithMemoryJobTimeout ¶ added in v1.2.0
func WithMemoryJobTimeout(timeout time.Duration) ServiceOpt
WithMemoryJobTimeout sets the timeout for each memory job.
func WithMemoryLimit ¶
func WithMemoryLimit(limit int) ServiceOpt
WithMemoryLimit sets the limit of memories per user.
func WithMemoryQueueSize ¶ added in v1.2.0
func WithMemoryQueueSize(size int) ServiceOpt
WithMemoryQueueSize sets the queue size for memory jobs.
func WithToolEnabled ¶
func WithToolEnabled(toolName string, enabled bool) ServiceOpt
WithToolEnabled sets which tool is enabled. If the tool name is invalid, this option will do nothing. User settings via WithToolEnabled take precedence over auto mode defaults, regardless of option order.