Skip to content

Commit a24dc2e

Browse files
committed
Started making question/ask for agents work standalone
1 parent 5d4cc75 commit a24dc2e

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

ai.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -316,8 +316,9 @@ func DecryptKMS(ctx context.Context, auth AppAuthenticationStorage, key, authori
316316
req.Header.Set("Authorization", fmt.Sprintf("Bearer %s", authorization))
317317
}
318318

319+
// Proper timeout
319320
client := &http.Client{
320-
Timeout: time.Second * 60,
321+
Timeout: time.Second * 300,
321322
}
322323
resp, err := client.Do(req)
323324
if err != nil {
@@ -692,7 +693,9 @@ func RunSelfCorrectingRequest(action Action, status int, additionalInfo, outputB
692693

693694
// Check if the amount of {} in inputBody is the same
694695
if strings.Count(inputBody, "{") != strings.Count(inputBody, "}") {
695-
log.Printf("[ERROR] Input body has mismatched curly braces. Fixing it. InputBody: %s", inputBody)
696+
if debug {
697+
log.Printf("[ERROR] Debug: Input body has mismatched curly braces ({*%d vs }*%d). Fixing it. InputBody pre-fix: %s", strings.Count(inputBody, "{"), strings.Count(inputBody, "}"), inputBody)
698+
}
696699

697700
// FIXME: Doesn't take into account key vs value, as it shouldn't change the value.
698701
if strings.Count(inputBody, "{") > strings.Count(inputBody, "}") {
@@ -4940,7 +4943,7 @@ func workerPool(jobs <-chan openai.ToolCall, results chan<- AtomicOutput, wg *sy
49404943
req.Header.Set("Authorization", "Bearer "+user.ApiKey)
49414944

49424945
client := &http.Client{
4943-
Timeout: time.Second * 60,
4946+
Timeout: time.Second * 300,
49444947
}
49454948
resp, err := client.Do(req)
49464949
if err != nil {
@@ -6338,8 +6341,9 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action)
63386341
// Metadata = org-specific context
63396342
// This e.g. makes "me" mean "users in my org" and such
63406343
metadata := ""
6344+
63416345
if len(execution.Workflow.UpdatedBy) > 0 {
6342-
metadata += fmt.Sprintf("Current person: %s\n", execution.Workflow.UpdatedBy)
6346+
metadata += fmt.Sprintf("Current user: %s\n", execution.Workflow.UpdatedBy)
63436347
}
63446348

63456349
if len(execution.Workflow.OrgId) == 0 && len(execution.ExecutionOrg) > 0 {
@@ -7317,6 +7321,9 @@ func GenerateSingulWorkflows(resp http.ResponseWriter, request *http.Request) {
73177321
}
73187322

73197323
// This can also be overridden by passing in a custom OpenAI ChatCompletion request
7324+
// FIXME: We need some kind of failover for this so that the request
7325+
// doesn't go from Backend directly, but instead from app. This makes it
7326+
// more versatile in general, and able to run from Onprem -> Local model
73207327
func RunAiQuery(systemMessage, userMessage string, incomingRequest ...openai.ChatCompletionRequest) (string, error) {
73217328
cnt := 0
73227329
maxTokens := 5000

shared.go

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19654,11 +19654,13 @@ func PrepareSingleAction(ctx context.Context, user User, appId string, body []by
1965419654

1965519655
OrgId: user.ActiveOrg.Id,
1965619656
Owner: user.Username,
19657+
UpdatedBy: user.Username,
1965719658
Start: action.ID,
1965819659
},
1965919660
Type: "AGENT",
1966019661
Start: action.ID,
1966119662
Status: "EXECUTING",
19663+
WorkflowId: workflowId,
1966219664
ExecutionId: workflowId,
1966319665
ExecutionOrg: user.ActiveOrg.Id,
1966419666
StartedAt: int64(time.Now().Unix()),
@@ -19842,7 +19844,7 @@ func PrepareSingleAction(ctx context.Context, user User, appId string, body []by
1984219844

1984319845
if len(action.AuthenticationId) > 0 {
1984419846
if debug {
19845-
log.Printf("[INFO][%s] Found auth ID for single action: %s", workflowExecution.ExecutionId, action.AuthenticationId)
19847+
log.Printf("[DEBUG][%s] Found auth ID for single action: %s", workflowExecution.ExecutionId, action.AuthenticationId)
1984619848
}
1984719849

1984819850
// FIXME: How do we decide what fields to replace?
@@ -23153,6 +23155,22 @@ func PrepareWorkflowExecution(ctx context.Context, workflow Workflow, request *h
2315323155
}
2315423156
}
2315523157

23158+
agentic := false
23159+
if len(start) == 0 && request != nil {
23160+
decisionId, decisionIdOk := request.URL.Query()["decision_id"]
23161+
if decisionIdOk {
23162+
log.Printf("[INFO][%s] Got decisionId %s inside Agentic decision", oldExecution.ExecutionId, decisionId[0])
23163+
23164+
agentic = true
23165+
if len(workflow.Actions) == 1 {
23166+
start = append(start, workflow.Actions[0].ID)
23167+
oldExecution.Results[0].Status = "WAITING"
23168+
} else {
23169+
log.Printf("[ERROR] No Agentic Start node found for workflow %s during workflow continuation. Decision ID: %s", workflow.ID, decisionId[0])
23170+
}
23171+
}
23172+
}
23173+
2315623174
if len(start) == 0 {
2315723175
log.Printf("[ERROR] No start node found for workflow %s during workflow continuation", workflow.ID)
2315823176
return workflowExecution, ExecInfo{}, fmt.Sprintf("No start node found for workflow continuation %s", workflow.ID), errors.New("No start node found for workflow continuation")
@@ -23164,7 +23182,7 @@ func PrepareWorkflowExecution(ctx context.Context, workflow Workflow, request *h
2316423182
for _, result := range oldExecution.Results {
2316523183
if result.Action.ID == start[0] {
2316623184
if result.Status == "ABORTED" {
23167-
log.Printf("[INFO] Found aborted result: %s (%s)", result.Action.Label, result.Action.ID)
23185+
log.Printf("[INFO][%s] Found aborted result: %s (%s)", oldExecution.ExecutionId, result.Action.Label, result.Action.ID)
2316823186
if oldExecution.Status != "ABORTED" {
2316923187
log.Printf("[INFO] Aborting execution %s as it should have already been aborted in the past", oldExecution.ExecutionId)
2317023188
oldExecution.Status = "ABORTED"
@@ -23176,7 +23194,11 @@ func PrepareWorkflowExecution(ctx context.Context, workflow Workflow, request *h
2317623194
}
2317723195
}
2317823196

23179-
if result.Status == "WAITING" {
23197+
if agentic {
23198+
log.Printf("[INFO][%s] Should fix the decision by injecting the values and continuing to the next step! :3", oldExecution.ExecutionId)
23199+
//os.Exit(3)
23200+
23201+
} else if result.Status == "WAITING" && !agentic {
2318023202
log.Printf("[INFO][%s] Found relevant User Input result: %s (%s)", result.ExecutionId, result.Action.Label, result.Action.ID)
2318123203

2318223204
var userinputResp UserInputResponse

structs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,9 @@ type WorkflowAppActionParameter struct {
260260
type Valuereplace struct {
261261
Key string `json:"key" datastore:"key" yaml:"key"`
262262
Value string `json:"value" datastore:"value,noindex" yaml:"value"`
263+
264+
// Used for e.g. user input storage
265+
Answer string `json:"details,omitempty" datastore:"details,noindex" yaml:"details,omitempty"`
263266
}
264267

265268
type WorkflowAppAction struct {

0 commit comments

Comments
 (0)