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

Function demonstrateThreadScope

examples/memory-working/main.go:39–102  ·  view source on GitHub ↗
(ctx context.Context, backend backends.BackendProtocol)

Source from the content-addressed store, hash-verified

37}
38
39func demonstrateThreadScope(ctx context.Context, backend backends.BackendProtocol) {
40 // 创建 thread scope 的 Working Memory 管理器
41 manager, err := memory.NewWorkingMemoryManager(&memory.WorkingMemoryConfig{
42 Backend: backend,
43 BasePath: "/working_memory/",
44 Scope: memory.ScopeThread,
45 })
46 if err != nil {
47 log.Fatalf("create manager: %v", err)
48 }
49
50 thread1 := "conversation-001"
51 thread2 := "conversation-002"
52 resource := "shared-resource"
53
54 // Thread 1: Alice 的会话
55 aliceProfile := `# User Profile
56Name: Alice
57Role: Software Engineer
58
59## Preferences
60- Prefers concise explanations
61- Uses TypeScript
62- Likes functional programming
63
64## Current Task
65Status: planning
66Goal: Design memory system`
67
68 err = manager.Update(ctx, thread1, resource, aliceProfile)
69 if err != nil {
70 log.Fatalf("update thread 1: %v", err)
71 }
72 fmt.Println("✓ Thread 1 (Alice) Working Memory 已更新")
73
74 // Thread 2: Bob 的会话
75 bobProfile := `# User Profile
76Name: Bob
77Role: Product Manager
78
79## Preferences
80- Prefers detailed explanations
81- Focuses on user stories
82- Likes diagrams
83
84## Current Task
85Status: reviewing
86Goal: Review memory system design`
87
88 err = manager.Update(ctx, thread2, resource, bobProfile)
89 if err != nil {
90 log.Fatalf("update thread 2: %v", err)
91 }
92 fmt.Println("✓ Thread 2 (Bob) Working Memory 已更新")
93
94 // 读取各自的 Working Memory
95 aliceMemory, _ := manager.Get(ctx, thread1, resource)
96 bobMemory, _ := manager.Get(ctx, thread2, resource)

Callers 1

mainFunction · 0.85

Calls 4

UpdateMethod · 0.95
GetMethod · 0.95
NewWorkingMemoryManagerFunction · 0.92
PrintfMethod · 0.80

Tested by

no test coverage detected