Delete 删除 Working Memory
(ctx context.Context, threadID, resourceID string)
| 241 | |
| 242 | // Delete 删除 Working Memory |
| 243 | func (wm *WorkingMemoryManager) Delete(ctx context.Context, threadID, resourceID string) error { |
| 244 | if threadID == "" && resourceID == "" { |
| 245 | return errors.New("threadID and resourceID cannot both be empty") |
| 246 | } |
| 247 | |
| 248 | path := wm.resolvePath(threadID, resourceID) |
| 249 | |
| 250 | // Backend 通常没有 Delete 方法,通过写入空内容或特殊标记实现 |
| 251 | // 这里我们写入一个标记为已删除的 JSON |
| 252 | deletedData := WorkingMemoryData{ |
| 253 | Meta: WorkingMemoryMeta{ |
| 254 | ThreadID: threadID, |
| 255 | ResourceID: resourceID, |
| 256 | UpdatedAt: time.Now(), |
| 257 | }, |
| 258 | Content: "", |
| 259 | } |
| 260 | |
| 261 | jsonData, _ := json.MarshalIndent(deletedData, "", " ") |
| 262 | if _, err := wm.backend.Write(ctx, path, string(jsonData)); err != nil { |
| 263 | return fmt.Errorf("delete working memory: %w", err) |
| 264 | } |
| 265 | |
| 266 | return nil |
| 267 | } |
| 268 | |
| 269 | // GetScope 返回当前配置的作用域 |
| 270 | func (wm *WorkingMemoryManager) GetScope() WorkingMemoryScope { |