Skip to content

Commit

Permalink
Merge pull request #1044 from Pythagora-io/move-docs-check
Browse files Browse the repository at this point in the history
Only check for docs if the user wants to run the task.
  • Loading branch information
LeonOstrez authored Jul 4, 2024
2 parents de8ae61 + 64e407d commit bd0afbe
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
10 changes: 9 additions & 1 deletion core/agents/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from core.agents.convo import AgentConvo
from core.agents.response import AgentResponse, ResponseType
from core.db.models.project_state import TaskStatus
from core.db.models.specification import Complexity
from core.llm.parser import JSONParser
from core.log import get_logger
from core.telemetry import telemetry
Expand Down Expand Up @@ -77,10 +78,17 @@ async def run(self) -> AgentResponse:

# By default, we want to ask the user if they want to run the task,
# except in certain cases (such as they've just edited it).
if not self.current_state.current_task.get("run_always", False):
# The check for docs is here to prevent us from asking the user whether we should
# run the task twice - we'll only ask if we haven't yet checked for docs.
if not self.current_state.current_task.get("run_always", False) and self.current_state.docs is None:
if not await self.ask_to_execute_task():
return AgentResponse.done(self)

if self.current_state.docs is None and self.current_state.specification.complexity != Complexity.SIMPLE:
# We check for external docs here, to make sure we only fetch the docs
# if the task is actually being done.
return AgentResponse.external_docs_required(self)

return await self.breakdown_current_task()

async def breakdown_current_iteration(self, review_feedback: Optional[str] = None) -> AgentResponse:
Expand Down
6 changes: 2 additions & 4 deletions core/agents/orchestrator.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from core.agents.tech_writer import TechnicalWriter
from core.agents.troubleshooter import Troubleshooter
from core.db.models.project_state import TaskStatus
from core.db.models.specification import Complexity
from core.log import get_logger
from core.telemetry import telemetry
from core.ui.base import ProjectStage
Expand Down Expand Up @@ -180,6 +179,8 @@ def create_agent(self, prev_response: Optional[AgentResponse]) -> BaseAgent:
return Developer(self.state_manager, self.ui, prev_response=prev_response)
if prev_response.type == ResponseType.IMPORT_PROJECT:
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 not state.specification.description:
if state.files:
Expand All @@ -199,9 +200,6 @@ def create_agent(self, prev_response: Optional[AgentResponse]) -> BaseAgent:
# Ask the Tech Lead to break down the initial project or feature into tasks and apply project templates
return TechLead(self.state_manager, self.ui, process_manager=self.process_manager)

if state.current_task and state.docs is None and state.specification.complexity != Complexity.SIMPLE:
return ExternalDocumentation(self.state_manager, self.ui)

# Current task status must be checked before Developer is called because we might want
# to skip it instead of breaking it down
current_task_status = state.current_task.get("status") if state.current_task else None
Expand Down
7 changes: 7 additions & 0 deletions core/agents/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class ResponseType(str, Enum):
IMPORT_PROJECT = "import-project"
"""User wants to import an existing project."""

EXTERNAL_DOCS_REQUIRED = "external-docs-required"
"""We need to fetch external docs for a task."""


class AgentResponse:
type: ResponseType = ResponseType.DONE
Expand Down Expand Up @@ -137,3 +140,7 @@ def task_review_feedback(agent: "BaseAgent", feedback: str) -> "AgentResponse":
@staticmethod
def import_project(agent: "BaseAgent") -> "AgentResponse":
return AgentResponse(type=ResponseType.IMPORT_PROJECT, agent=agent)

@staticmethod
def external_docs_required(agent: "BaseAgent") -> "AgentResponse":
return AgentResponse(type=ResponseType.EXTERNAL_DOCS_REQUIRED, agent=agent)

0 comments on commit bd0afbe

Please sign in to comment.