需求:两个智能体,智能体一和智能体二
智能体一可以写文章,然后更具智能体二的建议进行修改;
智能体二可以看智能体一的输出并且给出智能体一的内容修改建议;
解决:
MetaGPT有watch观察方法作为外部数据进行思考和action具体代码如下
智能体一的角色和action定义
import asyncio
from metagpt.actions import Action, UserRequirement
from metagpt.logs import logger
from metagpt.roles import Role
from metagpt.schema import Message
from metagpt.environment import Environment
from metagpt.const import MESSAGE_ROUTE_TO_ALL
classroom = Environment()
# 学生写诗词
class WritePoem(Action):
name: str = "WritePoem"
PROMPT_TEMPLATE: str = """
Here is the historical conversation record : {msg} .
写一篇有human提供主题的100字发言稿,只返回生成的文稿不返回其他文本。如果老师提供了关于发言稿的修改建议,根据建议修改并返回。
language: chinese
your poem:
"""
async def run(self, msg: str):
prompt = self.PROMPT_TEMPLATE.format(msg = msg)
rsp = await self._aask(prompt)
return rsp
# 定义学生角色 使用学生的action并且input老师的检查反馈
class Student(Role):
name: str