diff --git a/autogpt/agent/agent.py b/autogpt/agent/agent.py index 4db9e2eea6c4..68888401913b 100644 --- a/autogpt/agent/agent.py +++ b/autogpt/agent/agent.py @@ -1,3 +1,5 @@ +import signal +import sys from datetime import datetime from colorama import Fore, Style @@ -88,6 +90,20 @@ def start_interaction_loop(self): arguments = None user_input = "" + # Signal handler for interrupting y -N + def signal_handler(signum, frame): + if self.next_action_count == 0: + sys.exit() + else: + print( + Fore.RED + + "Interrupt signal received. Stopping continuous command execution." + + Style.RESET_ALL + ) + self.next_action_count = 0 + + signal.signal(signal.SIGINT, signal_handler) + while True: # Discontinue if continuous limit is reached self.cycle_count += 1