diff --git a/examples/debate.py b/examples/debate.py index 630f78cd8..597b44e8d 100644 --- a/examples/debate.py +++ b/examples/debate.py @@ -15,6 +15,7 @@ from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Message from metagpt.software_company import SoftwareCompany +from metagpt.utils.common import any_to_str class ShoutOut(Action): @@ -101,7 +102,9 @@ class Biden(Role): await super()._observe() # accept the very first human instruction (the debate topic) or messages sent (from opponent) to self, # disregard own messages from the last round - self._rc.news = [msg for msg in self._rc.news if msg.cause_by == BossRequirement or msg.send_to == {self.name}] + self._rc.news = [ + msg for msg in self._rc.news if msg.cause_by == any_to_str(BossRequirement) or msg.send_to == {self.name} + ] return len(self._rc.news) async def _act(self) -> Message: diff --git a/metagpt/roles/engineer.py b/metagpt/roles/engineer.py index 960f9c0f3..535a1e27f 100644 --- a/metagpt/roles/engineer.py +++ b/metagpt/roles/engineer.py @@ -141,13 +141,13 @@ class Engineer(Role): logger.info(todo) logger.info(code_rsp) # self.write_file(todo, code) - msg = Message(content=code_rsp, role=self.profile, cause_by=any_to_str(self._rc.todo)) + msg = Message(content=code_rsp, role=self.profile, cause_by=self._rc.todo) self._rc.memory.add(msg) self.publish_message(msg) del self.todos[0] logger.info(f"Done {self.get_workspace()} generating.") - msg = Message(content="all done.", role=self.profile, cause_by=any_to_str(self._rc.todo)) + msg = Message(content="all done.", role=self.profile, cause_by=self._rc.todo) return msg async def _act_sp(self) -> Message: @@ -158,7 +158,7 @@ class Engineer(Role): # logger.info(code_rsp) # code = self.parse_code(code_rsp) file_path = self.write_file(todo, code) - msg = Message(content=code, role=self.profile, cause_by=any_to_str(self._rc.todo)) + msg = Message(content=code, role=self.profile, cause_by=self._rc.todo) self._rc.memory.add(msg) self.publish_message(msg) @@ -169,7 +169,7 @@ class Engineer(Role): msg = Message( content=MSG_SEP.join(code_msg_all), role=self.profile, - cause_by=any_to_str(self._rc.todo), + cause_by=self._rc.todo, send_to="Edward", ) return msg @@ -211,7 +211,7 @@ class Engineer(Role): msg = Message( content=MSG_SEP.join(code_msg_all), role=self.profile, - cause_by=any_to_str(self._rc.todo), + cause_by=self._rc.todo, send_to="Edward", ) return msg diff --git a/metagpt/roles/qa_engineer.py b/metagpt/roles/qa_engineer.py index 0f932ebfb..760b65736 100644 --- a/metagpt/roles/qa_engineer.py +++ b/metagpt/roles/qa_engineer.py @@ -22,7 +22,7 @@ from metagpt.const import WORKSPACE_ROOT from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Message -from metagpt.utils.common import CodeParser, any_to_str, any_to_str_set, parse_recipient +from metagpt.utils.common import CodeParser, any_to_str_set, parse_recipient from metagpt.utils.special_tokens import FILENAME_CODE_SEP, MSG_SEP @@ -99,7 +99,7 @@ class QaEngineer(Role): msg = Message( content=str(file_info), role=self.profile, - cause_by=any_to_str(WriteTest), + cause_by=WriteTest, sent_from=self.profile, send_to=self.profile, ) @@ -133,9 +133,7 @@ class QaEngineer(Role): recipient = parse_recipient(result_msg) # the recipient might be Engineer or myself content = str(file_info) + FILENAME_CODE_SEP + result_msg - msg = Message( - content=content, role=self.profile, cause_by=any_to_str(RunCode), sent_from=self.profile, send_to=recipient - ) + msg = Message(content=content, role=self.profile, cause_by=RunCode, sent_from=self.profile, send_to=recipient) self.publish_message(msg) async def _debug_error(self, msg): @@ -147,7 +145,7 @@ class QaEngineer(Role): msg = Message( content=file_info, role=self.profile, - cause_by=any_to_str(DebugError), + cause_by=DebugError, sent_from=self.profile, send_to=recipient, ) @@ -165,7 +163,7 @@ class QaEngineer(Role): result_msg = Message( content=f"Exceeding {self.test_round_allowed} rounds of tests, skip (writing code counts as a round, too)", role=self.profile, - cause_by=any_to_str(WriteTest), + cause_by=WriteTest, sent_from=self.profile, ) return result_msg @@ -189,7 +187,7 @@ class QaEngineer(Role): result_msg = Message( content=f"Round {self.test_round} of tests done", role=self.profile, - cause_by=any_to_str(WriteTest), + cause_by=WriteTest, sent_from=self.profile, ) return result_msg diff --git a/metagpt/roles/researcher.py b/metagpt/roles/researcher.py index 8d5e43fab..29889b8ec 100644 --- a/metagpt/roles/researcher.py +++ b/metagpt/roles/researcher.py @@ -15,7 +15,6 @@ from metagpt.const import RESEARCH_PATH from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Message -from metagpt.utils.common import any_to_str class Report(BaseModel): @@ -64,20 +63,18 @@ class Researcher(Role): research_system_text = get_research_system_text(topic, self.language) if isinstance(todo, CollectLinks): links = await todo.run(topic, 4, 4) - ret = Message("", Report(topic=topic, links=links), role=self.profile, cause_by=any_to_str(todo)) + ret = Message("", Report(topic=topic, links=links), role=self.profile, cause_by=todo) elif isinstance(todo, WebBrowseAndSummarize): links = instruct_content.links todos = (todo.run(*url, query=query, system_text=research_system_text) for (query, url) in links.items()) summaries = await asyncio.gather(*todos) summaries = list((url, summary) for i in summaries for (url, summary) in i.items() if summary) - ret = Message("", Report(topic=topic, summaries=summaries), role=self.profile, cause_by=any_to_str(todo)) + ret = Message("", Report(topic=topic, summaries=summaries), role=self.profile, cause_by=todo) else: summaries = instruct_content.summaries summary_text = "\n---\n".join(f"url: {url}\nsummary: {summary}" for (url, summary) in summaries) content = await self._rc.todo.run(topic, summary_text, system_text=research_system_text) - ret = Message( - "", Report(topic=topic, content=content), role=self.profile, cause_by=any_to_str(self._rc.todo) - ) + ret = Message("", Report(topic=topic, content=content), role=self.profile, cause_by=self._rc.todo) self._rc.memory.add(ret) return ret diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py index ccad0b018..5c512b0f0 100644 --- a/metagpt/roles/role.py +++ b/metagpt/roles/role.py @@ -210,10 +210,10 @@ class Role: content=response.content, instruct_content=response.instruct_content, role=self.profile, - cause_by=any_to_str(self._rc.todo), + cause_by=self._rc.todo, ) else: - msg = Message(content=response, role=self.profile, cause_by=any_to_str(self._rc.todo)) + msg = Message(content=response, role=self.profile, cause_by=self._rc.todo) return msg diff --git a/metagpt/roles/seacher.py b/metagpt/roles/seacher.py index a37143196..587698d1d 100644 --- a/metagpt/roles/seacher.py +++ b/metagpt/roles/seacher.py @@ -12,7 +12,6 @@ from metagpt.logs import logger from metagpt.roles import Role from metagpt.schema import Message from metagpt.tools import SearchEngineType -from metagpt.utils.common import any_to_str class Searcher(Role): @@ -64,10 +63,10 @@ class Searcher(Role): content=response.content, instruct_content=response.instruct_content, role=self.profile, - cause_by=any_to_str(self._rc.todo), + cause_by=self._rc.todo, ) else: - msg = Message(content=response, role=self.profile, cause_by=any_to_str(self._rc.todo)) + msg = Message(content=response, role=self.profile, cause_by=self._rc.todo) self._rc.memory.add(msg) return msg