MCPcopy Create free account
hub / github.com/astercloud/aster / NewWorkingMemoryManager

Function NewWorkingMemoryManager

pkg/memory/working.go:66–103  ·  view source on GitHub ↗

NewWorkingMemoryManager 创建 Working Memory 管理器

(cfg *WorkingMemoryConfig)

Source from the content-addressed store, hash-verified

64
65// NewWorkingMemoryManager 创建 Working Memory 管理器
66func NewWorkingMemoryManager(cfg *WorkingMemoryConfig) (*WorkingMemoryManager, error) {
67 if cfg == nil {
68 return nil, errors.New("working memory config cannot be nil")
69 }
70 if cfg.Backend == nil {
71 return nil, errors.New("working memory requires a non-nil Backend")
72 }
73
74 basePath := cfg.BasePath
75 if basePath == "" {
76 basePath = "/working_memory/"
77 }
78 basePath = normalizeDir(basePath)
79
80 scope := cfg.Scope
81 if scope == "" {
82 scope = ScopeThread // 默认 thread 作用域
83 }
84 if scope != ScopeThread && scope != ScopeResource {
85 return nil, fmt.Errorf("invalid scope: %s (must be 'thread' or 'resource')", scope)
86 }
87
88 // 验证 Schema(如果提供)
89 if cfg.Schema != nil {
90 if err := cfg.Schema.Validate(); err != nil {
91 return nil, fmt.Errorf("invalid JSON schema: %w", err)
92 }
93 }
94
95 return &WorkingMemoryManager{
96 backend: cfg.Backend,
97 basePath: basePath,
98 scope: scope,
99 schema: cfg.Schema,
100 template: cfg.Template,
101 ttl: cfg.DefaultTTL,
102 }, nil
103}
104
105// Get 获取 Working Memory 内容
106// 根据配置的 scope 自动选择读取路径:

Calls 2

normalizeDirFunction · 0.85
ValidateMethod · 0.65