From 2c12d788c97db08719f66e9e276fdd005eb4a6fa Mon Sep 17 00:00:00 2001 From: Zvonimir Sabljic Date: Tue, 8 Aug 2023 12:51:43 +0200 Subject: [PATCH] A couple of changes in Developer Agent --- euclid/helpers/agents/CodeMonkey.py | 6 ++--- euclid/helpers/agents/Developer.py | 40 +++++++++++++++++++---------- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/euclid/helpers/agents/CodeMonkey.py b/euclid/helpers/agents/CodeMonkey.py index fb32e38..a9905ec 100644 --- a/euclid/helpers/agents/CodeMonkey.py +++ b/euclid/helpers/agents/CodeMonkey.py @@ -1,7 +1,5 @@ from const.function_calls import GET_FILES, DEV_STEPS, IMPLEMENT_CHANGES, CODE_CHANGES from helpers.files import update_file -from helpers.cli import run_command_until_success -from helpers.cli import build_directory_tree from helpers.AgentConvo import AgentConvo from helpers.Agent import Agent @@ -10,7 +8,7 @@ class CodeMonkey(Agent): super().__init__('code_monkey', project) self.developer = developer - def implement_code_changes(self, convo, code_changes_description, step_index): + def implement_code_changes(self, convo, code_changes_description, step_index=0): if convo == None: convo = AgentConvo(self) @@ -26,7 +24,7 @@ class CodeMonkey(Agent): "instructions": code_changes_description, "directory_tree": self.project.get_directory_tree(), "files": self.project.get_files(files_needed), - }, IMPLEMENT_CHANGES) + }, IMPLEMENT_CHANGES, True) for file_data in changes: update_file(self.project.get_full_file_path(file_data['name']), file_data['content']) diff --git a/euclid/helpers/agents/Developer.py b/euclid/helpers/agents/Developer.py index 86e5428..3d615f1 100644 --- a/euclid/helpers/agents/Developer.py +++ b/euclid/helpers/agents/Developer.py @@ -1,4 +1,5 @@ import json +import uuid from termcolor import colored from utils.utils import step_already_finished from helpers.agents.CodeMonkey import CodeMonkey @@ -33,7 +34,7 @@ class Developer(Agent): def implement_task(self, sibling_tasks, current_task_index, parent_task=None): print(colored('-------------------------', 'green')) print(colored(f"Implementing task {current_task_index + 1}...\n", "green")) - print(sibling_tasks[current_task_index]['description']) + print(colored(sibling_tasks[current_task_index]['description'], 'green')) print(colored('-------------------------', 'green')) convo_dev_task = AgentConvo(self) task_steps = convo_dev_task.send_message('development/task/breakdown.prompt', { @@ -52,32 +53,40 @@ class Developer(Agent): self.execute_task(convo_dev_task, task_steps) - def execute_task(self, convo, task_steps, test_command=None, reset_convo=True): - convo.save_branch('after_task_breakdown') + def execute_task(self, convo, task_steps, test_command=None, reset_convo=True, test_after_code_changes=True): + function_uuid = str(uuid.uuid4()) + convo.save_branch(function_uuid) for (i, step) in enumerate(task_steps): if reset_convo: - convo.load_branch('after_task_breakdown') + convo.load_branch(function_uuid) if step['type'] == 'command': - run_command_until_success(step['command'], step['command_timeout'], convo) + run_command_until_success(step['command']['command'], step['command']['timeout'], convo) elif step['type'] == 'code_change': print(f'Implementing code changes for `{step["code_change_description"]}`') code_monkey = CodeMonkey(self.project, self) updated_convo = code_monkey.implement_code_changes(convo, step['code_change_description'], i) - self.test_code_changes(code_monkey, updated_convo) + if test_after_code_changes: + self.test_code_changes(code_monkey, updated_convo) elif step['type'] == 'human_intervention': self.project.ask_for_human_intervention('I need your help! Can you try debugging this yourself and let me take over afterwards? Here are the details about the issue:', step['human_intervention_description']) - - else: - raise Exception('Step type must be either run_command or code_change.') if test_command is not None and step['check_if_fixed']: - response = execute_command_and_check_cli_response(test_command['command'], test_command['timeout'], convo) - if response == 'DONE': + should_rerun_command = convo.send_message('dev_ops/should_rerun_command.prompt', + test_command) + if should_rerun_command == 'NO': return True + elif should_rerun_command == 'YES': + response = execute_command_and_check_cli_response(test_command['command'], test_command['timeout'], convo) + if response == 'NEEDS_DEBUGGING': + print(colored(f'Got incorrect CLI response:', 'red')) + print(response) + print(colored('-------------------', 'red')) + if response == 'DONE': + return True def set_up_environment(self): self.project.current_step = 'environment_setup' @@ -140,7 +149,10 @@ class Developer(Agent): # ENVIRONMENT SETUP END def test_code_changes(self, code_monkey, convo): - (test_type, command, automated_test_description, manual_test_description) = convo.send_message('development/task/step_check.prompt', {}, GET_TEST_TYPE) + (test_type, command, automated_test_description, manual_test_description) = convo.send_message( + 'development/task/step_check.prompt', + {}, + GET_TEST_TYPE) if test_type == 'command_test': run_command_until_success(command['command'], command['timeout'], convo) @@ -148,10 +160,12 @@ class Developer(Agent): code_monkey.implement_code_changes(convo, automated_test_description, 0) elif test_type == 'manual_test': # TODO make the message better - self.project.ask_for_human_intervention( + response = self.project.ask_for_human_intervention( 'Message from Euclid: I need your help. Can you please test if this was successful?', manual_test_description ) + if response is not None and response != 'DONE': + self.test_code_changes(code_monkey, convo) def implement_step(self, convo, step_index, type, description): # TODO remove hardcoded folder path