Skip to content

Commit c1ffae8

Browse files
committed
Minor fixes to Singul run
1 parent 9f6ce04 commit c1ffae8

File tree

2 files changed

+32
-18
lines changed

2 files changed

+32
-18
lines changed

ai.go

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ func getBadOutputString(action Action, appname, inputdata, outputBody string, st
916916
}
917917

918918
if len(param.Value) > 0 {
919-
outputParams += fmt.Sprintf("\"%s\": \"%s\", ", param.Name, param.Value)
919+
outputParams += fmt.Sprintf(" \"%s\": \"%s\", ", param.Name, param.Value)
920920
}
921921
}
922922

@@ -927,7 +927,7 @@ func getBadOutputString(action Action, appname, inputdata, outputBody string, st
927927
outputData := fmt.Sprintf("Fields: %s\n\nHTTP Status: %d\nHTTP error: %s", outputParams, status, outputBody)
928928

929929
if debug {
930-
log.Printf("[DEBUG] Skipping output formatting (bad output string)")
930+
log.Printf("[WARNING] Skipping automatic output formatting (bad output string). Is this necessary?")
931931
}
932932
//errorString := HandleOutputFormatting(string(outputData), inputdata, appname)
933933

@@ -1268,6 +1268,7 @@ func FixContentOutput(contentOutput string) string {
12681268
contentOutput = strings.Trim(contentOutput, "\n")
12691269
contentOutput = strings.Trim(contentOutput, "\t")
12701270

1271+
// Attempts to balance it automatically
12711272
contentOutput = balanceJSONLikeString(contentOutput)
12721273

12731274
return contentOutput
@@ -6568,7 +6569,7 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
65686569
}
65696570

65706571
// Create the OpenAI body struct
6571-
systemMessage := `You are a general AI agent which makes decisions based on user input. You should output a list of decisions based on the same input. Available actions within categories you can choose from are below. Only use built-in actions such as analyze (ai analysis) or ask (human analysis) if it is absolutely necessary. If you need to ask for input multiple times in a row, ask both questions at the same time. Only ask if the User context doesn't contain the details you need, AND the question isn't about networking or authentication.
6572+
systemMessage := `You are a general AI agent which makes decisions based on user input. You should output a list of decisions based on the same input. Available actions within categories you can choose from are below. Only use built-in actions such as analyze (ai analysis) or ask (human analysis) if it is absolutely necessary. Do NOT ask about networking or authentication unless explicitly specified.
65726573
65736574
# agent actions:
65746575
- ask
@@ -6732,13 +6733,11 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
67326733
- If a tool or app is mentioned, add it to the tool field. Otherwise make the field empty.
67336734
- Indexes should be the same if they should run in parallell.
67346735
- The confidence is between 0 and 1.
6735-
- Runs are how many times it should run requests (default: 1, * for all looped items).
67366736
- The {{action_name}} has to match EXACTLY the action name of a previous decision.
67376737
- NEVER add unnecessary fields to the fields array, only add the ones that are absolutely needed for the action to run!
6738-
- If you ask for user input, use the "ask" action and add a "question" field. Do NOT use this for authentication.
6739-
- Any answer to a question by the user is in the 'answer' variable for the same field. This is empty or non-existant by default.
67406738
- If you use the "API" action, make sure to fill the "tool". Additionally fill in "url", "method" and "body" fields.
6741-
- Do NOT add empty decisions for no reason.
6739+
- Any answer to a question by the user is in the 'answer' variable for the same decisions' field. This is empty or non-existant before the user has answered.
6740+
- If you ask for user input, use the "ask" action and add one or multiple "question" fields. Do NOT use this for authentication or networking. Make MULTIPLE questions in the same decisions' fields - NOT multiple separate decisions in a row. Do NOT ask the user about confirming obvious information, nor to clarify or other 'optional' questions. Make assumption for them!
67426741
67436742
# Decision Rules:
67446743
- NEVER ask for usernames, apikeys or other authentication information from the user.
@@ -6754,7 +6753,7 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
67546753
//Model: "gpt-4o-mini",
67556754
//Model: "gpt-4.1-mini",
67566755
//Model: "o4-mini", // "gpt-4o-mini" is the same as "4o-mini" in OpenAI API
6757-
Model: "gpt-5-nano", // "gpt-4o-mini" is the same as "4o-mini" in OpenAI API
6756+
Model: "gpt-5-mini", // "gpt-4o-mini" is the same as "4o-mini" in OpenAI API
67586757
Messages: []openai.ChatCompletionMessage{
67596758
{
67606759
Role: openai.ChatMessageRoleSystem,
@@ -6765,8 +6764,9 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
67656764
Content: userMessage,
67666765
},
67676766
},
6768-
//Temperature: 0.95, // Adds a tiny bit of randomness
6769-
Temperature: 1,
6767+
6768+
// Move towards determinism
6769+
Temperature: 0,
67706770

67716771
// json_object -> tends to want a single item and not an array
67726772
//ResponseFormat: &openai.ChatCompletionResponseFormat{
@@ -7174,6 +7174,14 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
71747174
additions += 1
71757175
}
71767176

7177+
b := make([]byte, 6)
7178+
_, err := rand.Read(b)
7179+
if err == nil {
7180+
mappedDecision.RunDetails.Id = base64.RawURLEncoding.EncodeToString(b)
7181+
} else {
7182+
log.Printf("[ERROR][%s] Failed generating random string for decision index %s-%d (2)", execution.ExecutionId, mappedDecision.Tool, mappedDecision.I)
7183+
}
7184+
71777185
agentOutput.Decisions = append(agentOutput.Decisions, mappedDecision)
71787186
}
71797187

@@ -7215,13 +7223,15 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
72157223
agentOutput.CompletedAt = time.Now().Unix()
72167224
}
72177225

7218-
if len(mappedDecisions) == 0 {
7219-
agentOutput.DecisionString = decisionString
7220-
}
7226+
if !createNextActions {
7227+
if len(mappedDecisions) == 0 {
7228+
agentOutput.DecisionString = decisionString
7229+
}
72217230

7222-
// Ensures we track them along the way
7223-
if len(parsedAgentInput) > 0 {
7224-
agentOutput.Input = parsedAgentInput
7231+
// Ensures we track them along the way
7232+
if len(parsedAgentInput) > 0 {
7233+
agentOutput.Input = parsedAgentInput
7234+
}
72257235
}
72267236

72277237
log.Printf("[INFO] Using LastFinishedIndex = %d", lastFinishedIndex)
@@ -7269,6 +7279,7 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
72697279
} else if decision.Action == "ask" || decision.Action == "question" {
72707280
agentOutput.Decisions[decisionIndex].RunDetails.StartedAt = time.Now().Unix()
72717281
agentOutput.Decisions[decisionIndex].RunDetails.Status = "RUNNING"
7282+
72727283
} else {
72737284
// Do we run the singul action directly?
72747285
agentOutput.Decisions[decisionIndex].RunDetails.StartedAt = time.Now().Unix()
@@ -7307,7 +7318,7 @@ func HandleAiAgentExecutionStart(execution WorkflowExecution, startNode Action,
73077318
// These aren't properly being updated in the db, so
73087319
// we need additional logic here to ensure it is being
73097320
// set/started
7310-
if nextActionType == "ask" {
7321+
if nextActionType == "ask" || nextActionType == "finish" {
73117322
// Ensure we update all of it
73127323
for resultIndex, result := range execution.Results {
73137324
if result.Action.ID != startNode.ID {
@@ -7631,6 +7642,9 @@ func RunAiQuery(systemMessage, userMessage string, incomingRequest ...openai.Cha
76317642
Messages: []openai.ChatCompletionMessage{},
76327643
MaxTokens: maxTokens,
76337644

7645+
// Move towards determinism
7646+
Temperature: 0,
7647+
76347648
// Needs overriding / control
76357649
// DRASTICALLY slows down requests
76367650
ReasoningEffort: "minimal",

structs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4521,7 +4521,7 @@ type AgentDecisionRunDetails struct {
45214521

45224522
StartedAt int64 `json:"started_at" datastore:"started_at"`
45234523
CompletedAt int64 `json:"completed_at" datastore:"completed_at"`
4524-
Type string `json:"type" datastore:"type"`
4524+
Type string `json:"type,omitempty" datastore:"type"`
45254525
Status string `json:"status" datastore:"status"`
45264526
RawResponse string `json:"raw_response,omitempty" datastore:"raw_response"`
45274527
DebugUrl string `json:"debug_url,omitempty" datastore:"debug_url"`

0 commit comments

Comments
 (0)