feat: 异步工具结果主动推送 — 通用回调机制

- Synthesizer 新增 resultPusher 回调字段
- executeAsyncAndStore 完成后自动推送结果
- Orchestrator.SetToolResultPusher 透传
- 回调通用设计,不绑定特定工具

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-06-23 20:42:55 +08:00
parent 30d5b9b464
commit 01feb16262
3 changed files with 24 additions and 0 deletions
+9
View File
@@ -459,6 +459,15 @@ func main() {
memExtractor, memExtractor,
) )
orch.SetToolRegistry(toolRegistry) 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 { if visionProvider != nil {
orch.SetVisionProvider(visionProvider) orch.SetVisionProvider(visionProvider)
log.Printf("对话编排器: 视觉模型已注入 (%s)", visionProvider.ModelName()) log.Printf("对话编排器: 视觉模型已注入 (%s)", visionProvider.ModelName())
@@ -82,6 +82,11 @@ func (o *Orchestrator) SetToolRegistry(tr *plgManager.ToolRegistry) {
o.synthesizer.toolRegistry = tr 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. // SetVisionProvider sets the vision model provider for image preprocessing.
func (o *Orchestrator) SetVisionProvider(vp llm.LLMProvider) { func (o *Orchestrator) SetVisionProvider(vp llm.LLMProvider) {
o.visionProvider = vp o.visionProvider = vp
@@ -19,6 +19,7 @@ import (
type Synthesizer struct { type Synthesizer struct {
llmAdapter *llm.Adapter llmAdapter *llm.Adapter
toolRegistry *plgManager.ToolRegistry toolRegistry *plgManager.ToolRegistry
resultPusher func(sessionID, userID, toolName, result string)
} }
// NewSynthesizer 创建综合器 // 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 综合参数 // SynthesizeParams 综合参数
type SynthesizeParams struct { type SynthesizeParams struct {
UserID string UserID string
@@ -172,6 +178,10 @@ func (s *Synthesizer) executeAsyncAndStore(tc model.ToolCall, args map[string]in
Success: result != nil && result.Success, Success: result != nil && result.Success,
}) })
} }
// 主动推送工具结果
if s.resultPusher != nil && result != nil && result.Success {
s.resultPusher(sessionID, "", tc.Name, string(resultJSON))
}
} }
// buildSynthesizeMessages 构建综合用的 LLM 消息列表 // buildSynthesizeMessages 构建综合用的 LLM 消息列表