Merge pull request #1940 from satti-hari-krishna-reddy/nightly
feat(worker): Enable AI Agent App Support in Hybrid Mode
This commit is contained in:
@@ -1498,11 +1498,77 @@ func handleExecutionResult(workflowExecution shuffle.WorkflowExecution) {
|
|||||||
action, _ = singul.HandleSingulStartnode(workflowExecution, action, []string{})
|
action, _ = singul.HandleSingulStartnode(workflowExecution, action, []string{})
|
||||||
|
|
||||||
parsedAppname := strings.Replace(strings.ToLower(action.AppName), " ", "-", -1)
|
parsedAppname := strings.Replace(strings.ToLower(action.AppName), " ", "-", -1)
|
||||||
//if strings.ToLower(parsedAppname) == "singul" {
|
// if strings.ToLower(parsedAppname) == "singul" {
|
||||||
// parsedAppname = "shuffle-ai"
|
// parsedAppname = "shuffle-ai"
|
||||||
// appversion = "1.0.0"
|
// appversion = "1.0.0"
|
||||||
// appname = "shuffle-ai"
|
// appname = "shuffle-ai"
|
||||||
//}
|
// }
|
||||||
|
|
||||||
|
if parsedAppname == "ai-agent" {
|
||||||
|
log.Printf("[INFO][%s] Running AI Agent action %s via backend API", workflowExecution.ExecutionId, action.ID)
|
||||||
|
|
||||||
|
fullUrl := fmt.Sprintf("%s/api/v1/agent?execution_id=%s&authorization=%s&action_id=%s",
|
||||||
|
baseUrl, workflowExecution.ExecutionId, workflowExecution.Authorization, action.ID)
|
||||||
|
|
||||||
|
serverUrl := os.Getenv("SHUFFLE_BACKEND_URL")
|
||||||
|
if len(serverUrl) > 0 {
|
||||||
|
fullUrl = fmt.Sprintf("%s/api/v1/agent?execution_id=%s&authorization=%s&action_id=%s",
|
||||||
|
serverUrl, workflowExecution.ExecutionId, workflowExecution.Authorization, action.ID)
|
||||||
|
}
|
||||||
|
|
||||||
|
inputParamValue := ""
|
||||||
|
for _, param := range action.Parameters {
|
||||||
|
if strings.ToLower(param.Name) == "input" {
|
||||||
|
inputParamValue = param.Value
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBody := map[string]interface{}{
|
||||||
|
"id": action.ID,
|
||||||
|
"params": map[string]interface{}{
|
||||||
|
"tool_name": action.AppName,
|
||||||
|
"tool_id": action.AppID,
|
||||||
|
"environment": action.Environment,
|
||||||
|
"input": map[string]interface{}{
|
||||||
|
"text": inputParamValue,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
requestBodyBytes, err := json.Marshal(requestBody)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR][%s] Failed marshalling request body: %s", workflowExecution.ExecutionId, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
req, err := http.NewRequest("POST", fullUrl, bytes.NewBuffer(requestBodyBytes))
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR][%s] Failed creating AI Agent request: %s", workflowExecution.ExecutionId, err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
req.Header.Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
client := &http.Client{Timeout: 10 * time.Second}
|
||||||
|
resp, err := client.Do(req)
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("[ERROR][%s] Failed triggering AI Agent (timeout/error): %s", workflowExecution.ExecutionId, err)
|
||||||
|
log.Printf("[INFO][%s] Exiting execution handler - backend will requeue when agent completes", workflowExecution.ExecutionId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
defer resp.Body.Close()
|
||||||
|
// body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
// if err != nil {
|
||||||
|
// log.Printf("[ERROR][%s] Failed reading AI Agent response: %s", workflowExecution.ExecutionId, err)
|
||||||
|
// } else {
|
||||||
|
// log.Printf("[INFO][%s] AI Agent triggered: %s", workflowExecution.ExecutionId, string(body))
|
||||||
|
// }
|
||||||
|
|
||||||
|
log.Printf("[INFO][%s] AI Agent triggered successfully - exiting execution handler, backend will requeue when agent completes", workflowExecution.ExecutionId)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
imageName := fmt.Sprintf("%s:%s_%s", baseimagename, parsedAppname, action.AppVersion)
|
imageName := fmt.Sprintf("%s:%s_%s", baseimagename, parsedAppname, action.AppVersion)
|
||||||
if strings.Contains(imageName, " ") {
|
if strings.Contains(imageName, " ") {
|
||||||
|
|||||||
Reference in New Issue
Block a user