@@ -43,7 +43,6 @@ import (
4343var standalone bool
4444
4545// var model = "gpt-5-mini"
46- var maxTokens = 5000
4746var model = "gpt-5-mini"
4847//var model = "gpt-5.2-codex"
4948
@@ -52,7 +51,7 @@ var assistantId = os.Getenv("OPENAI_ASSISTANT_ID")
5251var docsVectorStoreID = os .Getenv ("OPENAI_DOCS_VS_ID" )
5352var assistantModel = model
5453
55- var aiMaxTokens = 1024 // Default for on-prem
54+ var aiMaxTokens = 4096 // Controllable with AI_MAX_TOKENS env
5655var aiReasoningEffort = ""
5756
5857func init () {
@@ -61,7 +60,11 @@ func init() {
6160 aiMaxTokens = t
6261 }
6362 }
64- aiReasoningEffort = os .Getenv ("AI_REASONING_EFFORT" )
63+
64+ reasoningEffort := os .Getenv ("AI_REASONING_EFFORT" )
65+ if reasoningEffort == "minimal" || reasoningEffort == "low" || reasoningEffort == "medium" || reasoningEffort == "high" {
66+ aiReasoningEffort = reasoningEffort
67+ }
6568}
6669
6770// Provide an incident triage and response plan for the reported incident finding. Make a short list of actions to perform in the following format: [{"title": "Title of the task", "category": "triage/containment/recovery/communication/documentation", "completed": false, "createdBy": "ai-agent@shuffler.io"}]. ONLY output as JSON array and nothing more. After the list is made, add these to the metadata.extensions.custom_attributes.tasks[] in the next action.
@@ -866,7 +869,7 @@ Input JSON Payload (ensure VALID JSON):
866869 Content : inputData ,
867870 },
868871 },
869- MaxCompletionTokens : maxTokens ,
872+ MaxCompletionTokens : aiMaxTokens ,
870873 Temperature : 0 ,
871874 ReasoningEffort : "low" ,
872875 }
@@ -2002,7 +2005,7 @@ Do not add explanations, comments, or extra formatting. Only return valid JSON.`
20022005 Content : userMessage ,
20032006 },
20042007 },
2005- MaxCompletionTokens : maxTokens ,
2008+ MaxCompletionTokens : aiMaxTokens ,
20062009 Temperature : 0 ,
20072010 ReasoningEffort : "medium" ,
20082011 }
@@ -2203,6 +2206,21 @@ Do not add explanations, comments, or extra formatting. Only return valid JSON.`
22032206}
22042207
22052208func GetActionAIResponse (ctx context.Context , resp http.ResponseWriter , user User , org Org , outputFormat string , input QueryInput ) ([]byte , error ) {
2209+ if len (org .Id ) == 0 {
2210+ if len (input .OrgId ) > 0 && user .ActiveOrg .Id == "" {
2211+ user .ActiveOrg .Id = input .OrgId
2212+ }
2213+
2214+ if len (user .ActiveOrg .Id ) > 0 {
2215+ newOrg , err := GetOrg (ctx , user .ActiveOrg .Id )
2216+ if err != nil {
2217+ log .Printf ("[ERROR] Failed to load orgid '%s' in ai response check" , user .ActiveOrg .Id )
2218+ } else {
2219+ org = * newOrg
2220+ }
2221+ }
2222+ }
2223+
22062224 standalone := false
22072225 standaloneEnv := os .Getenv ("STANDALONE" )
22082226 if standaloneEnv == "true" {
@@ -2212,7 +2230,9 @@ func GetActionAIResponse(ctx context.Context, resp http.ResponseWriter, user Use
22122230 respBody := []byte {}
22132231 if project .Environment == "cloud" && ! user .SupportAccess {
22142232 //if org.SyncFeatures.ShuffleGPT.Active && org.SyncFeatures.ShuffleGPT.Usage < org.SyncFeatures.ShuffleGPT.Limit {
2215- if org .SyncFeatures .ShuffleGPT .Usage < 100 {
2233+
2234+ // Most should never reach this
2235+ if org .SyncFeatures .ShuffleGPT .Usage < 1000 {
22162236 log .Printf ("[AUDIT] Org %#v (%s) has access to the auto feature. Allowing user %s to use it" , org .Name , org .Id , user .Username )
22172237 org .SyncFeatures .ShuffleGPT .Usage += 1
22182238
@@ -3757,7 +3777,7 @@ func findActionByInput(inputQuery, actionLabel string, foundApp WorkflowApp) (st
37573777 return contentOutput , nil
37583778}
37593779
3760- // Context aware parameter mapping
3780+ // Context aware parameter mapping per org-app-action
37613781func getSelectedAppParameters (ctx context.Context , user User , selectedAction WorkflowAppAction , foundApp WorkflowApp , appname , category , outputFormat string , httpOutput HTTPWrapper , input QueryInput ) (WorkflowAppAction , error ) {
37623782
37633783 inputQuery := input .Query
@@ -3985,7 +4005,7 @@ func getSelectedAppParameters(ctx context.Context, user User, selectedAction Wor
39854005 } else {
39864006 // Since we are trying to fill them in anyway :)
39874007 if len (sampleBody ) == 0 {
3988- log .Printf ("[INFO] No matching body found for app %s with action %s. Err: %s" , appname , selectedAction .Name , err )
4008+ log .Printf ("[INFO] No matching body found for app %s with action %s. Err: %s. Body: '%s' " , appname , selectedAction .Name , err , outputBody )
39894009 sampleBody = formattedFields
39904010 }
39914011 }
@@ -8875,7 +8895,7 @@ func RunAiQuery(systemMessage, userMessage string, incomingRequest ...openai.Cha
88758895 chatCompletion := openai.ChatCompletionRequest {
88768896 Model : model ,
88778897 Messages : []openai.ChatCompletionMessage {},
8878- MaxTokens : maxTokens ,
8898+ MaxTokens : aiMaxTokens ,
88798899
88808900 // Move towards determinism
88818901 Temperature : 0 ,
@@ -8991,7 +9011,7 @@ func RunAiQuery(systemMessage, userMessage string, incomingRequest ...openai.Cha
89919011
89929012 if strings .Contains (err .Error (), "not supported MaxTokens" ) {
89939013 chatCompletion .MaxTokens = 0
8994- chatCompletion .MaxCompletionTokens = maxTokens
9014+ chatCompletion .MaxCompletionTokens = aiMaxTokens
89959015 continue
89969016 } else if strings .Contains (err .Error (), "does not exist" ) {
89979017 if len (fallbackModel ) == 0 {
@@ -10268,7 +10288,7 @@ No other formats are allowed. Just structured steps.
1026810288Produce a minimal, correct, atomic plan for turning vague security workflows into structured actions. Do not overthink. Follow the format exactly, Including the headings.
1026910289` , categoryString )
1027010290
10271- maxTokens := 5000
10291+ aiMaxTokens := 5000
1027210292 var contentOutput string
1027310293 var err error
1027410294
@@ -10303,7 +10323,7 @@ Produce a minimal, correct, atomic plan for turning vague security workflows int
1030310323
1030410324 if model == "o4-mini" || model == "gpt-5-mini" {
1030510325 chatCompletion .MaxTokens = 0
10306- chatCompletion .MaxCompletionTokens = maxTokens
10326+ chatCompletion .MaxCompletionTokens = aiMaxTokens
1030710327 }
1030810328
1030910329 contentOutput , err = RunAiQuery ("" , "" , chatCompletion )
0 commit comments