From c04f2210cc3aa341d53b8e714f53a8927ab6b476 Mon Sep 17 00:00:00 2001 From: gravelBridge Date: Mon, 15 May 2023 20:02:33 -0700 Subject: [PATCH] Added feature to interrupt y -N continuous commands. (#4230) * Added feature to interrupt y -N continuous commands. * Fixed formatting. --------- Co-authored-by: Nicholas Tindle --- autogpt/agent/agent.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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