feat: 异步工具结果主动推送 — 通用回调机制
- Synthesizer 新增 resultPusher 回调字段 - executeAsyncAndStore 完成后自动推送结果 - Orchestrator.SetToolResultPusher 透传 - 回调通用设计,不绑定特定工具 Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 消息列表
|
||||
|
||||
Reference in New Issue
Block a user