-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
167 lines (145 loc) · 4.74 KB
/
Copy pathmain.go
File metadata and controls
167 lines (145 loc) · 4.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// Example: Dakera Go SDK — Memory & Session Operations
package main
import (
"context"
"fmt"
"log"
"os"
dakera "github.com/dakera-ai/dakera-go"
)
func dakeraURL() string {
if u := os.Getenv("DAKERA_API_URL"); u != "" {
return u
}
return "http://localhost:3300"
}
func dakeraAPIKey() string {
if k := os.Getenv("DAKERA_API_KEY"); k != "" {
return k
}
return "dk-mykey"
}
func main() {
client := dakera.NewClientWithOptions(dakera.ClientOptions{
BaseURL: dakeraURL(),
APIKey: dakeraAPIKey(),
})
ctx := context.Background()
agentID := "agent-001"
// -------------------------------------------------------------------------
// Store memories
// -------------------------------------------------------------------------
fmt.Println("--- Storing Memories ---")
importance := float32(0.9)
mem1, err := client.StoreMemory(ctx, agentID, dakera.StoreMemoryRequest{
Content: "The user prefers concise responses with code examples.",
MemoryType: "semantic",
Importance: &importance,
Metadata: map[string]interface{}{
"source": "user-feedback",
},
})
if err != nil {
log.Fatalf("StoreMemory failed: %v", err)
} else {
fmt.Printf("Stored memory: %s\n", mem1.Memory.ID)
}
imp2 := float32(0.7)
mem2, err := client.StoreMemory(ctx, agentID, dakera.StoreMemoryRequest{
Content: "User is working on a Go web service using the chi router.",
MemoryType: "episodic",
Importance: &imp2,
})
if err != nil {
log.Fatalf("StoreMemory failed: %v", err)
} else {
fmt.Printf("Stored memory: %s\n", mem2.Memory.ID)
}
// -------------------------------------------------------------------------
// Recall memories
// -------------------------------------------------------------------------
fmt.Println("\n--- Recalling Memories ---")
recallResp, err := client.Recall(ctx, agentID, dakera.RecallRequest{
Query: "What does the user prefer?",
TopK: 5,
})
if err != nil {
log.Fatalf("Recall failed: %v", err)
} else {
for _, m := range recallResp.Memories {
fmt.Printf(" [%.2f] %s — %s\n", m.Score, m.MemoryType, m.Content)
}
}
// -------------------------------------------------------------------------
// Search memories by type
// -------------------------------------------------------------------------
fmt.Println("\n--- Search Memories (type=semantic) ---")
searched, err := client.SearchMemories(ctx, agentID, dakera.SearchMemoriesRequest{
Query: "user preferences",
MemoryType: "semantic",
TopK: 3,
})
if err != nil {
log.Printf("SearchMemories (may not be supported): %v", err)
} else {
for _, m := range searched {
fmt.Printf(" [%.2f] %s\n", m.Score, m.Content)
}
}
// -------------------------------------------------------------------------
// Sessions
// -------------------------------------------------------------------------
fmt.Println("\n--- Session Management ---")
session, err := client.StartSession(ctx, dakera.StartSessionRequest{
AgentID: agentID,
Metadata: map[string]interface{}{
"task": "code-review",
},
})
if err != nil {
log.Printf("StartSession (may not be supported): %v", err)
} else {
fmt.Printf("Started session: %s\n", session.ID)
sessionMem, err := client.StoreMemory(ctx, agentID, dakera.StoreMemoryRequest{
Content: "Reviewing PR #42: refactor authentication middleware.",
SessionID: session.ID,
})
if err != nil {
log.Printf("StoreMemory with session (may not be supported): %v", err)
} else {
fmt.Printf("Stored session memory: %s\n", sessionMem.Memory.ID)
}
endResp, err := client.EndSession(ctx, session.ID)
if err != nil {
log.Printf("EndSession (may not be supported): %v", err)
} else {
fmt.Printf("Ended session: %s (memories: %d)\n", endResp.Session.ID, endResp.MemoryCount)
}
}
// -------------------------------------------------------------------------
// Agent stats
// -------------------------------------------------------------------------
fmt.Println("\n--- Agent Stats ---")
stats, err := client.AgentStats(ctx, agentID)
if err != nil {
log.Printf("AgentStats (may not be supported): %v", err)
} else {
fmt.Printf("Agent: %s\n", stats.AgentID)
fmt.Printf(" Total memories: %d\n", stats.TotalMemories)
fmt.Printf(" Total sessions: %d\n", stats.TotalSessions)
}
// -------------------------------------------------------------------------
// Summarize memories
// -------------------------------------------------------------------------
fmt.Println("\n--- Summarize ---")
summary, err := client.Summarize(ctx, dakera.SummarizeRequest{
AgentID: agentID,
TargetType: "semantic",
})
if err != nil {
log.Printf("Summarize (may not be supported): %v", err)
} else {
fmt.Printf("Summary (%d sources): %s\n", summary.SourceCount, summary.Summary)
}
fmt.Println("\nDone!")
}