@@ -173,6 +173,47 @@ eventLoop:
173173 mysis.Stop()
174174 }
175175
176+func TestMysisReceivesBroadcastWithSender(t *testing.T) {
177+ s, bus, cleanup := setupMysisTest(t)
178+ defer cleanup()
179+
180+ receiverStored, _ := s.CreateMysis("receiver", "mock", "test-model", 0.7)
181+ mock := provider.NewMock("mock", "response")
182+ receiver := NewMysis(receiverStored.ID, receiverStored.Name, receiverStored.CreatedAt, mock, s, bus)
183+
184+ if err := receiver.Start(); err != nil {
185+ t.Fatalf("Start() error: %v", err)
186+ }
187+ defer receiver.Stop()
188+
189+ senderID := "sender-mysis"
190+
191+ if err := receiver.SendMessageFrom("test broadcast", store.MemorySourceBroadcast, senderID); err != nil {
192+ t.Fatalf("SendMessageFrom() error: %v", err)
193+ }
194+
195+ memories, err := s.GetRecentMemories(receiverStored.ID, 10)
196+ if err != nil {
197+ t.Fatalf("GetRecentMemories() error: %v", err)
198+ }
199+
200+ if len(memories) == 0 {
201+ t.Fatal("expected at least 1 memory")
202+ }
203+
204+ found := false
205+ for _, m := range memories {
206+ if m.Source == store.MemorySourceBroadcast && m.SenderID == senderID {
207+ found = true
208+ break
209+ }
210+ }
211+
212+ if !found {
213+ t.Error("broadcast memory with correct sender_id not found")
214+ }
215+}
216+
176217 func TestMysisSetErrorState(t *testing.T) {
177218 s, bus, cleanup := setupMysisTest(t)
178219 defer cleanup()
@@ -274,12 +315,12 @@ func TestMysisContextMemoryLimit(t *testing.T) {
274315 mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
275316
276317 // Add system prompt
277- s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "")
318+ s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
278319
279320 // Add more memories than MaxContextMessages
280321 for i := 0; i < MaxContextMessages+10; i++ {
281- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "user message", "")
282- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "assistant response", "")
322+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "user message", "", "")
323+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "assistant response", "", "")
283324 }
284325
285326 // Get context memories
@@ -312,12 +353,12 @@ func TestMysisContextMemoryWithRecentSystemPrompt(t *testing.T) {
312353 mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
313354
314355 // Add system prompt
315- s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "")
356+ s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
316357
317358 // Add fewer memories than MaxContextMessages
318359 for i := 0; i < 5; i++ {
319- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "user message", "")
320- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "assistant response", "")
360+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "user message", "", "")
361+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "assistant response", "", "")
321362 }
322363
323364 // Get context memories
@@ -407,28 +448,28 @@ func TestMysisContextCompaction(t *testing.T) {
407448 mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
408449
409450 // Add system prompt
410- s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "")
451+ s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
411452
412453 // Add multiple get_ship tool results (should be compacted to keep only the latest)
413454 for i := 0; i < 5; i++ {
414- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "check ship", "")
415- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_1:get_ship:{}", "")
455+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "check ship", "", "")
456+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_1:get_ship:{}", "", "")
416457 s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool,
417- fmt.Sprintf(`call_1:{"ship_id":"ship_%d","hull":100}`, i), "")
458+ fmt.Sprintf(`call_1:{"ship_id":"ship_%d","hull":100}`, i), "", "")
418459 }
419460
420461 // Add multiple get_system tool results (should also be compacted)
421462 for i := 0; i < 3; i++ {
422- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "check system", "")
423- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_2:get_system:{}", "")
463+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "check system", "", "")
464+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_2:get_system:{}", "", "")
424465 s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool,
425- fmt.Sprintf(`call_2:{"system_id":"sys_%d","police_level":1}`, i), "")
466+ fmt.Sprintf(`call_2:{"system_id":"sys_%d","police_level":1}`, i), "", "")
426467 }
427468
428469 // Add a non-snapshot tool result (should be kept)
429- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "mine ore", "")
430- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_3:mine:{}", "")
431- s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool, `call_3:{"result":"mining"}`, "")
470+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "mine ore", "", "")
471+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_3:mine:{}", "", "")
472+ s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool, `call_3:{"result":"mining"}`, "", "")
432473
433474 // Get context memories
434475 memories, err := mysis.getContextMemories()
@@ -516,14 +557,14 @@ func TestZoeaListMysesCompaction(t *testing.T) {
516557 mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
517558
518559 // Add system prompt
519- s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "")
560+ s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
520561
521562 // Add multiple zoea_list_myses tool results (should be compacted to keep only the latest)
522563 for i := 0; i < 5; i++ {
523- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "list myses", "")
524- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_1:zoea_list_myses:{}", "")
564+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "list myses", "", "")
565+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, "[TOOL_CALLS]call_1:zoea_list_myses:{}", "", "")
525566 s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool,
526- fmt.Sprintf(`call_1:[{"id":"mysis-%d","name":"test-%d"}]`, i, i), "")
567+ fmt.Sprintf(`call_1:[{"id":"mysis-%d","name":"test-%d"}]`, i, i), "", "")
527568 }
528569
529570 // Get context memories
@@ -563,12 +604,12 @@ func TestMysisContextCompactionNonSnapshot(t *testing.T) {
563604 mock := provider.NewMock("mock", "response")
564605 mysis := NewMysis(stored.ID, stored.Name, stored.CreatedAt, mock, s, bus)
565606
566- s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "")
607+ s.AddMemory(stored.ID, store.MemoryRoleSystem, store.MemorySourceSystem, "System prompt", "", "")
567608
568609 for i := 0; i < 2; i++ {
569- s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "travel", "")
570- s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, fmt.Sprintf("[TOOL_CALLS]call_%d:travel:{}", i), "")
571- s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool, fmt.Sprintf(`call_%d:{"ship_id":"ship_%d"}`, i, i), "")
610+ s.AddMemory(stored.ID, store.MemoryRoleUser, store.MemorySourceDirect, "travel", "", "")
611+ s.AddMemory(stored.ID, store.MemoryRoleAssistant, store.MemorySourceLLM, fmt.Sprintf("[TOOL_CALLS]call_%d:travel:{}", i), "", "")
612+ s.AddMemory(stored.ID, store.MemoryRoleTool, store.MemorySourceTool, fmt.Sprintf(`call_%d:{"ship_id":"ship_%d"}`, i, i), "", "")
572613 }
573614
574615 memories, err := mysis.getContextMemories()