🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
support Message() without content param
better62964c5673d6a0a
diff --git a/examples/search_kb.py b/examples/search_kb.pyindex 7a9911ca2..5d61bbe02 100644--- a/examples/search_kb.py+++ b/examples/search_kb.py@@ -31,8 +31,8 @@ async def search():role = Sales(profile="Sales", store=store)role._watch({Action})queries = [- Message("Which facial cleanser is good for oily skin?", cause_by=Action),- Message("Is L'Oreal good to use?", cause_by=Action),+ Message(content="Which facial cleanser is good for oily skin?", cause_by=Action),+ Message(content="Is L'Oreal good to use?", cause_by=Action),]for query in queries:logger.info(f"User: {query}")diff --git a/metagpt/roles/researcher.py b/metagpt/roles/researcher.pyindex e894d1a57..162d72b9b 100644--- a/metagpt/roles/researcher.py+++ b/metagpt/roles/researcher.py@@ -54,18 +54,27 @@ class Researcher(Role):research_system_text = self.research_system_text(topic, todo)if isinstance(todo, CollectLinks):links = await todo.run(topic, 4, 4)- ret = Message("", Report(topic=topic, links=links), role=self.profile, cause_by=todo)+ ret = Message(+ content="", instruct_content=Report(topic=topic, links=links), role=self.profile, cause_by=todo+ )elif isinstance(todo, WebBrowseAndSummarize):links = instruct_content.linkstodos = (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=todo)+ ret = Message(+ content="", instruct_content=Report(topic=topic, summaries=summaries), role=self.profile, cause_by=todo+ )else:summaries = instruct_content.summariessummary_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=self._rc.todo)+ ret = Message(+ content="",+ instruct_content=Report(topic=topic, content=content),+ role=self.profile,+ cause_by=self._rc.todo,+ )self._rc.memory.add(ret)return retdiff --git a/metagpt/schema.py b/metagpt/schema.pyindex 4a9df7fe2..d3c836d8e 100644--- a/metagpt/schema.py+++ b/metagpt/schema.py@@ -110,7 +110,7 @@ class Message(BaseModel):sent_from: str = ""send_to: Set = Field(default_factory={MESSAGE_ROUTE_TO_ALL})- def __init__(self, **kwargs):+ def __init__(self, content: str = "", **kwargs):ic = kwargs.get("instruct_content", None)if ic and not isinstance(ic, BaseModel) and "class" in ic:# compatible with custom-defined ActionOutput@@ -122,6 +122,7 @@ class Message(BaseModel):kwargs["instruct_content"] = ic_newkwargs["id"] = kwargs.get("id", uuid.uuid4().hex)+ kwargs["content"] = kwargs.get("content", content)kwargs["cause_by"] = any_to_str(kwargs.get("cause_by", import_class("UserRequirement", "metagpt.actions.add_requirement")))diff --git a/metagpt/subscription.py b/metagpt/subscription.pyindex 0d2b30821..607cbdb8d 100644--- a/metagpt/subscription.py+++ b/metagpt/subscription.py@@ -19,7 +19,7 @@ class SubscriptionRunner(BaseModel):>>> async def trigger():... while True:- ... yield Message("the latest news about OpenAI")+ ... yield Message(content="the latest news about OpenAI")... await asyncio.sleep(3600 * 24)>>> async def callback(msg: Message):diff --git a/tests/metagpt/test_message.py b/tests/metagpt/test_message.pyindex 04d85d9e4..8f267ba54 100644--- a/tests/metagpt/test_message.py+++ b/tests/metagpt/test_message.py@@ -23,7 +23,7 @@ def test_all_messages():UserMessage(test_content),SystemMessage(test_content),AIMessage(test_content),- Message(test_content, role="QA"),+ Message(content=test_content, role="QA"),]for msg in msgs:assert msg.content == test_contentdiff --git a/tests/metagpt/test_subscription.py b/tests/metagpt/test_subscription.pyindex 2e898424d..75e06411c 100644--- a/tests/metagpt/test_subscription.py+++ b/tests/metagpt/test_subscription.py@@ -13,12 +13,12 @@ async def test_subscription_run():async def trigger():while True:- yield Message("the latest news about OpenAI")+ yield Message(content="the latest news about OpenAI")await asyncio.sleep(3600 * 24)class MockRole(Role):async def run(self, message=None):- return Message("")+ return Message(content="")async def callback(message):nonlocal callback_done@@ -61,11 +61,11 @@ async def test_subscription_run():async def test_subscription_run_error(loguru_caplog):async def trigger1():while True:- yield Message("the latest news about OpenAI")+ yield Message(content="the latest news about OpenAI")await asyncio.sleep(3600 * 24)async def trigger2():- yield Message("the latest news about OpenAI")+ yield Message(content="the latest news about OpenAI")class MockRole1(Role):async def run(self, message=None):@@ -73,7 +73,7 @@ async def test_subscription_run_error(loguru_caplog):class MockRole2(Role):async def run(self, message=None):- return Message("")+ return Message(content="")async def callback(msg: Message):print(msg)diff --git a/tests/metagpt/utils/test_common.py b/tests/metagpt/utils/test_common.pyindex 4bd38db63..0ab34437d 100644--- a/tests/metagpt/utils/test_common.py+++ b/tests/metagpt/utils/test_common.py@@ -47,7 +47,7 @@ class TestGetProjectRoot:Input(x=RunCode, want="metagpt.actions.run_code.RunCode"),Input(x=RunCode(), want="metagpt.actions.run_code.RunCode"),Input(x=Message, want="metagpt.schema.Message"),- Input(x=Message(""), want="metagpt.schema.Message"),+ Input(x=Message(content=""), want="metagpt.schema.Message"),Input(x="A", want="A"),]for i in inputs: