fixbug: sent_from, send_to

This commit is contained in:
莘权 马 2024-05-10 11:53:21 +08:00
parent 1e6e9d3103
commit 9fa47aff03
7 changed files with 19 additions and 18 deletions

View file

@ -76,7 +76,6 @@ class WriteDesign(Action):
+ list(self.repo.resources.seq_flow.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _new_system_design(self, context):

View file

@ -62,7 +62,6 @@ class WriteTasks(Action):
+ list(self.repo.resources.api_spec_and_task.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _update_tasks(self, filename):

View file

@ -94,7 +94,6 @@ class WritePRD(Action):
+ list(self.repo.resources.competitive_analysis.changed_files.keys())
),
cause_by=self,
sent_from=self,
)
async def _handle_bugfix(self, req: Document) -> Message:
@ -104,7 +103,6 @@ class WritePRD(Action):
return AIMessage(
content=f"A new issue is received: {BUGFIX_FILENAME}",
cause_by=FixBug,
sent_from=self,
send_to="Alex", # the name of Engineer
)

View file

@ -81,6 +81,7 @@ MESSAGE_ROUTE_CAUSE_BY = "cause_by"
MESSAGE_META_ROLE = "role"
MESSAGE_ROUTE_TO_ALL = "<all>"
MESSAGE_ROUTE_TO_NONE = "<none>"
MESSAGE_ROUTE_TO_SELF = "<self>" # Add this tag to replace `ActionOutput`
REQUIREMENT_FILENAME = "requirement.txt"
BUGFIX_FILENAME = "bugfix.txt"

View file

@ -47,6 +47,7 @@ from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import (
AIMessage,
AISelfMessage,
CodePlanAndChangeContext,
CodeSummarizeContext,
CodingContext,
@ -172,12 +173,7 @@ class Engineer(Role):
async def _act_write_code(self):
await self._act_sp_with_cr(review=self.use_code_review)
return AIMessage(
content="",
cause_by=WriteCodeReview if self.use_code_review else WriteCode,
send_to=self,
sent_from=self,
)
return AISelfMessage(content="", cause_by=WriteCodeReview if self.use_code_review else WriteCode)
async def _act_summarize(self):
tasks = []
@ -216,7 +212,6 @@ class Engineer(Role):
+ list(self.project_repo.srcs.changed_files.keys())
),
cause_by=SummarizeCode,
sent_from=self,
send_to="Edward", # The name of QaEngineer
)
# The maximum number of times the 'SummarizeCode' action is automatically invoked, with -1 indicating unlimited.
@ -244,12 +239,7 @@ class Engineer(Role):
dependencies=dependencies,
)
return AIMessage(
content="",
cause_by=WriteCodePlanAndChange,
send_to=self,
sent_from=self,
)
return AISelfMessage(content="", cause_by=WriteCodePlanAndChange)
async def _is_pass(self, summary) -> (str, str):
rsp = await self.llm.aask(msg=IS_PASS_PROMPT.format(context=summary), stream=False)

View file

@ -30,6 +30,7 @@ from pydantic import BaseModel, ConfigDict, Field, SerializeAsAny, model_validat
from metagpt.actions import Action, ActionOutput
from metagpt.actions.action_node import ActionNode
from metagpt.actions.add_requirement import UserRequirement
from metagpt.const import MESSAGE_ROUTE_TO_SELF
from metagpt.context_mixin import ContextMixin
from metagpt.logs import logger
from metagpt.memory import Memory
@ -443,6 +444,11 @@ class Role(SerializationMixin, ContextMixin, BaseModel):
"""If the role belongs to env, then the role's messages will be broadcast to env"""
if not msg:
return
if MESSAGE_ROUTE_TO_SELF in msg.send_to:
msg.send_to.add(any_to_str(self))
msg.send_to.remove(MESSAGE_ROUTE_TO_SELF)
if not msg.sent_from or msg.sent_from == MESSAGE_ROUTE_TO_SELF:
msg.sent_from = any_to_str(self)
if all(to in {any_to_str(self), self.name} for to in msg.send_to): # Message to myself
self.put_message(msg)
return

View file

@ -43,6 +43,7 @@ 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,
@ -200,7 +201,7 @@ class Message(BaseModel):
"""list[<role>: <content>]"""
id: str = Field(default="", validate_default=True) # According to Section 2.2.3.1.1 of RFC 135
content: str
content: str # natural language for user or agent
instruct_content: Optional[BaseModel] = Field(default=None, validate_default=True)
role: str = "user" # system / user / assistant
cause_by: str = Field(default="", validate_default=True)
@ -399,6 +400,13 @@ 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