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.
This commit is contained in:
Aska committed 2026-08-20 19:40:58 +08:00
1 parent 7c02d31194
commit cc040b861d
2 files changed
+12 -1

No files matched your search

+3 -1
View File
@@ -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})
}
+9
View File
@@ -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() {