mirror of
https://github.com/aljazceru/Auto-GPT.git
synced 2025-12-24 17:34:24 +01:00
Fix Auto-GPT looping forever (#87)
This commit is contained in:
@@ -42,35 +42,45 @@ def run_agent(
|
||||
)
|
||||
|
||||
start_time = time.time()
|
||||
timeout = config["cutoff"]
|
||||
|
||||
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,
|
||||
)
|
||||
|
||||
start_time = time.time()
|
||||
|
||||
while True:
|
||||
if process.stdout is None:
|
||||
continue
|
||||
|
||||
while output := process.stdout.readline():
|
||||
output = ""
|
||||
if process.stdout is not None:
|
||||
output = process.stdout.readline()
|
||||
print(output.strip())
|
||||
|
||||
# Check if process has ended
|
||||
if process.poll() is not None:
|
||||
print("The Python function has finished running.")
|
||||
# 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
|
||||
|
||||
# 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()
|
||||
break
|
||||
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.")
|
||||
|
||||
# Optional: sleep for a while
|
||||
time.sleep(0.1)
|
||||
|
||||
# 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
|
||||
|
||||
Submodule agent/Auto-GPT updated: e5fbe4313e...d4fc134f8c
Reference in New Issue
Block a user