AutoGPT: Use watchdog to mitigate empty commands

This commit is contained in:
Reinier van der Leer
2023-10-17 21:22:44 -07:00
parent 21a014790f
commit d617c3fa2f

View File

@@ -37,20 +37,28 @@ class WatchdogMixin:
WatchdogMixin, self WatchdogMixin, self
).propose_action(*args, **kwargs) ).propose_action(*args, **kwargs)
if ( if not self.config.big_brain and self.config.fast_llm != self.config.smart_llm:
not self.config.big_brain previous_command, previous_command_args = None, None
and len(self.event_history) > 1 if len(self.event_history) > 1:
and self.config.fast_llm != self.config.smart_llm # Detect repetitive commands
): previous_cycle = self.event_history.episodes[
# Detect repetitive commands self.event_history.cursor - 1
previous_cycle = self.event_history.episodes[self.event_history.cursor - 1] ]
if ( previous_command = previous_cycle.action.name
command_name == previous_cycle.action.name previous_command_args = previous_cycle.action.args
and command_args == previous_cycle.action.args
rethink_reason = ""
if not command_name:
rethink_reason = "AI did not specify a command"
elif (
command_name == previous_command
and command_args == previous_command_args
): ):
logger.info( rethink_reason = f"Repititive command detected ({command_name})"
f"Repetitive command detected ({command_name}), re-thinking with SMART_LLM..."
) if rethink_reason:
logger.info(f"{rethink_reason}, re-thinking with SMART_LLM...")
with ExitStack() as stack: with ExitStack() as stack:
@stack.callback @stack.callback