From ea3e8b7d9b4aa1fefb855d4e0745cf4cbd4dcee2 Mon Sep 17 00:00:00 2001 From: matija-ilijas Date: Thu, 25 Jul 2024 14:43:38 +0200 Subject: [PATCH] Added new feature request in deep focus pipeline --- core/agents/orchestrator.py | 5 +++-- core/agents/response.py | 3 --- core/agents/spec_writer.py | 28 ++++++++-------------------- core/agents/troubleshooter.py | 4 ++-- core/db/models/project_state.py | 1 + 5 files changed, 14 insertions(+), 27 deletions(-) diff --git a/core/agents/orchestrator.py b/core/agents/orchestrator.py index 3966020adf..475f37ac0a 100644 --- a/core/agents/orchestrator.py +++ b/core/agents/orchestrator.py @@ -182,8 +182,6 @@ class Orchestrator(BaseAgent): return Importer(self.state_manager, self.ui, prev_response=prev_response) if prev_response.type == ResponseType.EXTERNAL_DOCS_REQUIRED: return ExternalDocumentation(self.state_manager, self.ui, prev_response=prev_response) - if prev_response.type == ResponseType.NEW_FEATURE_REQUESTED: - return SpecWriter(self.state_manager, self.ui, prev_response=prev_response) if not state.specification.description: if state.files: # The project has been imported, but not analyzed yet @@ -253,6 +251,9 @@ class Orchestrator(BaseAgent): elif current_iteration_status == IterationStatus.PROBLEM_SOLVER: # Call Problem Solver if the user said "I'm stuck in a loop" return ProblemSolver(self.state_manager, self.ui) + elif current_iteration_status == IterationStatus.NEW_FEATURE_REQUESTED: + # Call Spec Writer to add the "change" requested by the user to project specification + return SpecWriter(self.state_manager, self.ui) # We have just finished the task, call Troubleshooter to ask the user to review return Troubleshooter(self.state_manager, self.ui) diff --git a/core/agents/response.py b/core/agents/response.py index 7b777eb6d3..4a4855f418 100644 --- a/core/agents/response.py +++ b/core/agents/response.py @@ -45,9 +45,6 @@ class ResponseType(str, Enum): EXTERNAL_DOCS_REQUIRED = "external-docs-required" """We need to fetch external docs for a task.""" - NEW_FEATURE_REQUESTED = "new-feature-requested" - """User wants to add a new feature to project specification.""" - class AgentResponse: type: ResponseType = ResponseType.DONE diff --git a/core/agents/spec_writer.py b/core/agents/spec_writer.py index d586e28ff9..3265ba046e 100644 --- a/core/agents/spec_writer.py +++ b/core/agents/spec_writer.py @@ -1,6 +1,7 @@ from core.agents.base import BaseAgent from core.agents.convo import AgentConvo -from core.agents.response import AgentResponse, ResponseType +from core.agents.response import AgentResponse +from core.db.models.project_state import IterationStatus from core.db.models import Complexity from core.llm.parser import StringParser from core.log import get_logger @@ -26,7 +27,8 @@ class SpecWriter(BaseAgent): display_name = "Spec Writer" async def run(self) -> AgentResponse: - if self.prev_response and self.prev_response.type == ResponseType.NEW_FEATURE_REQUESTED: + current_iteration = self.current_state.current_iteration + if current_iteration is not None and current_iteration["status"] == IterationStatus.NEW_FEATURE_REQUESTED: return await self.update_spec() else: return await self.initialize_spec() @@ -79,25 +81,10 @@ class SpecWriter(BaseAgent): telemetry.set("is_complex_app", complexity != Complexity.SIMPLE) self.next_state.action = SPEC_STEP_NAME - return AgentResponse.new_feature_requested(self) + return AgentResponse.done(self) async def update_spec(self) -> AgentResponse: - response = await self.ask_question( - "Describe the new feature you want to add", - allow_empty=False, - buttons={ - # FIXME: must be lowercase becase VSCode doesn't recognize it otherwise. Needs a fix in the extension - "cancel": "cancel", - }, - ) - if response.cancelled: - return AgentResponse.error(self, "No feature description") - - if response.button == "cancel": - return AgentResponse.error(self, "No feature description") - - feature_description = response.text.strip() - + feature_description = self.current_state.current_iteration["description"] await self.send_message("Adding new feature to project specification ...") llm = self.get_llm() convo = AgentConvo(self).template("add_new_feature", feature_description=feature_description) @@ -111,7 +98,8 @@ class SpecWriter(BaseAgent): "initial_prompt", updated_spec ) # TODO Check if a separate telemetry variable needed for updated spec - self.next_state.action = SPEC_STEP_NAME + self.next_state.current_iteration["status"] = IterationStatus.FIND_SOLUTION + self.next_state.flag_iterations_as_modified() return AgentResponse.done(self) async def check_prompt_complexity(self, prompt: str) -> str: diff --git a/core/agents/troubleshooter.py b/core/agents/troubleshooter.py index 6a3ebcccf9..d6b6159638 100644 --- a/core/agents/troubleshooter.py +++ b/core/agents/troubleshooter.py @@ -87,7 +87,7 @@ class Troubleshooter(IterationPromptMixin, BaseAgent): return await self.complete_task() user_feedback = bug_report or change_description - user_feedback_qa = await self.generate_bug_report(run_command, user_instructions, user_feedback) + user_feedback_qa = None # await self.generate_bug_report(run_command, user_instructions, user_feedback) if is_loop: if last_iteration["alternative_solutions"]: @@ -102,7 +102,7 @@ class Troubleshooter(IterationPromptMixin, BaseAgent): else: # should be - elif change_description is not None: - but to prevent bugs with the extension # this might be caused if we show the input field instead of buttons - iteration_status = IterationStatus.FIND_SOLUTION + iteration_status = IterationStatus.NEW_FEATURE_REQUESTED self.next_state.iterations = self.current_state.iterations + [ { diff --git a/core/db/models/project_state.py b/core/db/models/project_state.py index 5d4db95f60..67ad685ad0 100644 --- a/core/db/models/project_state.py +++ b/core/db/models/project_state.py @@ -41,6 +41,7 @@ class IterationStatus: IMPLEMENT_SOLUTION = "implement_solution" FIND_SOLUTION = "find_solution" PROBLEM_SOLVER = "problem_solver" + NEW_FEATURE_REQUESTED = "new_feature_requested" DONE = "done"