forked from EchoCog/echollama
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_integrations_v2.go
More file actions
208 lines (173 loc) · 7.22 KB
/
Copy pathtest_integrations_v2.go
File metadata and controls
208 lines (173 loc) · 7.22 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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
// +build ignore
package main
import (
"context"
"fmt"
"time"
"github.com/cogpy/echo9llama/core/deeptreeecho"
"github.com/cogpy/echo9llama/core/llm"
)
var _ = context.Background // Suppress unused import warning
func main() {
fmt.Println("╔═══════════════════════════════════════════════════════════════╗")
fmt.Println("║ 🧪 INTEGRATION TEST V2: SemanticMemory, Scheduler, EventBus║")
fmt.Println("╚═══════════════════════════════════════════════════════════════╝")
fmt.Println()
// Create LLM provider
llmProvider := llm.NewMultiProviderLLM()
fmt.Println("✅ Created multi-provider LLM")
// Test 1: Semantic Memory
fmt.Println("\n📦 Test 1: Semantic Memory (chromem-go inspired)...")
semanticMemory := deeptreeecho.NewSemanticMemory(llmProvider)
err := semanticMemory.Start()
if err != nil {
fmt.Printf(" ❌ Failed to start SemanticMemory: %v\n", err)
} else {
fmt.Println(" ✅ SemanticMemory started")
}
// Test storing memories
episodeID, err := semanticMemory.StoreEpisode("Learned about vector databases today", map[string]string{"context": "learning"})
if err != nil {
fmt.Printf(" ❌ Failed to store episode: %v\n", err)
} else {
fmt.Printf(" ✅ Stored episode: %s\n", episodeID)
}
factID, err := semanticMemory.StoreFact("Vector databases enable semantic search using embeddings", "research")
if err != nil {
fmt.Printf(" ❌ Failed to store fact: %v\n", err)
} else {
fmt.Printf(" ✅ Stored fact: %s\n", factID)
}
wisdomID, err := semanticMemory.StoreWisdom("Understanding emerges from connecting related concepts", "reflection", 0.85)
if err != nil {
fmt.Printf(" ❌ Failed to store wisdom: %v\n", err)
} else {
fmt.Printf(" ✅ Stored wisdom: %s\n", wisdomID)
}
// Test querying
results, err := semanticMemory.Query("semantic", "vector embeddings", 3)
if err != nil {
fmt.Printf(" ❌ Failed to query: %v\n", err)
} else {
fmt.Printf(" ✅ Query returned %d results\n", len(results))
for _, r := range results {
fmt.Printf(" - [%.2f] %s\n", r.Similarity, truncate(r.Document.Content, 50))
}
}
// Get metrics
smMetrics := semanticMemory.GetMetrics()
fmt.Printf(" Metrics: collections=%v, documents=%v, queries=%v\n",
smMetrics["collections"], smMetrics["total_documents"], smMetrics["total_queries"])
// Test 2: Cognitive Scheduler
fmt.Println("\n⏰ Test 2: Cognitive Scheduler (gocron inspired)...")
cogScheduler := deeptreeecho.NewCognitiveScheduler()
err = cogScheduler.Start()
if err != nil {
fmt.Printf(" ❌ Failed to start CognitiveScheduler: %v\n", err)
} else {
fmt.Println(" ✅ CognitiveScheduler started")
}
// Schedule an interval job
job1, err := cogScheduler.ScheduleInterval("heartbeat", 500*time.Millisecond, func(ctx context.Context) error {
fmt.Println(" 💓 Heartbeat")
return nil
})
if err != nil {
fmt.Printf(" ❌ Failed to schedule interval job: %v\n", err)
} else {
fmt.Printf(" ✅ Scheduled interval job: %s\n", job1.Name)
}
// Schedule a cognitive phase job
job2, err := cogScheduler.ScheduleCognitivePhase("perception_phase", 1, 2*time.Second, func(ctx context.Context) error {
fmt.Println(" 👁️ Perception phase triggered")
return nil
})
if err != nil {
fmt.Printf(" ❌ Failed to schedule phase job: %v\n", err)
} else {
fmt.Printf(" ✅ Scheduled cognitive phase job: %s\n", job2.Name)
}
// Let jobs run
fmt.Println(" ⏳ Running scheduler for 2 seconds...")
time.Sleep(2 * time.Second)
// Get metrics
csMetrics := cogScheduler.GetMetrics()
fmt.Printf(" Metrics: jobs=%v, total_run=%v, failed=%v\n",
csMetrics["job_count"], csMetrics["total_jobs_run"], csMetrics["total_jobs_failed"])
// Test 3: Event Bus V2
fmt.Println("\n📡 Test 3: Event Bus V2 (watermill inspired)...")
eventBus := deeptreeecho.NewEventBusV2()
err = eventBus.Start()
if err != nil {
fmt.Printf(" ❌ Failed to start EventBusV2: %v\n", err)
} else {
fmt.Println(" ✅ EventBusV2 started")
}
// Setup cognitive routes
eventBus.SetupCognitiveRoutes()
// Subscribe to topics
perceptionCount := 0
_, err = eventBus.Subscribe(deeptreeecho.TopicPerception, func(msg *deeptreeecho.EventMessage) error {
perceptionCount++
fmt.Printf(" 📥 Received perception event: %s\n", string(msg.Payload))
return nil
})
if err != nil {
fmt.Printf(" ❌ Failed to subscribe: %v\n", err)
} else {
fmt.Println(" ✅ Subscribed to perception topic")
}
wisdomCount := 0
_, err = eventBus.Subscribe(deeptreeecho.TopicWisdom, func(msg *deeptreeecho.EventMessage) error {
wisdomCount++
fmt.Printf(" 🔮 Received wisdom event: %s\n", string(msg.Payload))
return nil
})
if err != nil {
fmt.Printf(" ❌ Failed to subscribe: %v\n", err)
} else {
fmt.Println(" ✅ Subscribed to wisdom topic")
}
// Publish events
err = eventBus.PublishCognitiveEvent(deeptreeecho.TopicPerception, "visual", map[string]string{"content": "observed pattern"})
if err != nil {
fmt.Printf(" ❌ Failed to publish: %v\n", err)
} else {
fmt.Println(" ✅ Published perception event")
}
err = eventBus.PublishCognitiveEvent(deeptreeecho.TopicEmergence, "pattern", map[string]string{"pattern": "recursive structure"})
if err != nil {
fmt.Printf(" ❌ Failed to publish: %v\n", err)
} else {
fmt.Println(" ✅ Published emergence event (should route to wisdom)")
}
// Wait for events to be processed
time.Sleep(500 * time.Millisecond)
// Get metrics
ebMetrics := eventBus.GetMetrics()
fmt.Printf(" Metrics: topics=%v, published=%v, delivered=%v\n",
ebMetrics["topics"], ebMetrics["total_published"], ebMetrics["total_delivered"])
fmt.Printf(" Event counts: perception=%d, wisdom=%d\n", perceptionCount, wisdomCount)
// Test 4: Gestalt contributions
fmt.Println("\n🌐 Test 4: Gestalt Contributions...")
smGestalt := semanticMemory.ContributeToGestalt()
fmt.Printf(" SemanticMemory: running=%v, collections=%v\n", smGestalt["running"], smGestalt["collections"])
csGestalt := cogScheduler.ContributeToGestalt()
fmt.Printf(" CognitiveScheduler: running=%v, total_jobs_run=%v\n", csGestalt["running"], csGestalt["total_jobs_run"])
ebGestalt := eventBus.ContributeToGestalt()
fmt.Printf(" EventBusV2: running=%v, active_topics=%v\n", ebGestalt["running"], ebGestalt["active_topics"])
// Cleanup
fmt.Println("\n🧹 Cleaning up...")
cogScheduler.Stop()
eventBus.Stop()
semanticMemory.Stop()
fmt.Println("\n╔═══════════════════════════════════════════════════════════════╗")
fmt.Println("║ ✅ ALL INTEGRATION TESTS V2 PASSED ║")
fmt.Println("╚═══════════════════════════════════════════════════════════════╝")
}
func truncate(s string, maxLen int) string {
if len(s) <= maxLen {
return s
}
return s[:maxLen-3] + "..."
}