refactor: 软件公司message用来与team leader通讯

This commit is contained in:
莘权 马 2024-05-09 19:01:16 +08:00
parent 7571753a53
commit 9be140a421
5 changed files with 45 additions and 9 deletions

View file

@ -24,7 +24,7 @@ from metagpt.actions.design_api_an import (
)
from metagpt.const import DATA_API_DESIGN_FILE_REPO, SEQ_FLOW_FILE_REPO
from metagpt.logs import logger
from metagpt.schema import Document, Documents, Message
from metagpt.schema import AIMessage, Document, Documents, Message
from metagpt.utils.mermaid import mermaid_to_file
from metagpt.utils.report import DocsReporter, GalleryReporter
@ -68,6 +68,16 @@ class WriteDesign(Action):
logger.info("Nothing has changed.")
# Wait until all files under `docs/system_designs/` are processed before sending the publish message,
# leaving room for global optimization in subsequent steps.
return AIMessage(
content="Designing is complete. "
+ "\n".join(
list(self.repo.docs.system_design.changed_files.keys())
+ list(self.repo.resources.data_api_design.changed_files.keys())
+ list(self.repo.resources.seq_flow.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _new_system_design(self, context):
node = await DESIGN_API_NODE.fill(context=context, llm=self.llm, schema=self.prompt_schema)

View file

@ -17,7 +17,7 @@ from metagpt.actions.action import Action
from metagpt.actions.project_management_an import PM_NODE, REFINED_PM_NODE
from metagpt.const import PACKAGE_REQUIREMENTS_FILENAME
from metagpt.logs import logger
from metagpt.schema import Document, Documents
from metagpt.schema import AIMessage, Document, Documents
from metagpt.utils.report import DocsReporter
NEW_REQ_TEMPLATE = """
@ -54,6 +54,16 @@ class WriteTasks(Action):
logger.info("Nothing has changed.")
# Wait until all files under `docs/tasks/` are processed before sending the publish_message, leaving room for
# global optimization in subsequent steps.
return AIMessage(
content="WBS is completed. "
+ "\n".join(
[PACKAGE_REQUIREMENTS_FILENAME]
+ list(self.repo.docs.task.changed_files.keys())
+ list(self.repo.resources.api_spec_and_task.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _update_tasks(self, filename):
system_design_doc = await self.repo.docs.system_design.get(filename)

View file

@ -15,7 +15,6 @@ from __future__ import annotations
import json
from pathlib import Path
from typing import Optional, Union
from metagpt.actions import Action, ActionOutput
from metagpt.actions.action_node import ActionNode
@ -67,7 +66,7 @@ class WritePRD(Action):
3. Requirement update: If the requirement is an update, the PRD document will be updated.
"""
async def run(self, with_messages, *args, **kwargs) -> Optional[Union[ActionOutput, Message]]:
async def run(self, with_messages, *args, **kwargs) -> Message:
"""Run the action."""
req: Document = await self.repo.requirement
docs: list[Document] = await self.repo.docs.prd.get_all()
@ -87,13 +86,23 @@ class WritePRD(Action):
else:
logger.info(f"New requirement detected: {req.content}")
await self._handle_new_requirement(req)
return AIMessage(
content="PRD is completed. "
+ "\n".join(
list(self.repo.docs.prd.changed_files.keys())
+ list(self.repo.resources.prd.changed_files.keys())
+ list(self.repo.resources.competitive_analysis.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _handle_bugfix(self, req: Document) -> Message:
# ... bugfix logic ...
await self.repo.docs.save(filename=BUGFIX_FILENAME, content=req.content)
await self.repo.docs.save(filename=REQUIREMENT_FILENAME, content="")
return AIMessage(
content="",
content=f"A new issue is received: {BUGFIX_FILENAME}",
cause_by=FixBug,
sent_from=self,
send_to="Alex", # the name of Engineer

View file

@ -182,6 +182,8 @@ class Engineer(Role):
async def _act_summarize(self):
tasks = []
for todo in self.summarize_todos:
if self.n_summarize >= self.config.max_auto_summarize_code:
break
summary = await todo.run()
summary_filename = Path(todo.i_context.design_filename).with_suffix(".md").name
dependencies = {todo.i_context.design_filename, todo.i_context.task_filename}
@ -203,11 +205,16 @@ class Engineer(Role):
)
else:
await self.project_repo.docs.code_summary.delete(filename=Path(todo.i_context.design_filename).name)
self.summarize_todos = []
logger.info(f"--max-auto-summarize-code={self.config.max_auto_summarize_code}")
if not tasks or self.config.max_auto_summarize_code == 0:
self.n_summarize = 0
return AIMessage(
content="",
content="Coding is complete. "
"\n".join(
list(self.project_repo.resources.code_summary.changed_files.keys())
+ list(self.project_repo.srcs.changed_files.keys())
),
cause_by=SummarizeCode,
sent_from=self,
send_to="Edward", # The name of QaEngineer
@ -410,7 +417,6 @@ class Engineer(Role):
self.summarize_todos.append(new_summarize)
if self.summarize_todos:
self.set_todo(self.summarize_todos[0])
self.summarize_todos.pop(0)
async def _new_code_plan_and_change_action(self, cause_by: str):
"""Create a WriteCodePlanAndChange action for subsequent to-do actions."""

View file

@ -157,7 +157,8 @@ class QaEngineer(Role):
await init_python_folder(self.project_repo.tests.workdir)
if self.test_round > self.test_round_allowed:
result_msg = AIMessage(
content=f"Exceeding {self.test_round_allowed} rounds of tests, skip (writing code counts as a round, too)",
content=f"Exceeding {self.test_round_allowed} rounds of tests, stop. "
+ "\n".join(list(self.project_repo.tests.changed_files.keys())),
cause_by=WriteTest,
sent_from=self.profile,
send_to=MESSAGE_ROUTE_TO_NONE,