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

Function main

examples/memory-semantic-session/main.go:17–138  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

15)
16
17func main() {
18 ctx := context.Background()
19
20 // 1. 准备 Session 服务(短期记忆)
21 svc := session.NewInMemoryService()
22 appName := "ltm_demo"
23 userID := "alice"
24
25 teachingSessionID := "teaching-session"
26
27 // 创建教学会话
28 teachingSess, err := svc.Create(ctx, &session.CreateRequest{
29 AppName: appName,
30 UserID: userID,
31 AgentID: "teacher-agent",
32 Metadata: map[string]any{"kind": "teaching"},
33 })
34 if err != nil {
35 log.Fatalf("create teaching session: %v", err)
36 }
37 if teachingSess.ID() != teachingSessionID {
38 // 使用固定 sessionID 方便演示
39 if err := svc.Update(ctx, &session.UpdateRequest{
40 SessionID: teachingSess.ID(),
41 Metadata: map[string]any{"_alias": teachingSessionID},
42 }); err != nil {
43 log.Printf("update teaching session metadata: %v", err)
44 }
45 }
46
47 // 写入教学事件
48 teachEvents := []*session.Event{
49 {
50 ID: "evt-teach-1",
51 Timestamp: time.Now(),
52 InvocationID: "inv-001",
53 AgentID: "teacher-agent",
54 Author: "user",
55 Content: types.Message{
56 Role: types.RoleUser,
57 Content: "My secret is 0xabcd",
58 },
59 },
60 {
61 ID: "evt-teach-2",
62 Timestamp: time.Now().Add(1 * time.Second),
63 InvocationID: "inv-001",
64 AgentID: "teacher-agent",
65 Author: "assistant",
66 Content: types.Message{
67 Role: types.RoleAssistant,
68 Content: "Got it, I will remember your secret.",
69 },
70 },
71 }
72 for _, ev := range teachEvents {
73 if err := svc.AppendEvent(ctx, teachingSess.ID(), ev); err != nil {
74 log.Fatalf("append teaching event: %v", err)

Callers

nothing calls this directly

Calls 12

CreateMethod · 0.95
UpdateMethod · 0.95
AppendEventMethod · 0.95
SearchMethod · 0.95
NewInMemoryServiceFunction · 0.92
NewMemoryStoreFunction · 0.92
NewMockEmbedderFunction · 0.92
NewSemanticMemoryFunction · 0.92
PrintfMethod · 0.80
IDMethod · 0.65
AddMethod · 0.65

Tested by

no test coverage detected