Skip to content

🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming

refactor: 清空了软件公司message中的无用内容

莘权 马7571753a53f3
diff --git a/metagpt/actions/design_api.py b/metagpt/actions/design_api.py
index 83139035a..25b9d3720 100644
--- a/metagpt/actions/design_api.py
+++ b/metagpt/actions/design_api.py
@@ -13,7 +13,7 @@ import json
from pathlib import Path
from typing import Optional
-from metagpt.actions import Action, ActionOutput
+from metagpt.actions import Action
from metagpt.actions.design_api_an import (
DATA_STRUCTURES_AND_INTERFACES,
DESIGN_API_NODE,
@@ -68,7 +68,6 @@ 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 ActionOutput(content=changed_files.model_dump_json(), instruct_content=changed_files)
async def _new_system_design(self, context):
node = await DESIGN_API_NODE.fill(context=context, llm=self.llm, schema=self.prompt_schema)
diff --git a/metagpt/actions/project_management.py b/metagpt/actions/project_management.py
index 5aace9fa9..9fb4b6119 100644
--- a/metagpt/actions/project_management.py
+++ b/metagpt/actions/project_management.py
@@ -14,7 +14,6 @@ import json
from typing import Optional
from metagpt.actions.action import Action
-from metagpt.actions.action_output import ActionOutput
from metagpt.actions.project_management_an import PM_NODE, REFINED_PM_NODE
from metagpt.const import PACKAGE_REQUIREMENTS_FILENAME
from metagpt.logs import logger
@@ -55,7 +54,6 @@ 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 ActionOutput(content=change_files.model_dump_json(), instruct_content=change_files)
async def _update_tasks(self, filename):
system_design_doc = await self.repo.docs.system_design.get(filename)
diff --git a/metagpt/actions/write_prd.py b/metagpt/actions/write_prd.py
index 02bd1d6d5..79284530c 100644
--- a/metagpt/actions/write_prd.py
+++ b/metagpt/actions/write_prd.py
@@ -15,6 +15,7 @@ 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
@@ -33,7 +34,7 @@ from metagpt.const import (
REQUIREMENT_FILENAME,
)
from metagpt.logs import logger
-from metagpt.schema import BugFixContext, Document, Documents, Message
+from metagpt.schema import AIMessage, Document, Documents, Message
from metagpt.utils.common import CodeParser
from metagpt.utils.file_repository import FileRepository
from metagpt.utils.mermaid import mermaid_to_file
@@ -66,7 +67,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) -> ActionOutput | Message:
+ async def run(self, with_messages, *args, **kwargs) -> Optional[Union[ActionOutput, Message]]:
"""Run the action."""
req: Document = await self.repo.requirement
docs: list[Document] = await self.repo.docs.prd.get_all()
@@ -82,20 +83,17 @@ class WritePRD(Action):
# if requirement is related to other documents, update them, otherwise create a new one
if related_docs := await self.get_related_docs(req, docs):
logger.info(f"Requirement update detected: {req.content}")
- return await self._handle_requirement_update(req, related_docs)
+ await self._handle_requirement_update(req, related_docs)
else:
logger.info(f"New requirement detected: {req.content}")
- return await self._handle_new_requirement(req)
+ await self._handle_new_requirement(req)
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="")
- bug_fix = BugFixContext(filename=BUGFIX_FILENAME)
- return Message(
- content=bug_fix.model_dump_json(),
- instruct_content=bug_fix,
- role="",
+ return AIMessage(
+ content="",
cause_by=FixBug,
sent_from=self,
send_to="Alex", # the name of Engineer
diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py
index e7b5cf219..0328fb28b 100644
--- a/metagpt/roles/engineer.py
+++ b/metagpt/roles/engineer.py
@@ -150,12 +150,6 @@ class Engineer(Role):
dependencies=list(dependencies),
content=coding_context.code_doc.content,
)
- AIMessage(
- content=coding_context.model_dump_json(),
- instruct_content=coding_context,
- cause_by=WriteCode,
- )
-
changed_files.add(coding_context.code_doc.filename)
if not changed_files:
logger.info("Nothing has changed.")
@@ -177,9 +171,9 @@ class Engineer(Role):
return await self.rc.todo.run(self.rc.history)
async def _act_write_code(self):
- changed_files = await self._act_sp_with_cr(review=self.use_code_review)
+ await self._act_sp_with_cr(review=self.use_code_review)
return AIMessage(
- content="\n".join(changed_files),
+ content="",
cause_by=WriteCodeReview if self.use_code_review else WriteCode,
send_to=self,
sent_from=self,
@@ -221,7 +215,7 @@ class Engineer(Role):
# The maximum number of times the 'SummarizeCode' action is automatically invoked, with -1 indicating unlimited.
# This parameter is used for debugging the workflow.
self.n_summarize += 1 if self.config.max_auto_summarize_code > self.n_summarize else 0
- return AIMessage(content=json.dumps(tasks), cause_by=SummarizeCode, send_to=self, sent_from=self)
+ return AIMessage(content="", cause_by=SummarizeCode, send_to=self, sent_from=self)
async def _act_code_plan_and_change(self):
"""Write code plan and change that guides subsequent WriteCode and WriteCodeReview"""
@@ -244,7 +238,7 @@ class Engineer(Role):
)
return AIMessage(
- content=code_plan_and_change,
+ content="",
cause_by=WriteCodePlanAndChange,
send_to=self,
sent_from=self,
diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py
index c5f22174f..2947c942f 100644
--- a/metagpt/roles/qa_engineer.py
+++ b/metagpt/roles/qa_engineer.py
@@ -21,7 +21,6 @@ from metagpt.actions.summarize_code import SummarizeCode
from metagpt.const import MESSAGE_ROUTE_TO_NONE
from metagpt.logs import logger
from metagpt.roles import Role
-from metagpt.utils.report import EditorReporter
from metagpt.schema import AIMessage, Document, Message, RunCodeContext, TestingContext
from metagpt.utils.common import (
any_to_str,
@@ -29,6 +28,7 @@ from metagpt.utils.common import (
init_python_folder,
parse_recipient,
)
+from metagpt.utils.report import EditorReporter
class QaEngineer(Role):
diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py
index b6f6b7d20..14aa7dbb5 100644
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@ -408,7 +408,7 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
elif isinstance(response, Message):
msg = response
else:
- msg = AIMessage(content=response, cause_by=self.rc.todo, sent_from=self)
+ msg = AIMessage(content=response or "", cause_by=self.rc.todo, sent_from=self)
if self.enable_memory:
self.rc.memory.add(msg)
diff --git a/metagpt/schema.py b/metagpt/schema.py
index 5fc1ae242..ba64c0f06 100644
--- a/metagpt/schema.py
+++ b/metagpt/schema.py
@@ -748,10 +748,6 @@ class CodeSummarizeContext(BaseModel):
return hash((self.design_filename, self.task_filename))
-class BugFixContext(BaseContext):
- filename: str = ""
-
-
class CodePlanAndChangeContext(BaseModel):
requirement: str = ""
issue: str = ""