🌟 The Multi-Agent Framework: First AI Software Company, Towards Natural Language Programming
Add UserRequirement to watch in default if the role is not set to watch
shenchucheng68f386589314
diff --git a/metagpt/roles/role.py b/metagpt/roles/role.pyindex b07541b09..1e7ebf711 100644--- a/metagpt/roles/role.py+++ b/metagpt/roles/role.py@@ -27,6 +27,7 @@ from pydantic import BaseModel, Fieldfrom metagpt.actions import Action, ActionOutputfrom metagpt.actions.action_node import ActionNode+from metagpt.actions.add_requirement import UserRequirementfrom metagpt.llm import LLM, HumanProviderfrom metagpt.logs import loggerfrom metagpt.memory import Memory@@ -126,7 +127,17 @@ class RoleContext(BaseModel):return self.memory.get()-class Role:+class _RoleInjector(type):+ def __call__(cls, *args, **kwargs):+ instance = super().__call__(*args, **kwargs)++ if not instance._rc.watch:+ instance._watch([UserRequirement])++ return instance+++class Role(metaclass=_RoleInjector):"""Role/Agent"""def __init__(self, name="", profile="", goal="", constraints="", desc="", is_human=False):@@ -141,6 +152,7 @@ class Role:self._rc = RoleContext()self._subscription = {any_to_str(self), name} if name else {any_to_str(self)}+def _reset(self):self._states = []self._actions = []diff --git a/metagpt/schema.py b/metagpt/schema.pyindex 758149efa..5aec378e4 100644--- a/metagpt/schema.py+++ b/metagpt/schema.py@@ -121,6 +121,10 @@ class Message(BaseModel)::param send_to: Specifies the target recipient or consumer for message delivery in the environment.:param role: Message meta info tells who sent this message."""+ if not cause_by:+ from metagpt.actions import UserRequirement+ cause_by = UserRequirement+super().__init__(id=uuid.uuid4().hex,content=content,