Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

Fix Auto-GPT looping forever (#87)

merwanehamadib3c506cd943f
diff --git a/agbenchmark/agent_interface.py b/agbenchmark/agent_interface.py
index c737f30794..a1a79ada0a 100644
--- a/agbenchmark/agent_interface.py
+++ b/agbenchmark/agent_interface.py
@@ -42,35 +42,45 @@ def run_agent(
)
start_time = time.time()
- timeout = config["cutoff"]
- while True:
- if process.stdout is None:
- continue
+ print(
+ f"Running Python function '{config['entry_path']}' with timeout {config['cutoff']}"
+ )
+ command = [sys.executable, "-m", config["entry_path"], str(task)]
+ process = subprocess.Popen(
+ command,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.STDOUT,
+ universal_newlines=True,
+ )
- while output := process.stdout.readline():
- print(output.strip())
+ start_time = time.time()
- # Check if process has ended
- if process.poll() is not None:
- print("The Python function has finished running.")
- break
+ while True:
+ output = ""
+ if process.stdout is not None:
+ output = process.stdout.readline()
+ print(output.strip())
- # Check if process has exceeded timeout
- if time.time() - start_time > timeout:
- print(
- "The Python function has exceeded the time limit and was terminated."
- )
- # Terminate the process group
- process.terminate()
+ # Check if process has ended, has no more output, or exceeded timeout
+ if (
+ process.poll() is not None
+ or output == ""
+ or (time.time() - start_time > config["cutoff"])
+ ):
break
- # Optional: sleep for a while
- time.sleep(0.1)
+ if time.time() - start_time > config["cutoff"]:
+ print("The Python function has exceeded the time limit and was terminated.")
+ process.kill()
+ else:
+ print("The Python function has finished running.")
- # Wait for process to terminate, then get return code
process.wait()
+ if process.returncode != 0:
+ print(f"The agent timed out")
+
def copy_artifacts_into_workspace(
workspace: str, artifact_folder_name: str, challenge_dir_path: str
diff --git a/agent/Auto-GPT b/agent/Auto-GPT
index e5fbe4313e..d4fc134f8c 160000
--- a/agent/Auto-GPT
+++ b/agent/Auto-GPT
@@ -1 +1 @@
-Subproject commit e5fbe4313e0ebf7f75514a181a5d2044a7babd26
+Subproject commit d4fc134f8c4bd7b63f283f932f68932317f53f78