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 <polaris@Polaris.local> Co-authored-by: Reinier van der Leer <pwuts@agpt.co>pull/6872/head^2
parent
6cfe229332
commit
49a6d68200
|
@ -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(
|
||||
|
|
Loading…
Reference in New Issue