MCPcopy Create free account
hub / github.com/53AI/53AIHub / executeWorkflow

Function executeWorkflow

api/controller/relay/relay_workflow.go:156–220  ·  view source on GitHub ↗

executeWorkflow 执行工作流并返回标准响应数据

(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent)

Source from the content-addressed store, hash-verified

154
155// executeWorkflow 执行工作流并返回标准响应数据
156func executeWorkflow(c *gin.Context, workflowRequest *WorkflowRunRequest, agent *model.Agent) (*custom.WorkflowResponseData, error) {
157 // 允许空参数,归一化为 {}
158 if workflowRequest.Parameters == nil || len(workflowRequest.Parameters) == 0 {
159 workflowRequest.Parameters = map[string]interface{}{}
160 }
161
162 _, _, requestID := prepareDetachedExecutionContext(c, helper.GetRequestID(c.Request.Context()))
163 runCtx, runCancel := startAgentRunCancelWatcher(c.Request.Context(), agent.Eid, requestID, time.Second)
164 defer runCancel()
165 if c != nil && c.Request != nil {
166 c.Request = c.Request.WithContext(runCtx)
167 }
168
169 logger.SysLogf("工作流执行开始 - Model: %s, ConversationID: %d, Parameters: %+v",
170 workflowRequest.Model, workflowRequest.ConversationID, workflowRequest.Parameters)
171
172 modelName := agent.Model
173 // 获取渠道并检查/刷新token
174 logger.SysLogf("工作流执行 - 开始获取渠道,Eid: %d, ChannelType: %d, Model: %s",
175 agent.Eid, agent.ChannelType, modelName)
176
177 // 使用新的服务函数获取渠道并检查/刷新token
178 ctx := c.Request.Context()
179 channel, err := getAgentSpecificChannel(ctx, agent)
180 if err != nil {
181 return nil, fmt.Errorf("获取渠道失败,Eid: %d, ChannelType: %d, Model: %s, Error: %v",
182 agent.Eid, agent.ChannelType, modelName, err)
183 }
184 if channel == nil {
185 channel, err = service.GetChannelWithTokenRefresh(ctx, agent.Eid, agent.ChannelType, modelName, 0)
186 if err != nil {
187 providerID := agent.GetProviderID()
188 logger.SysLogf("尝试获取平台 ID %d", providerID)
189 // 如果是Coze渠道,尝试使用备用方法获取渠道(优先选择有Provider的Channel)
190 if agent.ChannelType == channeltype.Coze {
191 if providerID == 0 {
192 channel, err = model.GetFirstAvailableChannelByEidAndProviderType(agent.Eid, channeltype.Coze)
193 } else {
194 channel, err = model.GetFirstChannelByEidAndProviderType(agent.Eid, channeltype.Coze, providerID)
195 }
196
197 if err != nil || channel == nil {
198 return nil, fmt.Errorf("provider channel error")
199 }
200 channel.Models = channel.GetAddModelString(modelName)
201 err := model.DB.Updates(channel).Error
202 if err != nil {
203 return nil, fmt.Errorf("update channel error")
204 }
205 } else {
206 return nil, fmt.Errorf("获取渠道失败,Eid: %d, ChannelType: %d, Model: %s, Error: %v",
207 agent.Eid, agent.ChannelType, modelName, err)
208 }
209 }
210 }
211
212 logger.SysLogf("工作流执行 - 成功获取渠道,ChannelID: %d, BaseURL: %v",
213 channel.ChannelID, channel.BaseURL)

Callers 1

WorkflowRunFunction · 0.85

Calls 7

getAgentSpecificChannelFunction · 0.85
executeWorkflowDirectFunction · 0.85
ErrorfMethod · 0.80
GetProviderIDMethod · 0.80
GetAddModelStringMethod · 0.80

Tested by

no test coverage detected