diff --git a/backend/ai-core/internal/orchestrator/synthesizer.go b/backend/ai-core/internal/orchestrator/synthesizer.go index 1d5d438..431f247 100644 --- a/backend/ai-core/internal/orchestrator/synthesizer.go +++ b/backend/ai-core/internal/orchestrator/synthesizer.go @@ -87,32 +87,16 @@ func (s *Synthesizer) Synthesize(ctx context.Context, params SynthesizeParams, e args = make(map[string]interface{}) } + s.emitToolProgress(eventCh, tc.Name, "started", 0, "正在执行 "+tc.Name) s.emitToolProgress(eventCh, tc.Name, "started", 0, "正在执行 "+tc.Name) - toolCtx, cancel := context.WithTimeout(ctx, toolDeadline) - result, execErr := s.toolRegistry.Execute(toolCtx, tc.Name, args) - cancel() - - if execErr != nil { - logger.Printf("[synthesizer] 工具 %s 执行失败: %v", tc.Name, execErr) + // 工具调用全部异步执行,不阻塞主会话 + go s.executeAsyncAndStore(tc, args, params.SessionID, eventCh) + result := &plgSDK.ToolResult{ + ToolName: tc.Name, + Success: true, + Output: fmt.Sprintf("[后台执行中] %s 正在后台运行,结果稍后返回。", tc.Name), } - if result == nil { - result = &plgSDK.ToolResult{ToolName: tc.Name, Success: false, Error: execErr.Error()} - } - - // Async fallback: if tool timed out, store for next turn - if toolCtx.Err() == context.DeadlineExceeded { - s.emitToolProgress(eventCh, tc.Name, "running", 0.5, tc.Name+" 执行时间较长,转入后台继续...") - go s.executeAsyncAndStore(tc, args, params.SessionID, eventCh) - result = &plgSDK.ToolResult{ - ToolName: tc.Name, - Success: true, - Output: fmt.Sprintf("[后台执行中] %s 正在后台运行,结果将在下一轮对话中返回。你可以继续聊天。", tc.Name), - } - } else { - s.emitToolProgress(eventCh, tc.Name, "completed", 1.0, "") - } - resultJSON, _ := json.Marshal(result) messages = append(messages, model.LLMMessage{ Role: model.RoleTool,