MetaGPT入门(二)

接着MetaGPT入门(一),在文件里再添加一个role类

python 复制代码
class SimpleCoder(Role):
    
    def __init__(
            self,
            name:str="Alice",
            profile:str="SimpleCoder",
            **kwargs
    ):
        super().__init__(name,profile,**kwargs)
        self._init_actions([WriteSimpleCode])

    async def _act(self) -> Message:
        #记录角色的相关信息
        logger.info(f'{self._setting}:ready to {self._rc.todo}')
        #获取需要执行的动作,todo will be SimpleWriteCode()
        todo = self._rc.todo
        #获取动作执行需要的信息
        msg = self.get_memories(k=1)[0]
        #开始执行动作
        code_text = await todo.run(msg.content)
        #将动作的结果封装成消息形式返回,方便与其他Agent通信使用吧
        msg = Message(content=code_text,role=self.profile, cause_by=type(todo))

        return msg

async def main():
    msg = "write a function that calculates the sum of a list"
    role = SimpleCoder()
    logger.info(msg)
    result = await role.run(msg)
    logger.info(result)

asyncio.run(main())

logger里会详细记录运行过程及各种设置,可以仔细研究

运行结果正确

相关推荐
归去来?11 分钟前
记录一次从https接口提取25G大文件csv并落表的经历
大数据·数据仓库·hive·python·网络协议·5g·https
喵手12 分钟前
Python爬虫零基础入门【第三章:Requests 静态爬取入门·第1节】你的第一个爬虫:抓取页面并保存 HTML!
爬虫·python·爬虫实战·python爬虫工程化实战·requests静态爬取·抓取网页并保存html·零基础入门python爬虫
喵手14 分钟前
Python爬虫零基础入门【第三章:Requests 静态爬取入门·第2节】伪装与会话:Headers、Session、Cookie(合规使用)!
爬虫·python·python爬虫实战·python爬虫工程化实战·requests静态爬取·伪装与会话·零基础python爬虫入门
小白学大数据44 分钟前
绕过拼多多 App 反抓包机制的综合逆向解决方案
开发语言·爬虫·python·自动化
使者大牙1 小时前
【单点知识】 Python装饰器介绍
开发语言·数据库·python
Jackson@ML1 小时前
2026最新版Sublime Text 4安装使用指南
java·python·编辑器·sublime text
TonyLee0171 小时前
半监督学习介绍
人工智能·python·深度学习·机器学习
kong79069281 小时前
Python核心语法-Python自定义模块、Python包
开发语言·python·python核心语法
OLOLOadsd1231 小时前
基于Mask-RCNN和RegNetX的茎蛀虫检测识别系统详解
python
半路_出家ren1 小时前
1.古典密码概述
python·网络安全·密码学·古典密码·加密方式