From 024fcf8187ee35d464bb4026cd48fb840737564e Mon Sep 17 00:00:00 2001 From: mijauexe Date: Thu, 27 Feb 2025 16:17:51 +0100 Subject: [PATCH] Add more actions to agents --- core/agents/architect.py | 4 ++-- core/agents/bug_hunter.py | 27 +++++++++++++++++++++------ core/agents/code_monkey.py | 5 ++++- core/agents/developer.py | 21 +++++++++++++++------ core/agents/executor.py | 8 ++++++-- core/agents/frontend.py | 13 ++++++++++++- core/agents/problem_solver.py | 1 + core/agents/spec_writer.py | 8 ++++++-- core/agents/task_completer.py | 4 +++- core/agents/tech_lead.py | 10 ++++++++-- core/agents/tech_writer.py | 4 +++- core/agents/troubleshooter.py | 8 ++++++-- core/db/models/project_state.py | 6 ++++++ 13 files changed, 93 insertions(+), 26 deletions(-) diff --git a/core/agents/architect.py b/core/agents/architect.py index 758b7fe8bf..462886172e 100644 --- a/core/agents/architect.py +++ b/core/agents/architect.py @@ -34,8 +34,8 @@ class AppType(str, Enum): CLI = "cli-tool" -# FIXME: all the reponse pydantic models should be strict (see config._StrictModel), also check if we -# can disallow adding custom Python attributes to the model +# FIXME: all the response pydantic models should be strict (see config._StrictModel), also check if we +# can disallow adding custom Python attributes to the model class SystemDependency(BaseModel): name: str = Field( None, diff --git a/core/agents/bug_hunter.py b/core/agents/bug_hunter.py index f8fc85a9ee..114fc07f7a 100644 --- a/core/agents/bug_hunter.py +++ b/core/agents/bug_hunter.py @@ -44,6 +44,12 @@ class ImportantLogsForDebugging(BaseModel): logs: list[ImportantLog] = Field(description="Important logs that will help the human debug the current bug.") +BH_STARTING_PAIR_PROGRAMMING = "Start pair programming for task #{}" +BH_START_USER_TEST = "Start user testing for task #{}" +BH_WAIT_BUG_REP_INSTRUCTIONS = "Awaiting bug reproduction instructions for task #{}" +BH_START_BUG_HUNT = "Start bug hunt for task #{}" + + class BugHunter(ChatWithBreakdownMixin, BaseAgent): agent_type = "bug-hunter" display_name = "Bug Hunter" @@ -87,6 +93,9 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent): ) async def check_logs(self, logs_message: str = None): + self.next_state.action = BH_START_BUG_HUNT.format( + self.current_state.tasks.index(self.current_state.current_task) + 1 + ) llm = self.get_llm(CHECK_LOGS_AGENT_NAME, stream_output=True) convo = self.generate_iteration_convo_so_far() await self.ui.start_breakdown_stream() @@ -124,6 +133,15 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent): return AgentResponse.done(self) async def ask_user_to_test(self, awaiting_bug_reproduction: bool = False, awaiting_user_test: bool = False): + if awaiting_user_test: + self.next_state.action = BH_START_USER_TEST.format( + self.current_state.tasks.index(self.current_state.current_task) + 1 + ) + elif awaiting_bug_reproduction: + self.next_state.action = BH_WAIT_BUG_REP_INSTRUCTIONS.format( + self.current_state.tasks.index(self.current_state.current_task) + 1 + ) + await self.ui.stop_app() test_instructions = self.current_state.current_iteration["bug_reproduction_description"] await self.ui.send_message( @@ -201,6 +219,9 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent): return AgentResponse.done(self) async def start_pair_programming(self): + self.next_state.action = BH_STARTING_PAIR_PROGRAMMING.format( + self.current_state.tasks.index(self.current_state.current_task) + 1 + ) llm = self.get_llm(stream_output=True) convo = self.generate_iteration_convo_so_far(True) if len(convo.messages) > 1: @@ -359,9 +380,3 @@ class BugHunter(ChatWithBreakdownMixin, BaseAgent): ] self.next_state.current_iteration["status"] = new_status - - async def continue_on(self, convo, button_value, user_response): - llm = self.get_llm(stream_output=True) - convo = convo.template("continue_on") - continue_on = await llm(convo, temperature=0.5) - return continue_on diff --git a/core/agents/code_monkey.py b/core/agents/code_monkey.py index 5dfc0d3021..cf8a1cc96e 100644 --- a/core/agents/code_monkey.py +++ b/core/agents/code_monkey.py @@ -57,6 +57,9 @@ class FileDescription(BaseModel): ) +CM_UPDATE_FILES = "Updating files" + + class CodeMonkey(FileDiffMixin, BaseAgent): agent_type = "code-monkey" display_name = "Code Monkey" @@ -94,7 +97,7 @@ class CodeMonkey(FileDiffMixin, BaseAgent): ) else: await self.ui.send_file_status(file_name, "reworking", source=self.ui_source) - self.next_state.action = "Updating files" + self.next_state.action = CM_UPDATE_FILES attempt = 1 feedback = None diff --git a/core/agents/developer.py b/core/agents/developer.py index 1d48cd71bd..7878d9635f 100644 --- a/core/agents/developer.py +++ b/core/agents/developer.py @@ -72,6 +72,13 @@ class TaskSteps(BaseModel): steps: list[Step] +DEV_WAIT_TEST = "Awaiting user test" +DEV_TASK_STARTING = "Starting task #{}" +DEV_TASK_BREAKDOWN = "Task #{} breakdown" +DEV_TROUBLESHOOT = "Troubleshooting #{}" +DEV_TASK_REVIEW_FEEDBACK = "Task review feedback" + + class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): agent_type = "developer" display_name = "Developer" @@ -163,19 +170,20 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): ): # This is just a support for old iterations that don't have status self.next_state.complete_iteration() - self.next_state.action = f"Troubleshooting #{len(self.current_state.iterations)}" + self.next_state.action = DEV_TROUBLESHOOT.format(len(self.current_state.iterations)) elif iteration["status"] == IterationStatus.IMPLEMENT_SOLUTION: # If the user requested a change, then, we'll implement it and go straight back to testing self.next_state.complete_iteration() - self.next_state.action = f"Troubleshooting #{len(self.current_state.iterations)}" + self.next_state.action = DEV_TROUBLESHOOT.format(len(self.current_state.iterations)) elif iteration["status"] == IterationStatus.AWAITING_BUG_FIX: # If bug fixing is done, ask user to test again + self.next_state.action = DEV_WAIT_TEST self.next_state.current_iteration["status"] = IterationStatus.AWAITING_USER_TEST elif iteration["status"] == IterationStatus.AWAITING_LOGGING: # If logging is done, ask user to reproduce the bug self.next_state.current_iteration["status"] = IterationStatus.AWAITING_BUG_REPRODUCTION else: - self.next_state.action = "Task review feedback" + self.next_state.action = DEV_TASK_REVIEW_FEEDBACK current_task_index = self.current_state.tasks.index(current_task) self.next_state.tasks[current_task_index] = { @@ -186,6 +194,9 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): async def breakdown_current_task(self) -> AgentResponse: current_task = self.current_state.current_task + current_task_index = self.current_state.tasks.index(current_task) + self.next_state.action = DEV_TASK_BREAKDOWN.format(current_task_index + 1) + source = self.current_state.current_epic.get("source", "app") await self.ui.send_task_progress( self.current_state.tasks.index(current_task) + 1, @@ -203,8 +214,6 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): # Check which files are relevant to the current task await self.get_relevant_files_parallel() - current_task_index = self.current_state.tasks.index(current_task) - await self.send_message("Thinking about how to implement this task ...") await self.ui.start_breakdown_stream() @@ -246,7 +255,6 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): # There might be state leftovers from previous tasks that we need to clean here self.next_state.modified_files = {} self.set_next_steps(response, source) - self.next_state.action = f"Task #{current_task_index + 1} start" await telemetry.trace_code_event( "task-start", { @@ -314,6 +322,7 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent): "task_index": task_index, } ) + self.next_state.action = DEV_TASK_STARTING.format(task_index) await self.send_message(f"Starting task #{task_index} with the description:\n\n" + description) if self.current_state.run_command: await self.ui.send_run_command(self.current_state.run_command) diff --git a/core/agents/executor.py b/core/agents/executor.py index 865a74bdbe..24bdaa25fc 100644 --- a/core/agents/executor.py +++ b/core/agents/executor.py @@ -32,6 +32,10 @@ class CommandResult(BaseModel): ) +EX_SKIP_COMMAND = 'Skip "{}"' +EX_RUN_COMMAND = 'Run "{}"' + + class Executor(BaseAgent): agent_type = "executor" display_name = "Executor" @@ -94,7 +98,7 @@ class Executor(BaseAgent): log.info(f"Skipping command execution of `{cmd}` (requested by user)") await self.send_message(f"Skipping command {cmd}") self.complete() - self.next_state.action = f'Skip "{cmd_name}"' + self.next_state.action = EX_SKIP_COMMAND.format(cmd_name) return AgentResponse.done(self) if confirm.button != "yes": @@ -110,7 +114,7 @@ class Executor(BaseAgent): duration = (datetime.now(timezone.utc) - started_at).total_seconds() self.complete() - self.next_state.action = f'Run "{cmd_name}"' + self.next_state.action = EX_RUN_COMMAND.format(cmd_name) exec_log = ExecLog( started_at=started_at, diff --git a/core/agents/frontend.py b/core/agents/frontend.py index 85a8a70179..c2c6da2ede 100644 --- a/core/agents/frontend.py +++ b/core/agents/frontend.py @@ -15,6 +15,12 @@ from core.ui.base import ProjectStage log = get_logger(__name__) +FE_INIT = "Frontend init" +FE_START = "Frontend start" +FE_CONTINUE = "Frontend continue" +FE_ITERATION = "Frontend iteration" +FE_ITERATION_DONE = "Frontend iteration done" + class Frontend(FileDiffMixin, GitMixin, BaseAgent): agent_type = "frontend" @@ -39,6 +45,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent): :return: AgentResponse.done(self) """ + self.next_state.action = FE_INIT await self.ui.send_project_stage({"stage": ProjectStage.PROJECT_DESCRIPTION}) description = await self.ask_question( @@ -87,6 +94,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent): """ Starts the frontend of the app. """ + self.next_state.action = FE_START await self.send_message("Building the frontend... This may take a couple of minutes") description = self.current_state.epics[0]["description"] @@ -114,6 +122,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent): """ Continues building the frontend of the app after the initial user input. """ + self.next_state.action = FE_CONTINUE await self.ui.send_project_stage({"stage": ProjectStage.CONTINUE_FRONTEND}) await self.send_message("Continuing to build UI... This may take a couple of minutes") @@ -143,7 +152,7 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent): :return: True if the frontend is fully built, False otherwise. """ - + self.next_state.action = FE_ITERATION # update the pages in the knowledge base await self.state_manager.update_implemented_pages_and_apis() @@ -198,6 +207,8 @@ class Frontend(FileDiffMixin, GitMixin, BaseAgent): """ if finished: # TODO Add question if user app is fully finished + self.next_state.action = FE_ITERATION_DONE + self.next_state.complete_epic() await telemetry.trace_code_event( "frontend-finished", diff --git a/core/agents/problem_solver.py b/core/agents/problem_solver.py index e7b8de059f..5097461659 100644 --- a/core/agents/problem_solver.py +++ b/core/agents/problem_solver.py @@ -23,6 +23,7 @@ class AlternativeSolutions(BaseModel): ) +# TODO: add next state actions whenever this agent is reactivated class ProblemSolver(IterationPromptMixin, BaseAgent): agent_type = "problem-solver" display_name = "Problem Solver" diff --git a/core/agents/spec_writer.py b/core/agents/spec_writer.py index b3ba374c94..2a6d312b8a 100644 --- a/core/agents/spec_writer.py +++ b/core/agents/spec_writer.py @@ -14,7 +14,9 @@ ANALYZE_THRESHOLD = 1500 INITIAL_PROJECT_HOWTO_URL = ( "https://github.com/Pythagora-io/gpt-pilot/wiki/How-to-write-a-good-initial-project-description" ) -SPEC_STEP_NAME = "Create specification" +SPEC_CREATE_STEP_NAME = "Create specification" +SPEC_CHANGE_STEP_NAME = "Change specification" +SPEC_CHANGE_FEATURE_STEP_NAME = "Change specification due to new feature" log = get_logger(__name__) @@ -33,6 +35,7 @@ class SpecWriter(BaseAgent): return await self.initialize_spec() async def initialize_spec(self) -> AgentResponse: + self.next_state.action = SPEC_CREATE_STEP_NAME # response = await self.ask_question( # "Describe your app in as much detail as possible", # allow_empty=False, @@ -65,13 +68,14 @@ class SpecWriter(BaseAgent): telemetry.set("updated_prompt", reviewed_spec) telemetry.set("is_complex_app", complexity != Complexity.SIMPLE) - self.next_state.action = SPEC_STEP_NAME return AgentResponse.done(self) async def update_spec(self, iteration_mode) -> AgentResponse: if iteration_mode: + self.next_state.action = SPEC_CHANGE_FEATURE_STEP_NAME feature_description = self.current_state.current_iteration["user_feedback"] else: + self.next_state.action = SPEC_CHANGE_STEP_NAME feature_description = self.prev_response.data["description"] await self.send_message( diff --git a/core/agents/task_completer.py b/core/agents/task_completer.py index 7f00ad7709..0b13386dcd 100644 --- a/core/agents/task_completer.py +++ b/core/agents/task_completer.py @@ -6,6 +6,8 @@ from core.telemetry import telemetry log = get_logger(__name__) +TC_TASK_DONE = "Task #{} complete" + class TaskCompleter(BaseAgent, GitMixin): agent_type = "pythagora" @@ -16,7 +18,7 @@ class TaskCompleter(BaseAgent, GitMixin): await self.git_commit() current_task_index1 = self.current_state.tasks.index(self.current_state.current_task) + 1 - self.next_state.action = f"Task #{current_task_index1} complete" + self.next_state.action = TC_TASK_DONE.format(current_task_index1) self.next_state.complete_task() await self.state_manager.log_task_completed() tasks = self.current_state.tasks diff --git a/core/agents/tech_lead.py b/core/agents/tech_lead.py index 332a8f0cdd..a050534b1c 100644 --- a/core/agents/tech_lead.py +++ b/core/agents/tech_lead.py @@ -45,6 +45,11 @@ class EpicPlan(BaseModel): plan: list[Task] = Field(description="List of tasks that need to be done to implement the entire epic.") +TL_CREATE_INITIAL_EPIC = "Create initial project epic" +TL_CREATE_PLAN = "Create a development plan for epic: {}" +TL_START_FEATURE = "Start of feature #{}" + + class TechLead(RelevantFilesMixin, BaseAgent): agent_type = "tech-lead" display_name = "Tech Lead" @@ -76,13 +81,13 @@ class TechLead(RelevantFilesMixin, BaseAgent): # return AgentResponse.done(self) if self.current_state.current_epic: - self.next_state.action = "Create a development plan" await self.remove_mocked_data() return await self.plan_epic(self.current_state.current_epic) else: return await self.ask_for_new_feature() def create_initial_project_epic(self): + self.next_state.action = TL_CREATE_INITIAL_EPIC log.debug("Creating initial project Epic") self.next_state.epics = self.current_state.epics + [ { @@ -171,10 +176,11 @@ class TechLead(RelevantFilesMixin, BaseAgent): } ] # Orchestrator will rerun us to break down the new feature epic - self.next_state.action = f"Start of feature #{len(self.current_state.epics)}" + self.next_state.action = TL_START_FEATURE.format(len(self.current_state.epics)) return AgentResponse.update_specification(self, feature_description) async def plan_epic(self, epic) -> AgentResponse: + self.next_state.action = TL_CREATE_PLAN.format(epic["name"]) log.debug(f"Planning tasks for the epic: {epic['name']}") await self.send_message("Creating the development plan ...") diff --git a/core/agents/tech_writer.py b/core/agents/tech_writer.py index 90d6f5ef10..0dd97365ae 100644 --- a/core/agents/tech_writer.py +++ b/core/agents/tech_writer.py @@ -7,6 +7,8 @@ from core.ui.base import success_source log = get_logger(__name__) +TW_WRITE = "Write documentation" + class TechnicalWriter(BaseAgent): agent_type = "tech-writer" @@ -23,7 +25,7 @@ class TechnicalWriter(BaseAgent): await self.send_congratulations() await self.create_readme() - self.next_state.action = "Create README.md" + self.next_state.action = TW_WRITE self.next_state.set_current_task_status(TaskStatus.DOCUMENTED) return AgentResponse.done(self) diff --git a/core/agents/troubleshooter.py b/core/agents/troubleshooter.py index 7b85cf41fe..c9dd51bd17 100644 --- a/core/agents/troubleshooter.py +++ b/core/agents/troubleshooter.py @@ -31,6 +31,10 @@ class RouteFilePaths(BaseModel): files: list[str] = Field(description="List of paths for files that contain routes") +TS_TASK_REVIEWED = "Task #{} reviewed" +TS_ALT_SOLUTION = "Alternative solution (attempt #{})" + + class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFilesMixin, BaseAgent): agent_type = "troubleshooter" display_name = "Troubleshooter" @@ -142,7 +146,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles await self.trace_loop("loop-end") current_task_index1 = self.current_state.tasks.index(self.current_state.current_task) + 1 - self.next_state.action = f"Task #{current_task_index1} reviewed" + self.next_state.action = TS_TASK_REVIEWED.format(current_task_index1) self.next_state.set_current_task_status(TaskStatus.REVIEWED) return AgentResponse.done(self) @@ -332,7 +336,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles next_state_iteration["attempts"] += 1 next_state_iteration["status"] = IterationStatus.PROBLEM_SOLVER self.next_state.flag_iterations_as_modified() - self.next_state.action = f"Alternative solution (attempt #{next_state_iteration['attempts']})" + self.next_state.action = TS_ALT_SOLUTION.format(next_state_iteration["attempts"]) return AgentResponse.done(self) async def generate_bug_report( diff --git a/core/db/models/project_state.py b/core/db/models/project_state.py index a68a4aa870..c65bdf6d38 100644 --- a/core/db/models/project_state.py +++ b/core/db/models/project_state.py @@ -46,6 +46,10 @@ class IterationStatus: DONE = "done" +PS_EPIC_COMPLETE = "Epic {} completed" +PS_TASK_COMPLETE = "Task {} completed" + + class ProjectState(Base): __tablename__ = "project_states" __table_args__ = ( @@ -297,6 +301,8 @@ class ProjectState(Base): self.unfinished_epics[0]["completed"] = True self.tasks = [] flag_modified(self, "epics") + if len(self.unfinished_epics) > 0: + self.next_state.action = PS_EPIC_COMPLETE.format(self.unfinished_epics[0]["name"]) def complete_iteration(self): if not self.unfinished_iterations: