首页 > 其他分享 >2.metagpt中的软件公司智能体 (ProductManager 角色)

2.metagpt中的软件公司智能体 (ProductManager 角色)

时间:2024-12-16 21:59:02浏览次数:6  
标签:Product self Game metagpt game str 软件 ProductManager

1. 代码

ProductManager 类

from metagpt.actions import UserRequirement, WritePRD
from metagpt.actions.prepare_documents import PrepareDocuments
from metagpt.roles.role import Role, RoleReactMode
from metagpt.utils.common import any_to_name


class ProductManager(Role):
    """
    Represents a Product Manager role responsible for product development and management.

    Attributes:
        name (str): Name of the product manager.
        profile (str): Role profile, default is 'Product Manager'.
        goal (str): Goal of the product manager.
        constraints (str): Constraints or limitations for the product manager.
    """

    name: str = "Alice"
    profile: str = "Product Manager"
    goal: str = "efficiently create a successful product that meets market demands and user expectations"
    constraints: str = "utilize the same language as the user requirements for seamless communication"
    todo_action: str = ""

    def __init__(self, **kwargs) -> None:
        super().__init__(**kwargs)

        self.set_actions([PrepareDocuments, WritePRD])
        self._watch([UserRequirement, PrepareDocuments])
        self.rc.react_mode = RoleReactMode.BY_ORDER
        self.todo_action = any_to_name(WritePRD)

    async def _observe(self, ignore_memory=False) -> int:
        return await super()._observe(ignore_memory=True)

context上下文,即数据结构

# 初始化 Context
context = Context()

断言

assert context.git_repo is None
assert context.repo is None

2. 示例:

from metagpt.schema import Message
USER_REQUIREMENT = """开发一个贪吃蛇游戏"""

user_msg = Message(role="User", content=USER_REQUIREMENT, cause_by=UserRequirement)
product_manager = ProductManager(context=context)
rsp = await product_manager.run(user_msg)

输出:

2024-12-16 21:37:30.446 | INFO     | metagpt.roles.role:_act:403 - Alice(Product Manager): to do PrepareDocuments(PrepareDocuments)
2024-12-16 21:37:31.897 | INFO     | metagpt.utils.file_repository:save:57 - save to: D:\llm\MetaGPT\workspace\20241216213730\docs\requirement.txt
2024-12-16 21:37:31.898 | INFO     | metagpt.roles.role:_act:403 - Alice(Product Manager): to do WritePRD(WritePRD)
2024-12-16 21:37:31.900 | INFO     | metagpt.actions.write_prd:run:86 - New requirement detected: 开发一个贪吃蛇游戏


[CONTENT]
{
    "Language": "en_us",
    "Programming Language": "Python",
    "Original Requirements": "开发一个贪吃蛇游戏",
    "Project Name": "snake_game",
    "Product Goals": [
        "Create an engaging and intuitive user experience",
        "Ensure the game is scalable and performs well on various devices",
        "Implement a high-quality UI/UX design"
    ],
    "User Stories": [
        "As a player, I want to easily navigate the game controls to play the game",
        "As a player, I want to see my score and high scores displayed clearly on the screen",
        "As a player, I want the ability to pause and resume the game at any time",
        "As a player, I want to have the option to restart the game from the beginning",
        "As a player, I want the game to be visually appealing and responsive on different screen sizes"
    ],
    "Competitive Analysis": [
        "Snake Game A: Basic gameplay, lacks advanced features and customization",
        "Snake Game B: Offers a variety of themes and power-ups, but can be slow on older devices",
        "Snake Game C: Features a simple and clean UI, but lacks multiplayer functionality"
    ],
    "Competitive Quadrant Chart": "quadrantChart\n    title \"Performance and User Engagement\"\n    x-axis \"Low Performance\" --> \"High Performance\"\n    y-axis \"Low Engagement\" --> \"High Engagement\"\n    quadrant-1 \"We should expand\"\n    quadrant-2 \"Need to promote\"\n    quadrant-3 \"Re-evaluate\"\n    quadrant-4 \"May be improved\"\n    \"Game A\": [0.2, 0.4]\n    \"Game B\": [0.5, 0.6]\n    \"Game C\": [0.3, 0.5]\n    \"Our Target Product\": [0.7, 0.7]",
    "Requirement Analysis": "The game should be designed to be accessible to players of all skill levels, with a focus on ease of use and a high-quality visual experience. The game should also be optimized for performance on a range of devices, from low-end to high-end.",
    "Requirement Pool": [
        [
            "P0",
            "Develop the core gameplay logic for the snake movement and food generation"
        ],
        [
            "P0",
            "Implement a user-friendly interface with clear score tracking and game controls"
        ],
        [
            "P1",
            "Add features such as pause, resume, and restart functionality"
        ],
        [
            "P1",
            "Optimize the game for performance on various devices"
        ],
        [
            "P2",
            "Design and implement a high-quality UI/UX"
        ]
    ],
    "UI Design draft": "A simple and intuitive UI with a clear score display, easy-to-use controls, and a responsive design that adapts to different screen sizes.",
    "Anything UNCLEAR": "It is unclear whether there are specific design preferences or branding requirements for the game."
}
[/CONTENT]

2024-12-16 21:37:53.890 | WARNING  | metagpt.utils.cost_manager:update_cost:49 - Model GLM-4-flash not found in TOKEN_COSTS.
2024-12-16 21:37:53.951 | WARNING  | metagpt.utils.git_repository:rename_root:214 - Move D:\llm\MetaGPT\workspace\20241216213730 to D:\llm\MetaGPT\workspace\snake_game error: [WinError 32] 另一个程序正在使用此文件,进程无法访问。: 'D:\\llm\\MetaGPT\\workspace\\20241216213730'
2024-12-16 21:37:53.952 | INFO     | metagpt.utils.git_repository:rename_root:219 - Rename directory D:\llm\MetaGPT\workspace\20241216213730 to D:\llm\MetaGPT\workspace\snake_game

2024-12-16 21:37:54.134 | INFO     | metagpt.utils.file_repository:save:57 - save to: D:\llm\MetaGPT\workspace\snake_game\docs\prd\20241216213754.json
2024-12-16 21:37:54.191 | WARNING  | metagpt.utils.mermaid:mermaid_to_file:35 - RUN `npm install -g @mermaid-js/mermaid-cli` to install mmdc,or consider changing engine to `playwright`, `pyppeteer`, or `ink`.
2024-12-16 21:37:54.193 | INFO     | metagpt.utils.file_repository:save:57 - save to: D:\llm\MetaGPT\workspace\snake_game\resources\prd\20241216213754.md

解释:
- 根据用户消息生成项目结构,并在requirement文件中添加用户消息
- 在项目结构的prd文件中添加内容

print(rsp)
Alice(Product Manager): {'docs': {'20241216213754.json': {'root_path': 'docs\\prd', 'filename': '20241216213754.json', 'content': '{"Language":"en_us","Programming Language":"Python","Original Requirements":"开发一个贪吃蛇游戏","Project Name":"snake_game","Product Goals":["Create an engaging and intuitive user experience","Ensure the game is scalable and performs well on various devices","Implement a high-quality UI/UX design"],"User Stories":["As a player, I want to easily navigate the game controls to play the game","As a player, I want to see my score and high scores displayed clearly on the screen","As a player, I want the ability to pause and resume the game at any time","As a player, I want to have the option to restart the game from the beginning","As a player, I want the game to be visually appealing and responsive on different screen sizes"],"Competitive Analysis":["Snake Game A: Basic gameplay, lacks advanced features and customization","Snake Game B: Offers a variety of themes and power-ups, but can be slow on older devices","Snake Game C: Features a simple and clean UI, but lacks multiplayer functionality"],"Competitive Quadrant Chart":"quadrantChart\\n    title \\"Performance and User Engagement\\"\\n    x-axis \\"Low Performance\\" --> \\"High Performance\\"\\n    y-axis \\"Low Engagement\\" --> \\"High Engagement\\"\\n    quadrant-1 \\"We should expand\\"\\n    quadrant-2 \\"Need to promote\\"\\n    quadrant-3 \\"Re-evaluate\\"\\n    quadrant-4 \\"May be improved\\"\\n    \\"Game A\\": [0.2, 0.4]\\n    \\"Game B\\": [0.5, 0.6]\\n    \\"Game C\\": [0.3, 0.5]\\n    \\"Our Target Product\\": [0.7, 0.7]","Requirement Analysis":"The game should be designed to be accessible to players of all skill levels, with a focus on ease of use and a high-quality visual experience. The game should also be optimized for performance on a range of devices, from low-end to high-end.","Requirement Pool":[["P0","Develop the core gameplay logic for the snake movement and food generation"],["P0","Implement a user-friendly interface with clear score tracking and game controls"],["P1","Add features such as pause, resume, and restart functionality"],["P1","Optimize the game for performance on various devices"],["P2","Design and implement a high-quality UI/UX"]],"UI Design draft":"A simple and intuitive UI with a clear score display, easy-to-use controls, and a responsive design that adapts to different screen sizes.","Anything UNCLEAR":"It is unclear whether there are specific design preferences or branding requirements for the game."}'}}}

3. 代码解释

ProductManager(产品经理)角色类,继承自 Role 类,主要用于模拟产品经理在一个工作流中的行为,尤其是在产品开发过程中。

以下是对代码的逐部分解释:

类 ProductManager 说明
ProductManager 代表一个产品经理角色,负责产品开发和管理。
类中定义了几个主要属性:name、profile、goal 和 constraints,用来描述产品经理的基本信息和角色目标。
属性

  • name: str = “Alice”:定义了产品经理的名字为 Alice。
  • profile: str = “Product Manager”:定义了角色的身份为“产品经理”。
  • goal: str = “efficiently create a successful product that meets market demands and user expectations”:定义了产品经理的目标,即“有效地创建一个符合市场需求和用户期望的成功产品”。
  • constraints: str = “utilize the same language as the user requirements for seamless communication”:定义了产品经理的约束条件,即“使用与用户需求一致的语言进行无缝沟通”。
  • todo_action: str = “”:初始化了待执行的任务动作为空字符串。

init 方法
该方法初始化 ProductManager 类的实例。

  • super().init(**kwargs):调用父类 Role 的初始化方法,以确保继承的属性得到正确初始化。
  • self.set_actions([PrepareDocuments, WritePRD]):设置该角色可以执行的动作。这里设置了两个动作,分别是 PrepareDocuments(准备文档)和 WritePRD(撰写产品需求文档)。
  • self._watch([UserRequirement, PrepareDocuments]):使角色“观察” UserRequirement 和 PrepareDocuments 这两个事件或动作。观察是为了跟踪某些条件或状态的变化。
  • self.rc.react_mode = RoleReactMode.BY_ORDER:设置角色的反应模式为“按顺序反应”,意味着角色将按照顺序执行动作。
  • self.todo_action = any_to_name(WritePRD):将 WritePRD 动作的名称赋值给 todo_action,可能是为了后续跟踪或执行。

async def _observe(self, ignore_memory=False) -> int 方法

  • 这是一个异步方法,用于观察并执行某些操作。该方法通过调用父类的 _observe 方法来实现观察,并返回一个整数值,表示观察结果。ignore_memory 参数默认设置为 False,表示是否忽略记忆。

标签:Product,self,Game,metagpt,game,str,软件,ProductManager
From: https://blog.csdn.net/qq_41472205/article/details/144519033

相关文章

  • 软件著作权申请教程(超详细)(2024新版)软著申请
                         目录一、注册账号与实名登记二、材料准备三、申请步骤1.办理身份2.软件申请信息3.软件开发信息4.软件功能与特点5.填报完成一、注册账号与实名登记    首先我们需要在官网里面注册一个账号,并且完成实名认证,一般......
  • 安卓移动设备软件开发期末复习(1) 控件
    监听器监听器是事件监听机制的重要组成部分。在Java中每类事件都定义了一个相应的监听器接口,该接口定义了接收和处理事件的方法。实现该接口的类,其对象可作为监听器对象注册在事件源组件上。在图形用户界面中,需要响应用户操作的相关组件要注册一个或多个相应事件的监听器......
  • converge许可管理工具和软件的选择
    随着企业数字化转型的步伐加快,团队协作和许可管理变得越来越重要。在众多许可管理工具和软件中,如何选择最适合您的Converge许可管理工具和软件呢?本文将为您提供一些指导建议,帮助您做出明智的选择。一、明确需求与目标在选择Converge许可管理工具和软件之前,首先要明确您的需求和......
  • 跨境电商新利器:看板软件解锁圣诞节消费者心理
    看板软件在助力跨境电商探究圣诞节消费者心理倾向方面发挥着重要作用。以下详细阐述看板软件如何助力这一过程:一、整合多源数据,全面了解市场看板软件能够从多个数据源导入数据,包括电商平台数据、社交媒体数据、市场研究报告等,为跨境电商提供丰富的市场信息和消费者行为数据。这......
  • 7年软件测试转行,可做什么工作呢?
    这是网友的一则发帖。笔者有很多成功从测试转行进入网络安全领域,这是一个既具有挑战性又有发展前景的职业方向。以下是几个步骤和建议来帮助你成功转型:了解行业:首先,研究网络安全的基本概念、领域分类(如网络防御、渗透测试、数据安全等),以及当前市场上的热门技术和职业角......
  • 跨境电商圣诞营销思路——合理利用项目管理软件
    借助项目管理软件进行跨境电商圣诞节营销,可以更加高效、有序地推进营销活动,确保各个环节的顺利进行。以下是一些建议,帮助跨境电商企业利用项目管理软件进行圣诞节营销:一、明确营销目标与计划设定具体目标:确定营销活动的具体目标,如提高销售额、增加品牌知名度等。将目标分解为......
  • 推荐一款强大的开源物联网 Web 组态软件
    前言快速发展的物联网(IoT)领域,设备管理和监控的需求日益增长。为了满足这一需求并提供更高效的解决方案。向大家推荐一款强大的开源物联网Web组态软件。这款软件不仅具备灵活的可视化配置功能,还提供了丰富的工具和接口,轻松实现设备集成、数据监控和远程管理。项目介绍一拖一拽,......
  • IO软件层次结构
    IO软件层次结构‍​​‍​​‍一、用户层软件向上实现了用户接口,向下翻译为系统调用。​​‍二、设备独立性软件(设备无关性软件)与设备的硬件特性无关的功能几乎都在这一层实现。主要实现的功能:向上层提供统一的调用接口(如read/write系统调用)设备的保护原理......
  • web组态软件开发详细流程介绍
     什么是组态软件?组态软件是一种用于创建、配置和管理各种工业控制系统的应用程序。它通过用户友好的图形界面和先进的功能,使工程师能够实时监控和控制复杂的工业过程。一、组态软件的基本概念1.1组态软件的作用组态软件在工业控制系统中起到关键的作用。它可以实时获......
  • 软件缺少d3dx10_38.dll文件及错误提示问题
    其实很多用户玩单机游戏或者安装软件的时候就出现过这种问题,如果是新手第一时间会认为是软件或游戏出错了,其实并不是这样,其主要原因就是你电脑系统的该dll文件丢失了或没有安装一些系统软件平台所需要的动态链接库,这时你可以下载这个d3dx10_38.dll文件(挑选合适的版本文件)把它......