diff --git a/pilot/helpers/Debugger.py b/pilot/helpers/Debugger.py new file mode 100644 index 0000000..8117bde --- /dev/null +++ b/pilot/helpers/Debugger.py @@ -0,0 +1,75 @@ +import uuid + +from const.code_execution import MAX_COMMAND_DEBUG_TRIES, MAX_RECUSION_LAYER +from const.function_calls import DEBUG_STEPS_BREAKDOWN +from helpers.exceptions.TokenLimitError import TokenLimitError +from helpers.exceptions.TooDeepRecursionError import TooDeepRecursionError + + +class Debugger(): + def __init__(self, agent): + self.agent = agent + self.recursion_layer = 0 + + def debug(self, convo, command=None, user_input=None, issue_description=None, is_root_task=False): + """ + Debug a conversation. + + Args: + convo (AgentConvo): The conversation object. + command (dict, optional): The command to debug. Default is None. + user_input (str, optional): User input for debugging. Default is None. + issue_description (str, optional): Description of the issue to debug. Default is None. + + Returns: + bool: True if debugging was successful, False otherwise. + """ + + self.recursion_layer += 1 + if self.recursion_layer > MAX_RECUSION_LAYER: + raise TooDeepRecursionError() + + function_uuid = str(uuid.uuid4()) + convo.save_branch(function_uuid) + success = False + + for i in range(MAX_COMMAND_DEBUG_TRIES): + if success: + break + + convo.load_branch(function_uuid) + + debugging_plan = convo.send_message('dev_ops/debug.prompt', + { 'command': command['command'] if command is not None else None, 'user_input': user_input, 'issue_description': issue_description }, + DEBUG_STEPS_BREAKDOWN) + + try: + # TODO refactor to nicely get the developer agent + response = self.agent.project.developer.execute_task( + convo, + debugging_plan, + command, + test_after_code_changes=True, + continue_development=False, + is_root_task=is_root_task) + success = response['success'] + except TokenLimitError as e: + if self.recursion_layer > 0: + self.recursion_layer -= 1 + raise e + else: + continue + + # if not success: + # # TODO explain better how should the user approach debugging + # # we can copy the entire convo to clipboard so they can paste it in the playground + # user_input = convo.agent.project.ask_for_human_intervention( + # 'It seems like I cannot debug this problem by myself. Can you please help me and try debugging it yourself?' if user_input is None else f'Can you check this again:\n{issue_description}?', + # response['data'] + # ) + + # if user_input == 'continue': + # success = True + + self.recursion_layer -= 1 + return response diff --git a/pilot/helpers/exceptions/TooDeepRecursionError.py b/pilot/helpers/exceptions/TooDeepRecursionError.py new file mode 100644 index 0000000..89aa665 --- /dev/null +++ b/pilot/helpers/exceptions/TooDeepRecursionError.py @@ -0,0 +1,4 @@ +class TooDeepRecursionError(Exception): + def __init__(self, message='Recursion is too deep!'): + self.message = message + super().__init__(message) diff --git a/pilot/prompts/development/define_user_review_goal.prompt b/pilot/prompts/development/define_user_review_goal.prompt new file mode 100644 index 0000000..3b32c75 --- /dev/null +++ b/pilot/prompts/development/define_user_review_goal.prompt @@ -0,0 +1,8 @@ +How can a human user test if this task was completed successfully? If you specify a command that needs to be run or give example, be very specific. You don't want the user to have to think anything through but rather that they jsut follow your instructions. + +!IMPORTANT! +In case the task can be tested by making an API request, do not suggest how can a request be made with Postman but rather write a full cURL command that the user can just run. +!IMPORTANT! +Do not require any code writing form the user for testing this task. + +If it is difficult to test the task, you can just write that there is nothing specific to test and that the best thing is to move on to another task. If this is the case, answer with only this sentence - `There is nothing specific to test for this task so you can write "continue" and we'll move on to the next task.` \ No newline at end of file