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 Name | Value Type | Optional/Required | Description | Usage |
---|---|---|---|---|
--project-path | TEXT | Optional | Specify 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-name | TEXT | Optional | Unique 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.
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 Name | Value | Description |
---|---|---|
--project-name | "snake_game" | The folder name and project name for the newly created software project are "snake_game." |
--run-tests | Enable the unit testing phase. | |
--n-round | 20 | Perform 20 rounds. |
--max-auto-summarize-code | 1 | Fixing issues found in the "summarize code" is allowed for up to 1 time. |
The entire process is as follows:
Add new requirements to an existing project.
We use Azure's GPT-4 and the following parameters to append requirements:
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 Name | Value | Description |
---|---|---|
--project-path | "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" | Project path of the existing project. |
--run-tests | Enable the unit testing phase. | |
--n-round | 20 | Perform 20 rounds. |
--max-auto-summarize-code | 1 | Fixing issues found in the "summarize code" is allowed for up to 1 time. |
The entire process is as follows: 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:
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 Name | Value | Description |
---|---|---|
--project-path | "/Users/iorishinier/github/bak/MetaGPT/workspace/snake_game" | Project path of the existing project. |
--run-tests | Enable the unit testing phase. | |
--n-round | 10 | Perform 10 rounds. |
--max-auto-summarize-code | 0 | Do not fixing issues found in the "summarize code". |
The entire process is as follows:
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:
- Requirements related to the architecture, such as how to write setup.py or requirements.txt.
- Specifying that a particular function should perform a specific operation.
The reasons for this are as follows:
- Such "requirements" are essentially constraints or instructions. Unlike true requirements, they specify functionality for certain modules within the system rather than overall system functionality.
- 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.
Path | Editable | Description |
---|---|---|
.dependencies.json | No | Store explicit dependency relationships among files. |
docs/requirement.txt | No | Store 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.txt | No | Store bug feedback information for this round. During iterations, convert bug feedback into input for requirements; do not directly modify this file. |
docs/prds | Yes | The final breakdown of project requirements. |
docs/system_designs | Yes | The ultimate system design for the project. |
docs/tasks | Yes | The coding tasks for the project. |
docs/code_summaries | Yes | The review outcomes for the entire codebase. |
resources/competitive_analysis | No | Competitor analysis |
resources/data_api_design | No | Classes view files |
resources/seq_flow | No | Sequence view files |
resources/system_design | No | System design files |
resources/prd | No | PRD files |
resources/api_spec_and_tasks | No | Task files for coding |
tmp | No | Intermediate files generated during the project handling process. These files will not be archived by git. |
<workspace> | Yes | Project source code directory |
tests | Yes | Unit test code |
test_outputs | No | Results 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:
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
Fix bug
Fix bug using azure gpt-4:
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
We can see that game.py is continuously refactored through code review:
Besides, summarization code action also points out issues that were not found through code review, causing a new round of refactoring for game.py:
{
"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."
}
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:
Add New Requirements
We'll add obstacles to the game using azure gpt-4. Before adding the new requirements:
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
Here is the new class view and the sequence view: