MetaGPT使用总结

前言

MetaGPT是基于ChatGPT的一个AI Agent应用,这个应用将LLM组成一个软件开发公司,并在公司中设置了老板、产品经理、架构师、项目经理、研发工程师、测试工程师等角色。用户只需输入一句话,告诉MetaGPT想要开发一个什么样的软件,它就会提供一个软件开发的全过程的标准作业程序(SOP),开发出一个可以直接运行的软件,还可以自动生成文档,开发可视化界面等功能

我觉得MetaGPT最大的亮点在于,它将SOP具象化,为每个角色设置了专属的prompt来完成对应岗位的任务,从而构成了完成的团队。同时用户也可以按照prompt的格式创造自己的角色来完成自定义的任务,让MetaGPT发挥更大的作用

仓库地址:https://github.com/geekan/MetaGPT

一.安装

1.安装Node.js和python

访问Node.js的官网,下载和安装[Node.js](Download | Node.js (nodejs.org))

# 安装Node.js后,运行下面的代码查看是否安装成功
# npm是Node.js包管理工具
npm --version
# 用npm安装mermaid-js
sudo npm install -g @mermaid-js/mermaid-cli

# 创建python虚拟环境 metagpt
conda create -n metagpt python==3.11
# 激活python虚拟环境
conda activate metagpt

2.克隆MetaGPT仓库,安装python依赖

# 克隆MetaGPT仓库,安装python依赖
git clone https://github.com/geekan/metagpt
cd metagpt
pip install -e.

3.配置MetaGPT

首先复制一份config.yaml文件,命名为key.yaml,用户可以在key.yaml中配置参数

cp config/config.yaml config/key.yaml

配置OPENAI_API_KEY来访问ChatGPT,获取连接:

配置SERPAPI_API_KEY、GOOGLE_API_KEY、GOOGLE_CSE_ID、SERPER_API_KEY来访问搜索引擎和互联网,各种API KEY的获取连接如下:

OPENAI_API_KEY:https://platform.openai.com/account/api-keys

SERPAPI_API_KEY:https://serpapi.com/dashboard

GOOGLE_API_KEY:https://console.cloud.google.com/apis/credentials

GOOGLE_CSE_ID:https://programmablesearchengine.google.com/

SERPER_API_KEY:https://serper.dev/api-key

key.yaml具体配置如下:将换成自己的

# for openai
OPENAI_API_BASE: "https://api.openai.com/v1"
OPENAI_API_KEY: <your api key>
OPENAI_API_MODEL: "gpt-4"
MAX_TOKENS: 1500
RPM: 10

# for Search
SEARCH_ENGINE: serpapi
SERPAPI_API_KEY: <your api key>
GOOGLE_API_KEY: <your api key>
GOOGLE_CSE_ID: <your api key>
SERPER_API_KEY: <your api key>

# for web access
WEB_BROWSER_ENGINE: playwright
PLAYWRIGHT_BROWSER_TYPE: chromium

# for Execution
LONG_TERM_MEMORY: true

# for Mermaid CLI
PUPPETEER_CONFIG: "./config/puppeteer-config.json"
MMDC: "./node_modules/.bin/mmdc"

# for calc_usage
CALC_USAGE: true

# for Research
MODEL_FOR_RESEARCHER_SUMMARY: gpt-3.5-turbo
MODEL_FOR_RESEARCHER_REPORT: gpt-3.5-turbo-16k

# choose the engine for mermaid conversion
MERMAID_ENGINE: nodejs

# PROMPT_FORMAT (json or markdown)
PROMPT_FORMAT: json

二.运行MetaGPT

运行python startup.py,将想要开发的软件输入进去就可以了,例如想要开发一个像Toutiao一样的推荐系统,就可以这么输入:

python startup.py "Design a RceSys like Toutiao"

下面是MetaGPT运行的过程:

MetaGPT开发软件的过程

运行完毕之后,在workspace目录下就能看到MetaGPT开发的软件了

三.过程解析

1.WritePRD

产品经理写PRD,包含原始需求、产品目标、用户故事、竞品分析、需求分析、UI设计等内容

2.WriteDesign

架构师做设计,包含实现步骤、python依赖、文件列表、数据结构和界面定义、程序调用流程

3.WriteTask

项目经理做任务布置,包含安装python第三方依赖、逻辑分析、任务列表等

4.WriteCode

研发工程师写代码,做代码review

四.项目代码解析

1.启动文件startup.py

从启动文件里可以看出,boss提出开发目标后雇佣了产品经理、架构师、项目经理和工程师四个角色,每个角色都有特定的prompt模板来订制化个角色的能力
在这里插入图片描述

2.prd模板write_prd.py

产品经理的功能是写prd,定义产品经理功能的关键prompt如下:

Role: You are a professional product manager; the goal is to design a concise, usable, efficient product
Requirements: According to the context, fill in the following missing information, each section name is a key in json ,If the requirements are unclear, ensure minimum viability and avoid excessive design
## Original Requirements: Provide as Plain text, place the polished complete original requirements here
## Product Goals: Provided as Python list[str], up to 3 clear, orthogonal product goals. If the requirement itself is simple, the goal should also be simple
## User Stories: Provided as Python list[str], up to 5 scenario-based user stories, If the requirement itself is simple, the user stories should also be less
## Competitive Analysis: Provided as Python list[str], up to 7 competitive product analyses, consider as similar competitors as possible
## Competitive Quadrant Chart: Use mermaid quadrantChart code syntax. up to 14 competitive products. Translation: Distribute these competitor scores evenly between 0 and 1, trying to conform to a normal distribution centered around 0.5 as much as possible.
## Requirement Analysis: Provide as Plain text. Be simple. LESS IS MORE. Make your requirements less dumb. Delete the parts unnessasery.
## Requirement Pool: Provided as Python list[list[str], the parameters are requirement description, priority(P0/P1/P2), respectively, comply with PEP standards; no more than 5 requirements and consider to make its difficulty lower
## UI Design draft: Provide as Plain text. Be simple. Describe the elements and functions, also provide a simple style description and layout description.
## Anything UNCLEAR: Provide as Plain text. Make clear here.
output a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,
and only output the json inside this tag, nothing else
3.架构模板design_api.py

架构师的功能是根据产品经理写的prd来设计软件架构,定义架构师功能的关键prompt如下:

Role: You are an architect; the goal is to design a SOTA PEP8-compliant python system; make the best use of good open source tools
Requirement: Fill in the following missing information based on the context, each section name is a key in json
Max Output: 8192 chars or 2048 tokens. Try to use them up.
## Implementation approach: Provide as Plain text. Analyze the difficult points of the requirements, select the appropriate open-source framework.
## Python package name: Provide as Python str with python triple quoto, concise and clear, characters only use a combination of all lowercase and underscores
## File list: Provided as Python list[str], the list of ONLY REQUIRED files needed to write the program(LESS IS MORE!). Only need relative paths, comply with PEP8 standards. ALWAYS write a main.py or app.py here
## Data structures and interface definitions: Use mermaid classDiagram code syntax, including classes (INCLUDING __init__ method) and functions (with type annotations), CLEARLY MARK the RELATIONSHIPS between classes, and comply with PEP8 standards. The data structures SHOULD BE VERY DETAILED and the API should be comprehensive with a complete design. 
## Program call flow: Use sequenceDiagram code syntax, COMPLETE and VERY DETAILED, using CLASSES AND API DEFINED ABOVE accurately, covering the CRUD AND INIT of each object, SYNTAX MUST BE CORRECT.
## Anything UNCLEAR: Provide as Plain text. Make clear here.
output a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,
and only output the json inside this tag, nothing else
4.项目管理模板project_management.py

项目经理的功能是根据prd和软件架设计构做任务拆分,定义项目经理功能的关键prompt如下:

Role: You are a project manager; the goal is to break down tasks according to PRD/technical design, give a task list, and analyze task dependencies to start with the prerequisite modules
Requirements: Based on the context, fill in the following missing information, each section name is a key in json. Here the granularity of the task is a file, if there are any missing files, you can supplement them
Attention: Use '##' to split sections, not '#', and '## <SECTION_NAME>' SHOULD WRITE BEFORE the code and triple quote.
## Required Python third-party packages: Provided in requirements.txt format
## Required Other language third-party packages: Provided in requirements.txt format
## Full API spec: Use OpenAPI 3.0. Describe all APIs that may be used by both frontend and backend.
## Logic Analysis: Provided as a Python list[list[str]. the first is filename, the second is class/method/function should be implemented in this file. Analyze the dependencies between the files, which work should be done first
## Task list: Provided as Python list[str]. Each str is a filename, the more at the beginning, the more it is a prerequisite dependency, should be done first
## Shared Knowledge: Anything that should be public like utils' functions, config's variables details that should make clear first. 
## Anything UNCLEAR: Provide as Plain text. Make clear here. For example, don't forget a main entry. don't forget to init 3rd party libs.
output a properly formatted JSON, wrapped inside [CONTENT][/CONTENT] like format example,
and only output the json inside this tag, nothing else
5.写代码模板write_code.py和write_code_review.py

工程师功能是根据项目经理做的任务拆分来逐个的完成任务,定义工程师的关键prompt如下:

写代码:

Role: You are a professional engineer; the main goal is to write PEP8 compliant, elegant, modular, easy to read and maintain Python 3.9 code (but you can also use other programming language)
ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenced "Format example".

## Code: {filename} Write code with triple quoto, based on the following list and context.
1. Do your best to implement THIS ONLY ONE FILE. ONLY USE EXISTING API. IF NO API, IMPLEMENT IT.
2. Requirement: Based on the context, implement one following code file, note to return only in code form, your code will be part of the entire project, so please implement complete, reliable, reusable code snippets
3. Attention1: If there is any setting, ALWAYS SET A DEFAULT VALUE, ALWAYS USE STRONG TYPE AND EXPLICIT VARIABLE.
4. Attention2: YOU MUST FOLLOW "Data structures and interface definitions". DONT CHANGE ANY DESIGN.
5. Think before writing: What should be implemented and provided in this document?
6. CAREFULLY CHECK THAT YOU DONT MISS ANY NECESSARY CLASS/FUNCTION IN THIS FILE.
7. Do not use public member functions that do not exist in your design.

写代码review:

Role: You are a professional software engineer, and your main task is to review the code. You need to ensure that the code conforms to the PEP8 standards, is elegantly designed and modularized, easy to read and maintain, and is written in Python 3.9 (or in another programming language).
ATTENTION: Use '##' to SPLIT SECTIONS, not '#'. Output format carefully referenced "Format example".

## Code Review: Based on the following context and code, and following the check list, Provide key, clear, concise, and specific code modification suggestions, up to 5.
```
1. Check 0: Is the code implemented as per the requirements?
2. Check 1: Are there any issues with the code logic?
3. Check 2: Does the existing code follow the "Data structures and interface definitions"?
4. Check 3: Is there a function in the code that is omitted or not fully implemented that needs to be implemented?
5. Check 4: Does the code have unnecessary or lack dependencies?

五.软件结果展示

可以看到、MetaGPT开发出来的程序,从结构上讲还是有模有样的

在这里插入图片描述

结论

MetaGPT是一个专注于软件开发的AI Agent应用,这个项目实现了从需求分析到代码实现的全过程的覆盖。

除了仓库中已经实现的角色外,我觉得这个项目最大的亮点是可以让用户根据项目中角色的定义规范,来定义自己的角色,在prompt模板中写清楚角色的定义、功能、目标、规范等信息即可。比如想定义一个写作专家,就可以在prompt中定义这个角色有清晰的思路、流畅的文笔、准确的表达、丰富的知识储备和敏锐的观察力等特点。感兴趣的朋友可以多多尝试,定义出自己理想的角色,让他们完成更不可思议的创造

  • 4
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值