Skip to content

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

fix conflict

geekana5b6d0817d74
diff --git a/examples/debate_simple.py b/examples/debate_simple.py
index 524449771..fe04a7d1a 100644
--- a/examples/debate_simple.py
+++ b/examples/debate_simple.py
@@ -7,16 +7,16 @@
"""
import asyncio
-from metagpt.actions import Action, UserRequirement
+from metagpt.actions import Action
from metagpt.environment import Environment
from metagpt.roles import Role
from metagpt.team import Team
-action1 = Action(name="BidenSay", instruction="发表政见,充满激情的反驳特朗普最新消息,尽最大努力获得选票")
-action2 = Action(name="TrumpSay", instruction="发表政见,充满激情的反驳拜登最新消息,尽最大努力获得选票,MAGA!")
-biden = Role(name="拜登", profile="民主党候选人", goal="大选获胜", actions=[action1], watch=[action2, UserRequirement])
-trump = Role(name="特朗普", profile="共和党候选人", goal="大选获胜", actions=[action2], watch=[action1])
+action1 = Action(name="BidenSay", instruction="Passionately refute Trump's latest news, and strive to gain votes")
+action2 = Action(name="TrumpSay", instruction="Passionately refute Biden's latest news, and strive to gain votes")
+biden = Role(name="Biden", profile="Democratic candidate", goal="Win the election", actions=[action1], watch=[action2])
+trump = Role(name="Trump", profile="Republican candidate", goal="Win the election", actions=[action2], watch=[action1])
env = Environment(desc="US election live broadcast")
team = Team(investment=10.0, env=env, roles=[biden, trump])
-asyncio.run(team.run(idea="主题:气候变化,用中文辩论", n_round=5))
+asyncio.run(team.run(idea="Topic: Climate Change", send_to="Biden", n_round=5))
diff --git a/metagpt/roles/role.py b/metagpt/roles/role.py
index 6c3a4f758..404e05093 100644
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@ -146,7 +146,7 @@ class Role(BaseModel):
_states: list[str] = []
_actions: list[Action] = []
_rc: RoleContext = Field(default_factory=RoleContext)
- _subscription: tuple[str] = set()
+ subscription: set[str] = set()
# builtin variables
recovered: bool = False # to tag if a recovered role
@@ -185,7 +185,7 @@ class Role(BaseModel):
# 关于私有变量的初始化 https://github.com/pydantic/pydantic/issues/655
self._private_attributes["_llm"] = LLM() if not self.is_human else HumanProvider()
self._private_attributes["_role_id"] = str(self._setting)
- self._private_attributes["_subscription"] = {any_to_str(self), self.name} if self.name else {any_to_str(self)}
+ self.subscription = {any_to_str(self), self.name} if self.name else {any_to_str(self)}
for key in self._private_attributes.keys():
if key in kwargs:
@@ -327,9 +327,9 @@ class Role(BaseModel):
buffer to be further processed in _observe. By default, a Role subscribes Messages with a tag of its own name
or profile.
"""
- self._subscription = tags
+ self.subscription = tags
if self._rc.env: # According to the routing feature plan in Chapter 2.2.3.2 of RFC 113
- self._rc.env.set_subscription(self, self._subscription)
+ self._rc.env.set_subscription(self, self.subscription)
def _set_state(self, state: int):
"""Update the current state."""
@@ -342,7 +342,7 @@ class Role(BaseModel):
messages by observing."""
self._rc.env = env
if env:
- env.set_subscription(self, self._subscription)
+ env.set_subscription(self, self.subscription)
self.refresh_system_message() # add env message to system message
@property
@@ -431,7 +431,7 @@ class Role(BaseModel):
observed_pure = [msg.dict(exclude={"id": True}) for msg in observed]
existed_pure = [msg.dict(exclude={"id": True}) for msg in existed]
for idx, new in enumerate(observed_pure):
- if new["cause_by"] in self._rc.watch and new not in existed_pure:
+ if (new["cause_by"] in self._rc.watch or self.name in new["send_to"]) and new not in existed_pure:
news.append(observed[idx])
return news
diff --git a/metagpt/team.py b/metagpt/team.py
index 625903e3e..fd9af9045 100644
--- a/metagpt/team.py
+++ b/metagpt/team.py
@@ -124,10 +124,10 @@ class Team(BaseModel):
logger.info(self.json(ensure_ascii=False))
@serialize_decorator
- async def run(self, n_round=3, idea="", auto_archive=True):
+ async def run(self, n_round=3, idea="", send_to="", auto_archive=True):
"""Run company until target round or no money"""
if idea:
- self.run_project(idea=idea)
+ self.run_project(idea=idea, send_to=send_to)
while n_round > 0:
# self._save()