Skip to content

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

fixbug: teacher role

莘权 马86e0e706191d
diff --git a/examples/fork_meta_role_write_teaching_plan.py b/examples/fork_meta_role_write_teaching_plan.py
index d2898605e..e529a9b46 100644
--- a/examples/fork_meta_role_write_teaching_plan.py
+++ b/examples/fork_meta_role_write_teaching_plan.py
@@ -90,8 +90,11 @@ async def startup(lesson_file: str, investment: float = 3.0, n_round: int = 1, *
configs = yaml.safe_load(reader)
startup_config = ProjectConfig(**configs)
- roles = UMLMetaRoleFactory.create_roles(startup_config.roles, **kwargs)
company = SoftwareCompany()
+ roles = UMLMetaRoleFactory.create_roles(role_configs=startup_config.roles,
+ options=company.options,
+ cost_manager=company.cost_manager,
+ **kwargs)
company.hire(roles)
company.invest(startup_config.startup.investment)
company.start_project(lesson, role=startup_config.startup.role,
diff --git a/examples/write_teaching_plan.py b/examples/write_teaching_plan.py
index 9874d10a5..6ab5edce4 100644
--- a/examples/write_teaching_plan.py
+++ b/examples/write_teaching_plan.py
@@ -77,7 +77,7 @@ async def startup(lesson_file: str, investment: float = 3.0, n_round: int = 1, *
lesson = demo_lesson
company = SoftwareCompany()
- company.hire([Teacher(*args, **kwargs)])
+ company.hire([Teacher(options=company.options, cost_manager=company.cost_manager, *args, **kwargs)])
company.invest(investment)
company.start_project(lesson, role="Teacher", cause_by=TeachingPlanRequirement)
await company.run(n_round=1)
diff --git a/metagpt/actions/meta_action.py b/metagpt/actions/meta_action.py
index 3f01b8c0f..4c52e7cfd 100644
--- a/metagpt/actions/meta_action.py
+++ b/metagpt/actions/meta_action.py
@@ -21,19 +21,22 @@ from metagpt.schema import Message
class MetaAction(Action):
- def __init__(self, options: MetaActionOptions, llm=None, **kwargs):
- super(MetaAction, self).__init__(options.name, kwargs.get("context"), llm=llm)
- self.prompt = options.format_prompt(**kwargs)
- self.options = options
+ def __init__(self, options, action_options: MetaActionOptions, llm=None, **kwargs):
+ super(MetaAction, self).__init__(options=options,
+ name=action_options.name,
+ context=kwargs.get("context"),
+ llm=llm)
+ self.prompt = action_options.format_prompt(**kwargs)
+ self.action_options = action_options
self.kwargs = kwargs
def __str__(self):
"""Return `topic` value when str()"""
- return self.options.topic
+ return self.action_options.topic
def __repr__(self):
"""Show `topic` value when debug"""
- return self.options.topic
+ return self.action_options.topic
async def run(self, messages, *args, **kwargs):
if len(messages) < 1 or not isinstance(messages[0], Message):
@@ -46,11 +49,11 @@ class MetaAction(Action):
return self.rsp
def _set_result(self, rsp):
- if self.options.rsp_begin_tag and self.options.rsp_begin_tag in rsp:
- ix = rsp.index(self.options.rsp_begin_tag)
- rsp = rsp[ix + len(self.options.rsp_begin_tag):]
- if self.options.rsp_end_tag and self.options.rsp_end_tag in rsp:
- ix = rsp.index(self.options.rsp_end_tag)
+ if self.action_options.rsp_begin_tag and self.action_options.rsp_begin_tag in rsp:
+ ix = rsp.index(self.action_options.rsp_begin_tag)
+ rsp = rsp[ix + len(self.action_options.rsp_begin_tag):]
+ if self.action_options.rsp_end_tag and self.action_options.rsp_end_tag in rsp:
+ ix = rsp.index(self.action_options.rsp_end_tag)
rsp = rsp[0:ix]
self.rsp = rsp.strip()
diff --git a/metagpt/roles/fork_meta_role.py b/metagpt/roles/fork_meta_role.py
index c21d08e37..5311bc4f0 100644
--- a/metagpt/roles/fork_meta_role.py
+++ b/metagpt/roles/fork_meta_role.py
@@ -26,10 +26,10 @@ from metagpt.schema import Message
class ForkMetaRole(Role):
"""A `fork` style meta role capable of generating arbitrary roles at runtime based on a configuration file"""
- def __init__(self, runtime_options, cost_manager, role_options, **kwargs):
+ def __init__(self, options, cost_manager, role_options, **kwargs):
"""Initialize a `fork` style meta role
- :param runtime_options: System configuration
+ :param options: System configuration
:param cost_manager: Cost manager
:param role_options: pattern yaml file data
:param args: Parameters passed in format: `python your_script.py arg1 arg2 arg3`
@@ -49,7 +49,7 @@ class ForkMetaRole(Role):
global_variables[k] = v
super(ForkMetaRole, self).__init__(
- options=runtime_options,
+ options=options,
cost_manager=cost_manager,
name=global_variables["name"],
profile=global_variables["profile"],
@@ -70,7 +70,7 @@ class ForkMetaRole(Role):
o = MetaActionOptions(**m)
o.set_default_template(opts.templates[o.template_ix])
- act = MetaAction(options=o, llm=self._llm, **m)
+ act = MetaAction(options=options, action_options=o, llm=self._llm, **m)
actions.append(act)
self._init_actions(actions)
requirement_types = set()
diff --git a/metagpt/roles/uml_meta_role_factory.py b/metagpt/roles/uml_meta_role_factory.py
index 78f9689a2..42071b0a6 100644
--- a/metagpt/roles/uml_meta_role_factory.py
+++ b/metagpt/roles/uml_meta_role_factory.py
@@ -33,7 +33,7 @@ class UMLMetaRoleFactory:
raise NotImplementedError(
f"{opt.role_type} is not implemented"
)
- r = constructor(m, **kwargs)
+ r = constructor(role_options=m, **kwargs)
roles.append(r)
return roles