diff --git a/backend/ai-core/cmd/main.go b/backend/ai-core/cmd/main.go index 812c2df..1942afc 100644 --- a/backend/ai-core/cmd/main.go +++ b/backend/ai-core/cmd/main.go @@ -459,6 +459,15 @@ func main() { memExtractor, ) orch.SetToolRegistry(toolRegistry) + // 设置工具结果主动推送回调 — 通用,不绑定特定工具 + orch.SetToolResultPusher(func(sessionID, userID, toolName, result string) { + if thinker == nil { + return + } + // 通过 thinker 的主动消息机制推送 + thinker.TriggerReminderMessage(userID, sessionID, fmt.Sprintf("🔧 %s 执行完成:%s", toolName, result)) + }) + if visionProvider != nil { orch.SetVisionProvider(visionProvider) log.Printf("对话编排器: 视觉模型已注入 (%s)", visionProvider.ModelName()) diff --git a/backend/ai-core/internal/orchestrator/orchestrator.go b/backend/ai-core/internal/orchestrator/orchestrator.go index 4aefffe..740d208 100644 --- a/backend/ai-core/internal/orchestrator/orchestrator.go +++ b/backend/ai-core/internal/orchestrator/orchestrator.go @@ -82,6 +82,11 @@ func (o *Orchestrator) SetToolRegistry(tr *plgManager.ToolRegistry) { o.synthesizer.toolRegistry = tr } +// SetToolResultPusher sets the callback for proactive tool result delivery. +func (o *Orchestrator) SetToolResultPusher(pusher func(sessionID, userID, toolName, result string)) { + o.synthesizer.SetResultPusher(pusher) +} + // SetVisionProvider sets the vision model provider for image preprocessing. func (o *Orchestrator) SetVisionProvider(vp llm.LLMProvider) { o.visionProvider = vp diff --git a/backend/ai-core/internal/orchestrator/synthesizer.go b/backend/ai-core/internal/orchestrator/synthesizer.go index 431f247..3366fff 100644 --- a/backend/ai-core/internal/orchestrator/synthesizer.go +++ b/backend/ai-core/internal/orchestrator/synthesizer.go @@ -19,6 +19,7 @@ import ( type Synthesizer struct { llmAdapter *llm.Adapter toolRegistry *plgManager.ToolRegistry + resultPusher func(sessionID, userID, toolName, result string) } // NewSynthesizer 创建综合器 @@ -29,6 +30,11 @@ func NewSynthesizer(llmAdapter *llm.Adapter, toolRegistry *plgManager.ToolRegist } } +// SetResultPusher sets the callback for proactive tool result delivery. +func (s *Synthesizer) SetResultPusher(pusher func(sessionID, userID, toolName, result string)) { + s.resultPusher = pusher +} + // SynthesizeParams 综合参数 type SynthesizeParams struct { UserID string @@ -172,6 +178,10 @@ func (s *Synthesizer) executeAsyncAndStore(tc model.ToolCall, args map[string]in Success: result != nil && result.Success, }) } + // 主动推送工具结果 + if s.resultPusher != nil && result != nil && result.Success { + s.resultPusher(sessionID, "", tc.Name, string(resultJSON)) + } } // buildSynthesizeMessages 构建综合用的 LLM 消息列表