Skip to content

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

feat: rm AISelfMessage

莘权 马7616d8c6d3e3
diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py
index f615c8f8c..a76db09b1 100644
--- a/metagpt/roles/engineer.py
+++ b/metagpt/roles/engineer.py
@@ -39,6 +39,7 @@ from metagpt.actions.write_code_plan_and_change_an import WriteCodePlanAndChange
from metagpt.const import (
BUGFIX_FILENAME,
CODE_PLAN_AND_CHANGE_FILE_REPO,
+ MESSAGE_ROUTE_TO_SELF,
REQUIREMENT_FILENAME,
SYSTEM_DESIGN_FILE_REPO,
TASK_FILE_REPO,
@@ -47,7 +48,6 @@ from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import (
AIMessage,
- AISelfMessage,
CodePlanAndChangeContext,
CodeSummarizeContext,
CodingContext,
@@ -173,7 +173,9 @@ class Engineer(Role):
async def _act_write_code(self):
await self._act_sp_with_cr(review=self.use_code_review)
- return AISelfMessage(content="", cause_by=WriteCodeReview if self.use_code_review else WriteCode)
+ return AIMessage(
+ content="", cause_by=WriteCodeReview if self.use_code_review else WriteCode, send_to=MESSAGE_ROUTE_TO_SELF
+ )
async def _act_summarize(self):
tasks = []
@@ -217,7 +219,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 AISelfMessage(content="", cause_by=SummarizeCode)
+ return AIMessage(content="", cause_by=SummarizeCode, send_to=MESSAGE_ROUTE_TO_SELF)
async def _act_code_plan_and_change(self):
"""Write code plan and change that guides subsequent WriteCode and WriteCodeReview"""
@@ -239,7 +241,7 @@ class Engineer(Role):
dependencies=dependencies,
)
- return AISelfMessage(content="", cause_by=WriteCodePlanAndChange)
+ return AIMessage(content="", cause_by=WriteCodePlanAndChange, send_to=MESSAGE_ROUTE_TO_SELF)
async def _is_pass(self, summary) -> (str, str):
rsp = await self.llm.aask(msg=IS_PASS_PROMPT.format(context=summary), stream=False)
diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py
index 825cd8017..f76baff3f 100644
--- a/metagpt/roles/qa_engineer.py
+++ b/metagpt/roles/qa_engineer.py
@@ -18,17 +18,10 @@
from metagpt.actions import DebugError, RunCode, UserRequirement, WriteTest
from metagpt.actions.prepare_documents import PrepareDocuments
from metagpt.actions.summarize_code import SummarizeCode
-from metagpt.const import MESSAGE_ROUTE_TO_NONE
+from metagpt.const import MESSAGE_ROUTE_TO_NONE, MESSAGE_ROUTE_TO_SELF
from metagpt.logs import logger
from metagpt.roles import Role
-from metagpt.schema import (
- AIMessage,
- AISelfMessage,
- Document,
- Message,
- RunCodeContext,
- TestingContext,
-)
+from metagpt.schema import AIMessage, Document, Message, RunCodeContext, TestingContext
from metagpt.utils.common import (
any_to_str,
any_to_str_set,
@@ -102,10 +95,7 @@ class QaEngineer(Role):
additional_python_paths=[str(self.context.src_workspace)],
)
self.publish_message(
- AISelfMessage(
- content=run_code_context.model_dump_json(),
- cause_by=WriteTest,
- )
+ AIMessage(content=run_code_context.model_dump_json(), cause_by=WriteTest, send_to=MESSAGE_ROUTE_TO_SELF)
)
logger.info(f"Done {str(self.project_repo.tests.workdir)} generating.")
@@ -147,7 +137,9 @@ class QaEngineer(Role):
code = await DebugError(i_context=run_code_context, context=self.context, llm=self.llm).run()
await self.project_repo.tests.save(filename=run_code_context.test_filename, content=code)
run_code_context.output = None
- self.publish_message(AISelfMessage(content=run_code_context.model_dump_json(), cause_by=DebugError))
+ self.publish_message(
+ AIMessage(content=run_code_context.model_dump_json(), cause_by=DebugError, send_to=MESSAGE_ROUTE_TO_SELF)
+ )
async def _act(self) -> Message:
if self.project_path:
diff --git a/metagpt/schema.py b/metagpt/schema.py
index ee8b1ca96..1b527b594 100644
--- a/metagpt/schema.py
+++ b/metagpt/schema.py
@@ -43,7 +43,6 @@ from metagpt.const import (
MESSAGE_ROUTE_FROM,
MESSAGE_ROUTE_TO,
MESSAGE_ROUTE_TO_ALL,
- MESSAGE_ROUTE_TO_SELF,
PRDS_FILE_REPO,
SYSTEM_DESIGN_FILE_REPO,
TASK_FILE_REPO,
@@ -400,13 +399,6 @@ class AIMessage(Message):
return self.metadata.get(AGENT, "")
-class AISelfMessage(AIMessage):
- def __init__(self, **kwargs):
- super().__init__(**kwargs)
- self.sent_from = MESSAGE_ROUTE_TO_SELF
- self.send_to = MESSAGE_ROUTE_TO_SELF
-
-
class Task(BaseModel):
task_id: str = ""
dependent_task_ids: list[str] = [] # Tasks prerequisite to this Task