From f08fd2d9bbf8aca4e291e68de948be873fa71f3a Mon Sep 17 00:00:00 2001 From: Adrian Mohnacs <amohnacs@gmail.com> Date: Tue, 4 Jul 2023 15:35:57 +0700 Subject: [PATCH 1/5] Conditional statement expanded for errored API response Solved endless loop and hanging UI by extending our error catching by expanding conditional check to properties. --- .gitignore | 1 + superagi/agent/super_agi.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index ea17fbcbe..a6d6d6e99 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ venv workspace/output workspace/input ../bfg-report* +.vscode/settings.json diff --git a/superagi/agent/super_agi.py b/superagi/agent/super_agi.py index 700ab6024..54a4624d5 100644 --- a/superagi/agent/super_agi.py +++ b/superagi/agent/super_agi.py @@ -165,7 +165,7 @@ def execute(self, workflow_step: AgentWorkflowStep): total_tokens = current_tokens + TokenCounter.count_message_tokens(response, self.llm.get_model()) self.update_agent_execution_tokens(current_calls, total_tokens) - if response['content'] is None: + if 'content' not in response or response['content'] is None: raise RuntimeError(f"Failed to get response from llm") assistant_reply = response['content'] From cf2dcc38924b963c1c3a95757d25f3fcb0e49b79 Mon Sep 17 00:00:00 2001 From: Adrian Mohnacs <amohnacs@gmail.com> Date: Tue, 4 Jul 2023 15:43:34 +0700 Subject: [PATCH 2/5] Remove unneeded code from gitignore --- .gitignore | 1 - 1 file changed, 1 deletion(-) diff --git a/.gitignore b/.gitignore index a6d6d6e99..ea17fbcbe 100644 --- a/.gitignore +++ b/.gitignore @@ -16,4 +16,3 @@ venv workspace/output workspace/input ../bfg-report* -.vscode/settings.json From b89b7decad00f4c07a5ea8d081d4782da2ed6cf1 Mon Sep 17 00:00:00 2001 From: Adrian Mohnacs <amohnacs@gmail.com> Date: Tue, 4 Jul 2023 16:25:34 +0700 Subject: [PATCH 3/5] Catching errors to continue with retry backoff --- superagi/jobs/agent_executor.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/superagi/jobs/agent_executor.py b/superagi/jobs/agent_executor.py index 11c52a709..11419496a 100644 --- a/superagi/jobs/agent_executor.py +++ b/superagi/jobs/agent_executor.py @@ -203,7 +203,13 @@ def execute_next_action(self, agent_execution_id): agent_workflow_step = session.query(AgentWorkflowStep).filter( AgentWorkflowStep.id == agent_execution.current_step_id).first() - response = spawned_agent.execute(agent_workflow_step) + + try: + response = spawned_agent.execute(agent_workflow_step) + except RuntimeError as e: + # If our execution encounters an error we respond as an error and attempt to retry + response = { "result": "ERROR", "message": str(e) } + if "retry" in response and response["retry"]: response = spawned_agent.execute(agent_workflow_step) agent_execution.current_step_id = agent_workflow_step.next_step_id From 31f018ec17c832e1a9694f0fd71bdbd8e62a8691 Mon Sep 17 00:00:00 2001 From: Adrian Mohnacs <amohnacs@gmail.com> Date: Tue, 4 Jul 2023 16:39:52 +0700 Subject: [PATCH 4/5] simplifies return instead of creating bad object --- superagi/jobs/agent_executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superagi/jobs/agent_executor.py b/superagi/jobs/agent_executor.py index 11419496a..8399c5ba2 100644 --- a/superagi/jobs/agent_executor.py +++ b/superagi/jobs/agent_executor.py @@ -208,7 +208,7 @@ def execute_next_action(self, agent_execution_id): response = spawned_agent.execute(agent_workflow_step) except RuntimeError as e: # If our execution encounters an error we respond as an error and attempt to retry - response = { "result": "ERROR", "message": str(e) } + return if "retry" in response and response["retry"]: response = spawned_agent.execute(agent_workflow_step) From 2b7ae1fd21cfd677db284e6c1cef7279c8663d0b Mon Sep 17 00:00:00 2001 From: Adrian Mohnacs <amohnacs@gmail.com> Date: Tue, 4 Jul 2023 16:40:50 +0700 Subject: [PATCH 5/5] Quick update to documentation --- superagi/jobs/agent_executor.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/superagi/jobs/agent_executor.py b/superagi/jobs/agent_executor.py index 8399c5ba2..c44ec1d1f 100644 --- a/superagi/jobs/agent_executor.py +++ b/superagi/jobs/agent_executor.py @@ -207,7 +207,7 @@ def execute_next_action(self, agent_execution_id): try: response = spawned_agent.execute(agent_workflow_step) except RuntimeError as e: - # If our execution encounters an error we respond as an error and attempt to retry + # If our execution encounters an error we return and attempt to retry return if "retry" in response and response["retry"]: