Skip to content

Commit 2952698

Browse files
committed
Added run_agent action
1 parent e0fb386 commit 2952698

File tree

3 files changed

+91
-20
lines changed

3 files changed

+91
-20
lines changed

shuffle-ai/1.0.0/src/app.py

Lines changed: 86 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,45 @@ def gpt(self, input_text):
427427
"reason": "Not implemented yet"
428428
}
429429

430+
def run_agent(self, input_data, actions=None, apps=None):
431+
prepared_format = {
432+
"id": self.action["id"],
433+
"params": {
434+
"tool_name": self.action["app_name"],
435+
"tool_id": self.action["app_id"],
436+
"environment": self.action["environment"],
437+
"input": {
438+
"text": input_data,
439+
}
440+
},
441+
}
442+
443+
if actions:
444+
prepared_format["params"]["tool_name"] = actions
445+
446+
if apps:
447+
pass
448+
449+
baseurl = f"{self.url}/api/v1/agent?execution_id={self.current_execution_id}&authorization={self.authorization}&action_id={self.action['id']}"
450+
self.logger.info("[DEBUG] Running agent action with URL '%s'" % (baseurl))
451+
452+
headers = {}
453+
request = requests.post(
454+
baseurl,
455+
json=prepared_format,
456+
headers=headers,
457+
)
458+
459+
# Random sleep timer to force delay
460+
time.sleep(2)
461+
# Gets into waiting state on backend
462+
return json.dumps({
463+
"app_run": True,
464+
"input_prompt": prepared_format,
465+
"status": request.status_code,
466+
"body": request.text,
467+
})
468+
430469
def run_schemaless(self, category, action, app_name="", fields=""):
431470
self.logger.info("[DEBUG] Running schemaless action with category '%s' and action label '%s'" % (category, action))
432471

@@ -477,27 +516,55 @@ def run_schemaless(self, category, action, app_name="", fields=""):
477516

478517
else:
479518
fields = str(fields).strip()
480-
if not fields.startswith("{") and not fields.startswith("["):
481-
fields = json.dumps({
482-
"data": fields,
483-
})
484-
485-
try:
486-
loadedfields = json.loads(fields)
487-
for key, value in loadedfields.items():
488-
data["fields"].append({
489-
"key": key,
490-
"value": value,
519+
# Valid format:
520+
# {"field1": "value1", "field2": "value2"}
521+
# field1=value1&field2=value2
522+
# field1:value1\nfield2:value2
523+
524+
cursplit = None
525+
if "\\n" in fields and not fields.startswith("{") and not fields.startswith("["):
526+
cursplit = "\\n"
527+
elif ("=" in fields or ":" in fields) and not fields.startswith("{") and not fields.startswith("["):
528+
cursplit = "&"
529+
530+
if cursplit:
531+
newfields = []
532+
for line in fields.split(cursplit):
533+
splitkey = None
534+
if "=" in line:
535+
splitkey = "="
536+
elif ":" in line:
537+
splitkey = ":"
538+
539+
if splitkey:
540+
parts = line.split(splitkey, 1)
541+
newfields.append({
542+
"key": parts[0].strip(),
543+
"value": splitkey.join(parts[1:]).strip(),
544+
})
545+
546+
data["fields"] = newfields
547+
else:
548+
if not fields.startswith("{") and not fields.startswith("["):
549+
fields = json.dumps({
550+
"data": fields,
491551
})
492552

493-
except Exception as e:
494-
self.logger.info("[ERROR] Failed to load fields as JSON: %s" % e)
495-
return json.dumps({
496-
"success": False,
497-
"reason": "Ensure 'Fields' are valid JSON",
498-
"details": "%s" % e,
499-
})
500-
553+
try:
554+
loadedfields = json.loads(fields)
555+
for key, value in loadedfields.items():
556+
data["fields"].append({
557+
"key": key,
558+
"value": value,
559+
})
560+
561+
except Exception as e:
562+
self.logger.info("[ERROR] Failed to load fields as JSON: %s" % e)
563+
return json.dumps({
564+
"success": False,
565+
"reason": "Ensure 'Fields' are valid JSON",
566+
"details": "%s" % e,
567+
})
501568

502569
#baseurl = "%s/api/v1/apps/categories/run" % self.base_url
503570
baseurl = "%s/api/v1/apps/categories/run" % self.url

shuffle-tools/1.2.0/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ json2xml==5.0.5
88
ipaddress==1.0.23
99
google.auth==2.37.0
1010
paramiko==3.5.0
11-
shuffle-sdk==0.0.31
11+
shuffle-sdk==0.0.33

shuffle-tools/1.2.0/src/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,10 @@ def send_email_shuffle(self, apikey, recipients, subject, body, attachments=""):
235235
def repeat_back_to_me(self, call):
236236
return call
237237

238+
def repeat_back_to_me2(self, body):
239+
print("call:", body)
240+
return body
241+
238242
def dedup_and_merge(self, key, value, timeout, set_skipped=True):
239243
timeout = int(timeout)
240244
key = str(key)

0 commit comments

Comments
 (0)