AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.
AutoGPT: Fix error handling in `AgentProtocolServer.execute_step`
Reinier van der Leer8dbcdc28ed02
diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.pyindex 00c41640ae..e69fdfdfc4 100644--- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py+++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py@@ -4,6 +4,7 @@ import pathlibfrom io import BytesIOfrom uuid import uuid4+import orjsonfrom fastapi import APIRouter, FastAPI, UploadFilefrom fastapi.middleware.cors import CORSMiddlewarefrom fastapi.responses import RedirectResponse, StreamingResponse@@ -33,7 +34,7 @@ from autogpt.commands.user_interaction import ask_userfrom autogpt.config import Configfrom autogpt.core.resource.model_providers import ChatModelProviderfrom autogpt.file_workspace import FileWorkspace-from autogpt.models.action_history import ActionSuccessResult+from autogpt.models.action_history import ActionErrorResult, ActionSuccessResultlogger = logging.getLogger(__name__)@@ -239,7 +240,17 @@ class AgentProtocolServer:)# Propose next action- next_command, next_command_args, raw_output = await agent.propose_action()+ try:+ next_command, next_command_args, raw_output = await agent.propose_action()+ logger.debug(f"AI output: {raw_output}")+ except Exception as e:+ step = await self.db.update_step(+ task_id=task_id,+ step_id=step.step_id,+ status="completed",+ output=f"An error occurred while proposing the next action: {e}",+ )+ return step# Format step outputoutput = (@@ -263,7 +274,14 @@ class AgentProtocolServer:"last_action": {"name": execute_command,"args": execute_command_args,- "result": execute_result.dict(),+ "result": (+ orjson.loads(execute_result.json())+ if not isinstance(execute_result, ActionErrorResult)+ else {+ "error": str(execute_result.error),+ "reason": execute_result.reason,+ }+ ),},}if not is_init_step