From 0bd776dde5614e4030a777913fddfb6b39b67424 Mon Sep 17 00:00:00 2001 From: Reinier van der Leer Date: Tue, 7 Nov 2023 16:48:54 -0600 Subject: [PATCH] fix: Prevent AutoGPT crashes when LLM does not use a command - Updated `agent.py` to check if `command_name` exists before registering an action in `event_history`. - Updated `agent_protocol_server.py` to handle the scenario when `execute_command` is not provided by LLM. - Updated `main.py` to check if `command_name` exists before executing the command and logging the result. --- autogpts/autogpt/autogpt/agents/agent.py | 13 +++++++------ .../autogpt/app/agent_protocol_server.py | 2 ++ autogpts/autogpt/autogpt/app/main.py | 17 ++++++++++------- 3 files changed, 19 insertions(+), 13 deletions(-) diff --git a/autogpts/autogpt/autogpt/agents/agent.py b/autogpts/autogpt/autogpt/agents/agent.py index 633c3e62..13275a4e 100644 --- a/autogpts/autogpt/autogpt/agents/agent.py +++ b/autogpts/autogpt/autogpt/agents/agent.py @@ -187,13 +187,14 @@ class Agent( NEXT_ACTION_FILE_NAME, ) - self.event_history.register_action( - Action( - name=command_name, - args=arguments, - reasoning=assistant_reply_dict["thoughts"]["reasoning"], + if command_name: + self.event_history.register_action( + Action( + name=command_name, + args=arguments, + reasoning=assistant_reply_dict["thoughts"]["reasoning"], + ) ) - ) return command_name, arguments, assistant_reply_dict diff --git a/autogpts/autogpt/autogpt/app/agent_protocol_server.py b/autogpts/autogpt/autogpt/app/agent_protocol_server.py index 84573edc..1426178f 100644 --- a/autogpts/autogpt/autogpt/app/agent_protocol_server.py +++ b/autogpts/autogpt/autogpt/app/agent_protocol_server.py @@ -226,6 +226,8 @@ class AgentProtocolServer: if execute_command == ask_user.__name__: # HACK execute_result = ActionSuccessResult(outputs=user_input) agent.event_history.register_result(execute_result) + elif not execute_command: + execute_result = None elif execute_approved: step = await self.db.update_step( task_id=task_id, diff --git a/autogpts/autogpt/autogpt/app/main.py b/autogpts/autogpt/autogpt/app/main.py index c974ae15..ff454e4d 100644 --- a/autogpts/autogpt/autogpt/app/main.py +++ b/autogpts/autogpt/autogpt/app/main.py @@ -556,14 +556,17 @@ async def run_interaction_loop( handle_stop_signal() - result = await agent.execute(command_name, command_args, user_input) + if command_name: + result = await agent.execute(command_name, command_args, user_input) - if result.status == "success": - logger.info(result, extra={"title": "SYSTEM:", "title_color": Fore.YELLOW}) - elif result.status == "error": - logger.warn( - f"Command {command_name} returned an error: {result.error or result.reason}" - ) + if result.status == "success": + logger.info( + result, extra={"title": "SYSTEM:", "title_color": Fore.YELLOW} + ) + elif result.status == "error": + logger.warn( + f"Command {command_name} returned an error: {result.error or result.reason}" + ) def update_user(