Skip to content

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

decompose reply to human and summary

黄伟韬beb66b05b42c
diff --git a/metagpt/prompts/di/role_zero.py b/metagpt/prompts/di/role_zero.py
index 80a505d17..caba52e57 100644
--- a/metagpt/prompts/di/role_zero.py
+++ b/metagpt/prompts/di/role_zero.py
@@ -223,8 +223,9 @@ REPORT_TO_HUMAN_PROMPT = """
# Restrictions
{requirements_constraints}
-Your have just finish all tasks, Use "RoleZero.reply_to_human" to answer the user requirements.
-Report to human what you have done. Do Not ouput any other format.
+You have just finished all tasks.
+Reply to the human requirements.
+Do not output any other format.
Your reply is:
"""
@@ -233,8 +234,6 @@ SUMMARY_PROMPY = """
{requirements_constraints}
You have just completed some tasks.
-You must reply to human what you have done and what is the result.
-If there are any deliverables, provide descriptions and file paths.
-Do Not ouput any other format. limited in 300 words.
-Your reply is:
+Summarize the tasks you have accomplished without including detailed information.
+If there are any deliverables, list their descriptions and provide their file paths.
"""
diff --git a/metagpt/roles/di/role_zero.py b/metagpt/roles/di/role_zero.py
index 59714b726..8dfd888d2 100644
--- a/metagpt/roles/di/role_zero.py
+++ b/metagpt/roles/di/role_zero.py
@@ -26,6 +26,7 @@ from metagpt.prompts.di.role_zero import (
QUICK_THINK_PROMPT,
QUICK_THINK_SYSTEM_PROMPT,
REGENERATE_PROMPT,
+ REPORT_TO_HUMAN_PROMPT,
ROLE_INSTRUCTION,
SUMMARY_PROMPY,
SYSTEM_PROMPT,
@@ -68,6 +69,8 @@ class RoleZero(Role):
react_mode: Literal["react"] = "react"
max_react_loop: int = 20 # used for react mode
+ # Summary Mode
+ use_summary: bool = True
# Tools
tools: list[str] = [] # Use special symbol ["<all>"] to indicate use of all registered tools
tool_recommender: Optional[ToolRecommender] = None
@@ -482,25 +485,21 @@ class RoleZero(Role):
async def _end(self):
self._set_state(-1)
-
- # summary
- memory = self.get_memories(k=self.memory_k)
- summary_prompt = SUMMARY_PROMPY.format(
- requirements_constraints=self.requirements_constraints,
- )
- reply_content = await self.llm.aask(self.llm.format_msg(memory + [UserMessage(summary_prompt)]))
# Ensure reply to the human before the "end" command is executed.
- need_reply = True
- for memory in self.get_memories(k=5)[::-1]:
- if "reply_to_human" in memory.content:
- need_reply = False
- break
- if "[Message]" in memory.content:
- # Receive new message from other
- need_reply = True
- break
- if need_reply:
+ if not any(["reply_to_human" in memory.content for memory in self.get_memories(k=5)]):
+ memory = self.rc.memory.get(self.memory_k)
+ reply_to_human_prompt = REPORT_TO_HUMAN_PROMPT.format(
+ requirements_constraints=self.requirements_constraints,
+ )
+ reply_content = await self.llm.aask(self.llm.format_msg(memory + [UserMessage(reply_to_human_prompt)]))
await self.reply_to_human(content=reply_content)
self.rc.memory.add(AIMessage(content=reply_content, cause_by=RunCommand))
-
- return reply_content
+ outputs = ""
+ # Summary of the Completed Task and Deliverables
+ if self.use_summary:
+ memory = self.rc.memory.get(self.memory_k)
+ summary_prompt = SUMMARY_PROMPY.format(
+ requirements_constraints=self.requirements_constraints,
+ )
+ outputs = await self.llm.aask(self.llm.format_msg(memory + [UserMessage(summary_prompt)]))
+ return outputs
diff --git a/metagpt/roles/di/team_leader.py b/metagpt/roles/di/team_leader.py
index 97100f295..112ca5a84 100644
--- a/metagpt/roles/di/team_leader.py
+++ b/metagpt/roles/di/team_leader.py
@@ -30,6 +30,8 @@ class TeamLeader(RoleZero):
experience_retriever: Annotated[ExpRetriever, Field(exclude=True)] = SimpleExpRetriever()
+ use_summary: bool = False
+
def _update_tool_execution(self):
self.tool_execution_map.update(
{