mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2026-02-06 14:54:40 +01:00
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:
@@ -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
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user