memory

package
v0.100.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 17, 2026 License: MIT Imports: 1 Imported by: 0

README

AI Memory Engineering (ai/memory)

memory 包定义了 AI Agent 的记忆扩展接口,旨在实现更高级的记忆管理机制,如遗忘、合并及固化。

架构设计

classDiagram
    class Generator {
        <<interface>>
        +GenerateAsync(ctx, req)
        +GenerateSync(ctx, req) error
        +Shutdown(ctx) error
    }
    class NoOpGenerator {
        +GenerateAsync()
        +GenerateSync()
    }
    
    Generator <|.. NoOpGenerator : default implementation
  • Generator 接口: 定义了记忆生成的标准行为。
    • 异步生成 (GenerateAsync): 用于生产环境,不阻塞主流程。
    • 同步生成 (GenerateSync): 用于测试或调试。
  • NoOpGenerator: 默认的空实现。在未配置外部记忆服务(如 Mem0, Letta)时使用,确保系统稳定性。

记忆工程概念

该包的设计参考了人类记忆机制:

  1. Importance Scoring: 基于相关性、频率和新近度对信息打分。
  2. Forgetting: 模拟生物遗忘机制。
  3. Consolidation: 将短期记忆合并为长期记忆。

目前处于 基础设施阶段,定义了扩展点,未来可对接复杂的记忆存储服务。

Documentation

Overview

Package memory provides the memory extension point for AI agents.

Memory engineering is a specialized domain involving:

  • Importance scoring (relevance + frequency + recency)
  • Forgetting mechanisms (biologically-inspired decay)
  • Memory consolidation (merging, deduplication, compression)
  • Security (memory poisoning detection)
  • Multi-dimensional retrieval (semantic + temporal + causal)

This package defines the extension interface. Implementations can range from simple (for development/testing) to sophisticated (Mem0, Letta integration).

Reference: docs/architecture/context-engineering.md Phase 3

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Generator added in v0.100.0

type Generator interface {
	// GenerateAsync starts asynchronous memory generation.
	// This method returns immediately and processes the memory in a goroutine.
	// Implementations SHOULD be non-blocking and handle their own error logging.
	GenerateAsync(ctx context.Context, req MemoryRequest)

	// GenerateSync generates memory synchronously (for testing).
	// This method blocks until memory generation completes or fails.
	GenerateSync(ctx context.Context, req MemoryRequest) error

	// Shutdown waits for all pending memory generation tasks to complete.
	// This should be called during graceful service shutdown.
	Shutdown(ctx context.Context) error
}

Generator defines the memory generation extension point. Implementations can be:

  • NoOpGenerator: No-op implementation (default, production-safe)
  • SimpleGenerator: Basic implementation for dev/test (not production-ready)
  • ExternalGenerator: Integration with Mem0, Letta, or custom services

type MemoryRequest added in v0.100.0

type MemoryRequest struct {
	BlockID   int64
	UserID    int32
	AgentType string
	UserInput string
	Outcome   string // Assistant's response
	Metadata  map[string]any
}

MemoryRequest contains the data needed to generate a memory.

type NoOpGenerator added in v0.100.0

type NoOpGenerator struct{}

NoOpGenerator is a no-op implementation of Generator. It is the default implementation, safe for production use. Use this when memory generation is disabled or not yet configured.

func NewNoOpGenerator added in v0.100.0

func NewNoOpGenerator() *NoOpGenerator

NewNoOpGenerator creates a new no-op memory generator.

func (*NoOpGenerator) GenerateAsync added in v0.100.0

func (n *NoOpGenerator) GenerateAsync(_ context.Context, _ MemoryRequest)

func (*NoOpGenerator) GenerateSync added in v0.100.0

func (n *NoOpGenerator) GenerateSync(_ context.Context, _ MemoryRequest) error

func (*NoOpGenerator) Shutdown added in v0.100.0

func (n *NoOpGenerator) Shutdown(_ context.Context) error

Directories

Path Synopsis
Package simple provides a basic memory generator implementation.
Package simple provides a basic memory generator implementation.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL