diff --git a/pilot/const/function_calls.py b/pilot/const/function_calls.py index dc94525a86..8ccf223345 100644 --- a/pilot/const/function_calls.py +++ b/pilot/const/function_calls.py @@ -491,7 +491,7 @@ REVIEW_CHANGES = { }, "reason": { "type": "string", - "desciprion": "Reason for applying or ignoring this hunk." + "description": "Reason for applying or ignoring this hunk." }, "decision": { "type": "string", @@ -512,3 +512,40 @@ REVIEW_CHANGES = { } }], } + +GET_BUG_REPORT_MISSING_DATA = { + 'definitions': [{ + 'name': 'bug_report_missing_data', + 'description': 'Review bug report and identify missing data. List questions that need to be answered to proceed with the bug fix. If no additional questions are needed missing_data should be an empty array.', + 'parameters': { + "type": "object", + "properties": { + "reasoning": { + "type": "string", + "description": "Reasoning for asking these questions or for not asking any questions." + }, + "missing_data": { + "type": "array", + "items": { + "type": "object", + "properties": { + "category": { + "type": "string", + "enum": ["general", "frontend", "backend", "database", "devops", "other"], + "description": "Category of the question." + }, + "question": { + "type": "string", + "description": "Very clear question that needs to be answered to have good bug report.", + }, + }, + "required": ["category", "question"], + "additionalProperties": False + }, + } + }, + "required": ["reasoning", "missing_data"], + "additionalProperties": False + } + }], +} diff --git a/pilot/const/ipc.py b/pilot/const/ipc.py index 559e24fa1e..42390f744e 100644 --- a/pilot/const/ipc.py +++ b/pilot/const/ipc.py @@ -19,6 +19,7 @@ MESSAGE_TYPE = { LOCAL_IGNORE_MESSAGE_TYPES = [ 'info', 'project_folder_name', + 'run_command', 'button', 'buttons-only', 'exit', diff --git a/pilot/helpers/agents/Developer.py b/pilot/helpers/agents/Developer.py index cff4a228b8..f1cbf28123 100644 --- a/pilot/helpers/agents/Developer.py +++ b/pilot/helpers/agents/Developer.py @@ -26,7 +26,8 @@ from helpers.Agent import Agent from helpers.AgentConvo import AgentConvo from utils.utils import should_execute_step, array_of_objects_to_string, generate_app_data from helpers.cli import run_command_until_success, execute_command_and_check_cli_response -from const.function_calls import EXECUTE_COMMANDS, GET_TEST_TYPE, IMPLEMENT_TASK, COMMAND_TO_RUN, ALTERNATIVE_SOLUTIONS +from const.function_calls import (EXECUTE_COMMANDS, GET_TEST_TYPE, IMPLEMENT_TASK, COMMAND_TO_RUN, + ALTERNATIVE_SOLUTIONS, GET_BUG_REPORT_MISSING_DATA) from database.database import save_progress, get_progress_steps, update_app_status from utils.telemetry import telemetry from prompts.prompts import ask_user @@ -602,6 +603,7 @@ class Developer(Agent): return {"success": True, "user_input": user_feedback} if user_feedback is not None: + user_feedback = self.bug_report_generator(user_feedback) stuck_in_loop = user_feedback.startswith(STUCK_IN_LOOP) if stuck_in_loop: # Remove the STUCK_IN_LOOP prefix from the user feedback @@ -660,6 +662,57 @@ class Developer(Agent): task_steps = llm_response['tasks'] self.execute_task(iteration_convo, task_steps, is_root_task=True) + def bug_report_generator(self, user_feedback): + """ + Generate a bug report from the user feedback. + + :param user_feedback: The user feedback. + :return: The bug report. + """ + bug_report_convo = AgentConvo(self) + function_uuid = str(uuid.uuid4()) + bug_report_convo.save_branch(function_uuid) + questions_and_answers = [] + while True: + llm_response = bug_report_convo.send_message('development/bug_report.prompt', { + "user_feedback": user_feedback, + "app_summary": self.project.project_description, + "files": self.project.get_all_coded_files(), + "questions_and_answers": questions_and_answers, + }, GET_BUG_REPORT_MISSING_DATA) + + missing_data = llm_response['missing_data'] + if len(missing_data) == 0: + break + + for missing_data_item in missing_data: + if self.project.check_ipc(): + print(missing_data_item['question'], type='verbose') + print('skip question', type='button') + if self.run_command: + print(self.run_command, type='run_command') + + answer = ask_user(self.project, missing_data_item['question']) + if answer.lower() == 'skip question': + continue + + questions_and_answers.append({ + "question": missing_data_item['question'], + "answer": answer + }) + + bug_report_convo.load_branch(function_uuid) + + if len(questions_and_answers): + bug_report_summary_convo = AgentConvo(self) + user_feedback = bug_report_summary_convo.send_message('development/bug_report_summary.prompt', { + "app_summary": self.project.project_description, + "user_feedback": user_feedback, + "questions_and_answers": questions_and_answers, + }) + + return user_feedback + def review_task(self): """ Review all task changes and refactor big files. diff --git a/pilot/prompts/development/bug_report.prompt b/pilot/prompts/development/bug_report.prompt new file mode 100644 index 0000000000..cdba1e49e5 --- /dev/null +++ b/pilot/prompts/development/bug_report.prompt @@ -0,0 +1,39 @@ +Here is description of app that you are working on: +``` +{{ app_summary }} +``` + +{{ files_list }} + +Client wrote this feedback: +``` +{{ user_feedback }} +``` +{% if questions_and_answers|length > 0 %} +Here are questions and answers that you already asked the client: +```{% for row in questions_and_answers %} +Q: {{ row.question }} +A: {{ row.answer }} +{% endfor %} +```{% endif %} + +Your job is to identify if feedback is good enough for you to solve the problem. If not, what information you need to solve the problem. Ask for any information that you need to solve the problem. +If you have enough information don't ask any questions. + +When thinking of questions, consider the following: +- After getting answers to your questions, you must be able to solve the problem. +- Category on which you need more information ("general", "frontend", "backend", "database", "devops", "other") +- Make sure to cover all categories that you need to solve the problem. +- Ask only specific information that you need to solve the problem. +- Ask clear, short and concise questions. +- Ask only crucial questions. Do not ask for information that you do not need to solve the problem. +- Ask least amount of questions to get the most information. +- Ask least amount of questions to solve the problem. + +Here are some examples of good questions: +"Are there any logs in browser?" +"Can you provide logs from server?" +"What is the error message?" +"What is the expected behavior?" +"What is the actual behavior?" +"What is the stack trace?" \ No newline at end of file diff --git a/pilot/prompts/development/bug_report_summary.prompt b/pilot/prompts/development/bug_report_summary.prompt new file mode 100644 index 0000000000..0eca36ec09 --- /dev/null +++ b/pilot/prompts/development/bug_report_summary.prompt @@ -0,0 +1,27 @@ +You are working on this app: +``` +{{ app_summary }} +``` + +User came to you with this bug report: +``` +{{ user_feedback }} +``` +You didn't have enough information to start working on it, so you asked the user to provide more details. +Here are questions and answers that you asked the user: +```{% for row in questions_and_answers %} +Q: {{ row.question }} +A: {{ row.answer }} +{% endfor %} +``` + +Your job is now to write issue explanation that will be sent to developer, strictly following these rules: +- If there are some logs you MUST copy all logs in whole! Do not omit any logs! This is also true for code snippets or stack traces! +- Explanation must be very clear and factual, keep it as short as possible. +- When writing explanation of the issue, it is good to cover all categories that you have information on. If you don't have information about one category, then don't mention it. Here are categories: "general", "frontend", "backend", "database", "devops", "other". +- Omit all information that turns out to be irrelevant for this issue (e.g. after asking additional questions it turns out that first user message is not relevant then you should ignore it) +- Write issue explanation as if you are talking directly to developer (in first person). Do not mention "user", talk as if you found the the issue. +- Do not use any subjective thoughts, just facts. +- Write only issue explanation. Do not write any recap, summary or ideas how to solve the problem at the end. Do not write introduction at the start (e.g. "Issue Explanation for Developer:"). +- Have in mind that developer is smart and he will understand everything as long as you provide all information that you have and that is needed to fix this issue. +- Have in mind that issue might not be related to your current development task.