diff --git a/core/agents/orchestrator.py b/core/agents/orchestrator.py index 0c31132ff2..3966020adf 100644 --- a/core/agents/orchestrator.py +++ b/core/agents/orchestrator.py @@ -182,7 +182,8 @@ 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 diff --git a/core/agents/response.py b/core/agents/response.py index d41843367c..7b777eb6d3 100644 --- a/core/agents/response.py +++ b/core/agents/response.py @@ -45,6 +45,9 @@ 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 @@ -144,3 +147,7 @@ class AgentResponse: @staticmethod def external_docs_required(agent: "BaseAgent") -> "AgentResponse": return AgentResponse(type=ResponseType.EXTERNAL_DOCS_REQUIRED, agent=agent) + + @staticmethod + def new_feature_requested(agent: "BaseAgent") -> "AgentResponse": + return AgentResponse(type=ResponseType.NEW_FEATURE_REQUESTED, agent=agent) diff --git a/core/agents/spec_writer.py b/core/agents/spec_writer.py index 5002f734c8..d586e28ff9 100644 --- a/core/agents/spec_writer.py +++ b/core/agents/spec_writer.py @@ -1,6 +1,6 @@ from core.agents.base import BaseAgent from core.agents.convo import AgentConvo -from core.agents.response import AgentResponse +from core.agents.response import AgentResponse, ResponseType from core.db.models import Complexity from core.llm.parser import StringParser from core.log import get_logger @@ -26,6 +26,12 @@ 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: + return await self.update_spec() + else: + return await self.initialize_spec() + + async def initialize_spec(self) -> AgentResponse: response = await self.ask_question( "Describe your app in as much detail as possible", allow_empty=False, @@ -72,6 +78,39 @@ class SpecWriter(BaseAgent): telemetry.set("initial_prompt", spec) telemetry.set("is_complex_app", complexity != Complexity.SIMPLE) + self.next_state.action = SPEC_STEP_NAME + return AgentResponse.new_feature_requested(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() + + 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) + llm_response: str = await llm(convo, temperature=0, parser=StringParser()) + updated_spec = llm_response.strip() + + self.next_state.specification = self.current_state.specification.clone() + self.next_state.specification.description = updated_spec + + telemetry.set( + "initial_prompt", updated_spec + ) # TODO Check if a separate telemetry variable needed for updated spec + self.next_state.action = SPEC_STEP_NAME return AgentResponse.done(self) diff --git a/core/prompts/spec-writer/add_new_feature.prompt b/core/prompts/spec-writer/add_new_feature.prompt new file mode 100644 index 0000000000..395efe3b9b --- /dev/null +++ b/core/prompts/spec-writer/add_new_feature.prompt @@ -0,0 +1,21 @@ +Your team has taken the client brief and turned it into a project specification. +Afterwards the client added a description for a new feature to be added to the project specification. +Your job is to update the project specification so that it contains the new feature information but does not lack any of the information from the original project specification. + +This might include: +* details on how the app should work +* information which 3rd party packages or APIs to use or avoid +* concrete examples of API requests/responses, library usage, or other external documentation + +Here is the client brief: +---PROJECT-SPECIFICATION-START--- +{{ state.specification.description }} +---PROJECT-SPECIFICATION-END--- + +Here is the specification your team came up with: +---FEATURE-DESCRIPTION-START--- +{{ feature_description }} +---FEATURE-DESCRIPTION-END--- + +In your response, output the new updated project specification. +If there is no feature description, just output the original project specification.