From cc040b861d22c4fd4e4191fbf6eaefe15cd0ae39 Mon Sep 17 00:00:00 2001 From: Aska Date: Thu, 20 Aug 2026 19:40:58 +0800 Subject: [PATCH] feat(ai-core): trigger memory extraction after each conversation round The WS hub and platform bridge now call Pipeline.FinishRound when the response stream completes, recording the assistant reply and invoking the LLM memory extractor asynchronously. --- backend/cmd/cyrene/main.go | 4 +++- backend/services/gateway/ws/hub.go | 9 +++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/backend/cmd/cyrene/main.go b/backend/cmd/cyrene/main.go index 4e62564..f429556 100644 --- a/backend/cmd/cyrene/main.go +++ b/backend/cmd/cyrene/main.go @@ -388,10 +388,12 @@ func loadAdaptersFromConfig(router *bridge.Router, cfg *bridge.BridgeConfig, orc } router.SetMessageHandler(func(msg *bridge.UnifiedMessage) { - tokenCh, _, err := orch.ProcessInput(context.Background(), "bridge-"+msg.Source, msg.Content) + sessionID := "bridge-" + msg.Source + tokenCh, _, err := orch.ProcessInput(context.Background(), sessionID, msg.Content) if err != nil { return } var fc string for t := range tokenCh { fc += t.Content } + orch.FinishRound(sessionID, msg.SenderID, fc) if fc != "" { router.SendTo(msg.Platform, msg.Source, fc, bridge.SendOptions{MaxLength: 500, MinGap: 3 * time.Second}) } diff --git a/backend/services/gateway/ws/hub.go b/backend/services/gateway/ws/hub.go index 4e6a8a5..a06355a 100644 --- a/backend/services/gateway/ws/hub.go +++ b/backend/services/gateway/ws/hub.go @@ -6,6 +6,7 @@ import ( "encoding/json" "git.yeij.top/AskaEth/Cyrene_v2/internal/logger" "net/http" + "strings" "sync" "github.com/gorilla/websocket" @@ -22,6 +23,9 @@ var upgrader = websocket.Upgrader{ // Orchestrator is the interface for the AI dialogue pipeline. type Orchestrator interface { ProcessInput(ctx context.Context, sessionID, userMessage string) (<-chan model.StreamToken, *model.Intent, error) + // FinishRound records the assistant reply and triggers post-round work + // (e.g. memory extraction) after the response stream completes. + FinishRound(sessionID, userID, assistantReply string) } // Hub manages all active WebSocket connections. @@ -168,13 +172,18 @@ func (c *Client) handleChatMessage(msg WSMessage) { } // Stream tokens + var fullContent strings.Builder for token := range tokenCh { + fullContent.WriteString(token.Content) if token.Done { c.sendJSON(WSMessage{Type: "stream_end", SessionID: msg.SessionID}) break } c.sendJSON(WSMessage{Type: "stream_chunk", Content: token.Content, SessionID: msg.SessionID}) } + + // Record the reply and trigger post-round work (memory extraction etc.) + c.hub.orchestrator.FinishRound(msg.SessionID, c.UserID, fullContent.String()) } func (c *Client) writePump() {