Skip to content

Incremental Development

You can improve exits project code through these steps:

  • Locate the folder of project created by MetaGPT which you want to improve anywhere on your computer
  • execute metagpt <new-idea-or-bug-feedback> --project-path <the-path-to-the-folder>

metagpt Options

By using the following parameters, it is possible to iterate continuously on the exists project generated by MetaGPT.

CLI Parameter NameValue TypeOptional/RequiredDescriptionUsage
--project-pathTEXTOptionalSpecify the directory path of the old version project to fulfill the incremental requirements.metagpt "BUG_FEEDBACK_XXX" --project-path "YOUR_PROJECT_FULL_PATH"

metagpt "INCREMENT_REQUIREMENTS" --project-path "YOUR_PROJECT_FULL_PATH"
--project-nameTEXTOptionalUnique project name, such as 'game_2048'.metagpt "NEW_REQUIREMENTS" --project-name "YOUR_PROJECT_NAME"

For more command options, check metagpt --help.


Demo

Using the example of Snake, we will demonstrate how to incrementally carry out software iterations.

Create a new Snake game project.

We use the following command parameters to create a Snake software project with gpt-3.5-turbo-1106.

shell
metagpt "Write a cli snake game based on pygame" --project-name "snake_game" --run-tests --n-round 20 --max-auto-summarize-code 1
metagpt "Write a cli snake game based on pygame" --project-name "snake_game" --run-tests --n-round 20 --max-auto-summarize-code 1

Among them, the functional descriptions of the relevant parameters are as follows:

CLI Parameter NameValueDescription
--project-name"snake_game"The folder name and project name for the newly created software project are "snake_game."
--run-testsEnable the unit testing phase.
--n-round20Perform 20 rounds.
--max-auto-summarize-code1Fixing issues found in the "summarize code" is allowed for up to 1 time.

The entire process is as follows: part1part2


Add new requirements to an existing project.

We use Azure's GPT-4 and the following parameters to append requirements:

shell
metagpt "Add a randomly appearing enemy that lasts for 5 seconds. If the enemy is eaten, the game ends. If the enemy is not eaten, it disappears after 5 seconds." --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" --run-tests --n-round 20 --max-auto-summarize-code 1
metagpt "Add a randomly appearing enemy that lasts for 5 seconds. If the enemy is eaten, the game ends. If the enemy is not eaten, it disappears after 5 seconds." --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" --run-tests --n-round 20 --max-auto-summarize-code 1

Among them, the functional descriptions of the relevant parameters are as follows:

CLI Parameter NameValueDescription
--project-path"/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game"Project path of the existing project.
--run-testsEnable the unit testing phase.
--n-round20Perform 20 rounds.
--max-auto-summarize-code1Fixing issues found in the "summarize code" is allowed for up to 1 time.

The entire process is as follows: part1part2part3part4part5 The final LLM request for code generation timed out, but it won't affect the subsequent incremental iterations of the project. Since the new requirements have already accumulated in the PRD, rerunning or adding new requirements will be based on the current PRD.


Fix Bug

We use Azure's GPT-4 and the following parameters to fix bugs. To demonstrate the bug-fixing process, we directly introduce erroneous code onto the generated code to trigger a bug. Subsequently, we submit the bug information as part of the requirement content, as shown below:

shell
metagpt "TypeError: draw() takes 1 positional argument but 2 were given" --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" --run-tests --n-round 10 --max-auto-summarize-code 0
metagpt "TypeError: draw() takes 1 positional argument but 2 were given" --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" --run-tests --n-round 10 --max-auto-summarize-code 0

Among them, the functional descriptions of the relevant parameters are as follows:

CLI Parameter NameValueDescription
--project-path"/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game"Project path of the existing project.
--run-testsEnable the unit testing phase.
--n-round10Perform 10 rounds.
--max-auto-summarize-code0Do not fixing issues found in the "summarize code".

The entire process is as follows: part1part2part3part4part5


Unresolved Issues

The Software Company is a laboratory project designed to showcase the capabilities of the MetaGPT framework rather than to address practical issues in production. Therefore, MetaGPT Software Company does not support the input of new requirements of the following nature:

  1. Requirements related to the architecture, such as how to write setup.py or requirements.txt.
  2. Specifying that a particular function should perform a specific operation.

The reasons for this are as follows:

  1. Such "requirements" are essentially constraints or instructions. Unlike true requirements, they specify functionality for certain modules within the system rather than overall system functionality.
  2. MetaGPT Software Company simplifies software development process into requirements to class views and sequence diagrams, which are then directly translated into source code. Design requirements for internal modules of the system, such as those mentioned above, lack a clear implementation process and are therefore discarded.

Edit Project Files

You can add new requirements by directly editing the project files generated by the Software Company. After making the necessary modifications to the relevant files, initiate a new round of incremental iteration using the metagpt command. Below is an explanation of the folder structure generated by the Software Company. Files to be used during the project iteration should be placed in the docs directory.

PathEditableDescription
.dependencies.jsonNoStore explicit dependency relationships among files.
docs/requirement.txtNoStore the newly added requirements for this iteration. During the project handling process, the contents inside will be split and merged into docs/prds/. Please modify this file using the metagpt command.
docs/bugfix.txtNoStore bug feedback information for this round.
During iterations, convert bug feedback into input for requirements; do not directly modify this file.
docs/prdsYesThe final breakdown of project requirements.
docs/system_designsYesThe ultimate system design for the project.
docs/tasksYesThe coding tasks for the project.
docs/code_summariesYesThe review outcomes for the entire codebase.
resources/competitive_analysisNoCompetitor analysis
resources/data_api_designNoClasses view files
resources/seq_flowNoSequence view files
resources/system_designNoSystem design files
resources/prdNoPRD files
resources/api_spec_and_tasksNoTask files for coding
tmpNoIntermediate files generated during the project handling process. These files will not be archived by git.
<workspace>YesProject source code directory
testsYesUnit test code
test_outputsNoResults of unit test execution

More Demos

Flappy Bird Game

  • New Project

Create a new flappy bird Game project with the command below using gpt-3.5-turbo-1106:

shell
metagpt "write a flappy bird game without any obstacles" --project-name "flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 0
metagpt "write a flappy bird game without any obstacles" --project-name "flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 0

video

Fix bug using azure gpt-4:

shell
metagpt "for event in pygame.event.get(): pygame.error: video system not initialized" --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 1
metagpt "for event in pygame.event.get(): pygame.error: video system not initialized" --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 1

video

We can see that game.py is continuously refactored through code review: imgimg

Besides, summarization code action also points out issues that were not found through code review, causing a new round of refactoring for game.py:

text
{
    "game.py": "Implement the 'jump' method in the 'Bird' class, the 'generate_obstacles' method in the 'Game' class, and improve the collision detection in the 'check_collision_and_update_score' method. Also, use the 'obstacles' attribute in the 'Game' class to store and manage the obstacles, and update the score in real-time in the 'draw' method.",
    "main.py": "No changes needed."
}
{
    "game.py": "Implement the 'jump' method in the 'Bird' class, the 'generate_obstacles' method in the 'Game' class, and improve the collision detection in the 'check_collision_and_update_score' method. Also, use the 'obstacles' attribute in the 'Game' class to store and manage the obstacles, and update the score in real-time in the 'draw' method.",
    "main.py": "No changes needed."
}

img Summarization code action can lead to unlimited and continuous refactoring of source code. However, we limit it to 1 round by setting --max-auto-summarize-code 1 to showcase the capabilities of summarization code action.

The following are available project versions:

img

  • Add New Requirements

    We'll add obstacles to the game using azure gpt-4. Before adding the new requirements:

imgimg

shell
metagpt "Add moving obstacles, move randomly, last for 5 seconds." --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 1
metagpt "Add moving obstacles, move randomly, last for 5 seconds." --project-path "/Users/iorishinier/github/bak/MetaGPT/workspace/flappy_bird" --run-tests --n-round 20 --max-auto-summarize-code 1

video

Here is the new class view and the sequence view:

imgimg

Released under the MIT License.