Skip to content

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

Merge branch 'main' into feat_basemodel

better62919d33110bffa
diff --cc examples/agent_creator.py
index 0b85b33a6,dbb6f735a..d4d7de3be
--- a/examples/agent_creator.py
+++ b/examples/agent_creator.py
@@@ -55,16 -55,19 +55,16 @@@ class CreateAgent(Action)
class AgentCreator(Role):
- def __init__(
- self,
- name: str = "Matrix",
- profile: str = "AgentCreator",
- agent_template: str = MULTI_ACTION_AGENT_CODE_EXAMPLE,
- **kwargs,
- ):
- super().__init__(name, profile, **kwargs)
+ name: str = "Matrix"
+ profile: str = "AgentCreator"
+ agent_template: str = MULTI_ACTION_AGENT_CODE_EXAMPLE
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
self._init_actions([CreateAgent])
- self.agent_template = agent_template
async def _act(self) -> Message:
- logger.info(f"{self._setting}: ready to {self._rc.todo}")
+ logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo
msg = self._rc.memory.get()[-1]
diff --cc examples/build_customized_agent.py
index 679aee948,ccdf7748a..7a7fa6b56
--- a/examples/build_customized_agent.py
+++ b/examples/build_customized_agent.py
@@@ -71,16 -76,18 +71,16 @@@ class SimpleCoder(Role)
class RunnableCoder(Role):
- def __init__(
- self,
- name: str = "Alice",
- profile: str = "RunnableCoder",
- **kwargs,
- ):
- super().__init__(name, profile, **kwargs)
+ name: str = "Alice"
+ profile: str = "RunnableCoder"
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
self._init_actions([SimpleWriteCode, SimpleRunCode])
- self._set_react_mode(react_mode="by_order")
+ self._set_react_mode(react_mode=RoleReactMode.BY_ORDER.value)
async def _act(self) -> Message:
- logger.info(f"{self._setting}: ready to {self._rc.todo}")
+ logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
# By choosing the Action by order under the hood
# todo will be first SimpleWriteCode() then SimpleRunCode()
todo = self._rc.todo
diff --cc metagpt/roles/researcher.py
index 29c879233,456e8baba..27f046878
--- a/metagpt/roles/researcher.py
+++ b/metagpt/roles/researcher.py
@@@ -24,23 -25,24 +24,23 @@@ class Report(BaseModel)
class Researcher(Role):
- def __init__(
- self,
- name: str = "David",
- profile: str = "Researcher",
- goal: str = "Gather information and conduct research",
- constraints: str = "Ensure accuracy and relevance of information",
- language: str = "en-us",
- **kwargs,
- ):
- super().__init__(name, profile, goal, constraints, **kwargs)
- self._init_actions([CollectLinks(name), WebBrowseAndSummarize(name), ConductResearch(name)])
- self._set_react_mode(react_mode="by_order")
- self.language = language
- if language not in ("en-us", "zh-cn"):
- logger.warning(f"The language `{language}` has not been tested, it may not work.")
+ name: str = "David"
+ profile: str = "Researcher"
+ goal: str = "Gather information and conduct research"
+ constraints: str = "Ensure accuracy and relevance of information"
+ language: str = "en-us"
+
+ def __init__(self, **kwargs):
+ super().__init__(**kwargs)
+ self._init_actions(
+ [CollectLinks(name=self.name), WebBrowseAndSummarize(name=self.name), ConductResearch(name=self.name)]
+ )
+ self._set_react_mode(react_mode=RoleReactMode.BY_ORDER.value)
+ if self.language not in ("en-us", "zh-cn"):
+ logger.warning(f"The language `{self.language}` has not been tested, it may not work.")
async def _act(self) -> Message:
- logger.info(f"{self._setting}: ready to {self._rc.todo}")
+ logger.info(f"{self._setting}: to do {self._rc.todo}({self._rc.todo.name})")
todo = self._rc.todo
msg = self._rc.memory.get(k=1)[0]
if isinstance(msg.instruct_content, Report):
diff --cc metagpt/roles/role.py
index 98d835281,d868e820f..b59f51929
--- a/metagpt/roles/role.py
+++ b/metagpt/roles/role.py
@@@ -204,7 -205,11 +205,10 @@@ class Role(BaseModel)
object.__setattr__(self, "builtin_class_name", self.__class__.__name__)
self.__fields__["builtin_class_name"].default = self.__class__.__name__
+ if "actions" in kwargs:
+ self._init_actions(kwargs["actions"])
+
- if "watch" in kwargs:
- self._watch(kwargs["watch"])
+ self._watch(kwargs.get("watch") or [UserRequirement])
def __init_subclass__(cls, **kwargs: Any) -> None:
super().__init_subclass__(**kwargs)