From 49a6d68200253116a081edd825b9e5f0bfa25850 Mon Sep 17 00:00:00 2001 From: Thunder Drag <74146396+ThunderDrag@users.noreply.github.com> Date: Tue, 20 Feb 2024 15:36:30 +0530 Subject: [PATCH] fix(agent/setup): Fix revising constraints and best practices (#6777) In a `for item in list` loop, removing items from the list while iterating causes it to skip over the next item. Fix: refactor `interactively_revise_ai_settings` routine to use while loop for iterating over constraints, resources, and best practices. --------- Co-authored-by: Kripanshu Jindal Co-authored-by: Reinier van der Leer --- autogpts/autogpt/autogpt/app/setup.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/autogpts/autogpt/autogpt/app/setup.py b/autogpts/autogpt/autogpt/app/setup.py index 8a271d26..df4e9436 100644 --- a/autogpts/autogpt/autogpt/app/setup.py +++ b/autogpts/autogpt/autogpt/app/setup.py @@ -89,7 +89,9 @@ async def interactively_revise_ai_settings( ) # Revise constraints - for i, constraint in enumerate(directives.constraints): + i = 0 + while i < len(directives.constraints): + constraint = directives.constraints[i] print_attribute(f"Constraint {i+1}:", f'"{constraint}"') new_constraint = ( await clean_input( @@ -99,11 +101,15 @@ async def interactively_revise_ai_settings( ) or constraint ) + if new_constraint == "-": directives.constraints.remove(constraint) + continue elif new_constraint: directives.constraints[i] = new_constraint + i += 1 + # Add new constraints while True: new_constraint = await clean_input( @@ -115,7 +121,9 @@ async def interactively_revise_ai_settings( directives.constraints.append(new_constraint) # Revise resources - for i, resource in enumerate(directives.resources): + i = 0 + while i < len(directives.resources): + resource = directives.resources[i] print_attribute(f"Resource {i+1}:", f'"{resource}"') new_resource = ( await clean_input( @@ -127,9 +135,12 @@ async def interactively_revise_ai_settings( ) if new_resource == "-": directives.resources.remove(resource) + continue elif new_resource: directives.resources[i] = new_resource + i += 1 + # Add new resources while True: new_resource = await clean_input( @@ -141,7 +152,9 @@ async def interactively_revise_ai_settings( directives.resources.append(new_resource) # Revise best practices - for i, best_practice in enumerate(directives.best_practices): + i = 0 + while i < len(directives.best_practices): + best_practice = directives.best_practices[i] print_attribute(f"Best Practice {i+1}:", f'"{best_practice}"') new_best_practice = ( await clean_input( @@ -153,9 +166,12 @@ async def interactively_revise_ai_settings( ) if new_best_practice == "-": directives.best_practices.remove(best_practice) + continue elif new_best_practice: directives.best_practices[i] = new_best_practice + i += 1 + # Add new best practices while True: new_best_practice = await clean_input(