Add redo task functionality

pull/1160/head
mijauexe 2 years ago
parent 4348a021e5
commit 6cfae57cd3

@ -230,6 +230,15 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent):
):
related_api_endpoints = []
redo_task_user_feedback = None
if (
self.next_state
and self.next_state.current_task
and self.next_state.current_task.get("redo_human_instructions", None) is not None
):
redo_task_user_feedback = self.next_state.current_task["redo_human_instructions"]
convo = AgentConvo(self).template(
"breakdown",
task=current_task,
@ -237,6 +246,7 @@ class Developer(ChatWithBreakdownMixin, RelevantFilesMixin, BaseAgent):
current_task_index=current_task_index,
docs=self.current_state.docs,
related_api_endpoints=related_api_endpoints,
redo_task_user_feedback=redo_task_user_feedback,
)
response: str = await llm(convo)
convo.assistant(response)

@ -72,12 +72,25 @@ class Orchestrator(BaseAgent, GitMixin):
await self.set_favicon()
await self.enable_debugger()
# TODO: consider refactoring this into two loop; the outer with one iteration per comitted step,
# TODO: consider refactoring this into two loop; the outer with one iteration per committed step,
# and the inner which runs the agents for the current step until they're done. This would simplify
# handle_done() and let us do other per-step processing (eg. describing files) in between agent runs.
while True:
await self.update_stats()
# If the task is marked as "redo_human_instructions", we need to reload the project at the state before the current task breakdown
if (
self.current_state.current_task
and self.current_state.current_task.get("redo_human_instructions", None) is not None
):
redo_human_instructions = self.current_state.current_task["redo_human_instructions"]
project_state = await self.state_manager.get_project_state_for_redo_task(self.current_state)
if project_state is not None:
await self.state_manager.load_project(
branch_id=project_state.branch_id, step_index=project_state.step_index
)
self.next_state.current_task["redo_human_instructions"] = redo_human_instructions
await self.update_stats()
agent = self.create_agent(response)
# In case where agent is a list, run all agents in parallel.

@ -86,11 +86,25 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
# use "current_iteration" here
last_iteration = self.current_state.iterations[-1] if len(self.current_state.iterations) >= 3 else None
should_iterate, is_loop, bug_report, change_description = await self.get_user_feedback(
should_iterate, is_loop, should_redo, bug_report, change_description = await self.get_user_feedback(
run_command,
user_instructions,
last_iteration is not None,
)
if should_redo:
# ask user to provide more info
task_redo_info_question = await self.ask_question(
"Please provide more information about the task you want to redo",
buttons_only=False,
)
if task_redo_info_question.text:
self.next_state.current_task["redo_human_instructions"] = task_redo_info_question.text
self.next_state.current_task["redo_task_id"] = self.current_state.current_task["id"]
return AgentResponse.done(self)
if not should_iterate:
# User tested and reported no problems, we're done with the task
return await self.complete_task()
@ -235,7 +249,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
run_command: str,
user_instructions: str,
last_iteration: Optional[dict],
) -> tuple[bool, bool, str, str]:
) -> tuple[bool, bool, bool, str, str]:
"""
Ask the user to test the app and provide feedback.
@ -247,6 +261,8 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
If "is_loop" is True, Pythagora is stuck in a loop and needs to consider alternative solutions.
If "should_redo" is True, the user wants to redo the task and we need to reset the task and start over.
The last element in the tuple is the user feedback, which may be empty if the user provided no
feedback (eg. if they just clicked on "Continue" or "Start Pair Programming").
"""
@ -257,6 +273,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
is_loop = False
should_iterate = True
should_redo = False
extra_info = "restart_app" if not self.current_state.iterations else None
while True:
@ -273,6 +290,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
"continue": "Everything works",
"change": "I want to make a change",
"bug": "There is an issue",
"redo": "Redo task",
}
user_response = await self.ask_question(
@ -285,6 +303,10 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
)
extra_info = None
if user_response.button == "redo":
should_redo = True
break
if user_response.button == "continue" or user_response.cancelled:
should_iterate = False
break
@ -314,7 +336,7 @@ class Troubleshooter(ChatWithBreakdownMixin, IterationPromptMixin, RelevantFiles
await self.get_relevant_files_parallel(user_feedback=bug_report)
break
return should_iterate, is_loop, bug_report, change_description
return should_iterate, is_loop, should_redo, bug_report, change_description
def try_next_alternative_solution(self, user_feedback: str, user_feedback_qa: list[str]) -> AgentResponse:
"""

@ -3,7 +3,7 @@ from datetime import datetime
from typing import TYPE_CHECKING, Optional, Union
from uuid import UUID, uuid4
from sqlalchemy import ForeignKey, UniqueConstraint, delete, inspect, select
from sqlalchemy import ForeignKey, UniqueConstraint, and_, delete, inspect, select
from sqlalchemy.ext.asyncio import AsyncSession
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.orm.attributes import flag_modified
@ -558,3 +558,26 @@ class ProjectState(Base):
:return: True if the current epic is a feature, False otherwise.
"""
return self.epics and self.current_epic and self.current_epic.get("source") == "feature"
@staticmethod
async def get_state_for_redo_task(session: AsyncSession, project_state: "ProjectState") -> Optional["ProjectState"]:
states_result = await session.execute(
select(ProjectState).where(
and_(
ProjectState.step_index <= project_state.step_index,
ProjectState.branch_id == project_state.branch_id,
)
)
)
result = states_result.scalars().all()
result = sorted(result, key=lambda x: x.step_index, reverse=True)
for state in result:
if state.tasks:
for task in state.tasks:
if task.get("id") == project_state.current_task.get("id") and task.get("instructions") is None:
if task.get("status") == TaskStatus.TODO:
return state
return None

@ -48,6 +48,14 @@ We've broken the development of this {% if state.epics|length > 1 %}feature{% el
You are currently working on task #{{ current_task_index + 1 }} with the following description:
```
{{ task.description }}
{% if redo_task_user_feedback is defined and redo_task_user_feedback %}
You tried implementing this task before but you were unsuccessful. Here is what a human developer told you about what to watch out for while you're implementing this task so you don't make the same mistakes again:
---START_OF_USER_FEEDBACK---
{{ redo_task_user_feedback }}
---END_OF_USER_FEEDBACK---
{% endif %}
```
{% if related_api_endpoints|length > 0 %}
In this task, you need to focus on implementing the following endpoints:{% for api in related_api_endpoints %}{{ "`" ~ api.endpoint ~ "`" }}{% if not loop.last %},{% endif %}{% endfor %}

@ -94,6 +94,9 @@ class StateManager:
async def get_branches_for_project_id(self, project_id: UUID) -> list[Branch]:
return await Project.get_branches_for_project_id(self.current_session, project_id)
async def get_project_state_for_redo_task(self, project_state: ProjectState) -> Optional[ProjectState]:
return await ProjectState.get_state_for_redo_task(self.current_session, project_state)
async def find_user_input(self, project_state, branch_id) -> Optional[list["UserInput"]]:
return await UserInput.find_user_inputs(self.current_session, project_state, branch_id)

Loading…
Cancel
Save