(ctx context.Context, backend backends.BackendProtocol)
| 231 | } |
| 232 | |
| 233 | func demonstrateFindAndReplace(ctx context.Context, backend backends.BackendProtocol) { |
| 234 | manager, err := memory.NewWorkingMemoryManager(&memory.WorkingMemoryConfig{ |
| 235 | Backend: backend, |
| 236 | BasePath: "/working_memory_experimental/", |
| 237 | Scope: memory.ScopeThread, |
| 238 | }) |
| 239 | if err != nil { |
| 240 | log.Fatalf("create manager: %v", err) |
| 241 | } |
| 242 | |
| 243 | threadID := "edit-session" |
| 244 | resourceID := "task-tracker" |
| 245 | |
| 246 | // 初始状态 |
| 247 | initialState := `# Task Tracker |
| 248 | |
| 249 | ## Status: in_progress |
| 250 | |
| 251 | ## Tasks |
| 252 | - [x] Design system |
| 253 | - [ ] Implement features |
| 254 | - [ ] Write tests |
| 255 | - [ ] Write documentation` |
| 256 | |
| 257 | err = manager.Update(ctx, threadID, resourceID, initialState) |
| 258 | if err != nil { |
| 259 | log.Fatalf("update initial: %v", err) |
| 260 | } |
| 261 | fmt.Println("✓ 初始状态已设置") |
| 262 | |
| 263 | // Find and Replace: 更新状态 |
| 264 | err = manager.FindAndReplace(ctx, threadID, resourceID, |
| 265 | "Status: in_progress", |
| 266 | "Status: completed") |
| 267 | if err != nil { |
| 268 | log.Fatalf("find and replace: %v", err) |
| 269 | } |
| 270 | fmt.Println("✓ 状态已更新(find and replace)") |
| 271 | |
| 272 | // Find and Replace: 更新任务 |
| 273 | err = manager.FindAndReplace(ctx, threadID, resourceID, |
| 274 | "- [ ] Implement features", |
| 275 | "- [x] Implement features") |
| 276 | if err != nil { |
| 277 | log.Fatalf("update task: %v", err) |
| 278 | } |
| 279 | fmt.Println("✓ 任务已完成(find and replace)") |
| 280 | |
| 281 | // Append: 添加新任务(search string 为空) |
| 282 | err = manager.FindAndReplace(ctx, threadID, resourceID, |
| 283 | "", |
| 284 | "- [ ] Deploy to production") |
| 285 | if err != nil { |
| 286 | log.Fatalf("append: %v", err) |
| 287 | } |
| 288 | fmt.Println("✓ 新任务已添加(append)") |
| 289 | |
| 290 | // 查看最终状态 |
no test coverage detected