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.
This commit is contained in:
Reinier van der Leer
2023-11-07 16:48:54 -06:00
parent 25c6d019fe
commit 0bd776dde5
3 changed files with 19 additions and 13 deletions

View File

@@ -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

View File

@@ -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,

View File

@@ -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(