Skip to content

Quickstart

Installation

pip install metagpt
pip install metagpt

Available installation methods can be found in the Installation section

Setup

import os
os.environ["OPENAI_API_KEY"] = "sk-..."
os.environ["OPENAI_API_MODEL"] = "gpt-4"
import os
os.environ["OPENAI_API_KEY"] = "sk-..."
os.environ["OPENAI_API_MODEL"] = "gpt-4"

Variations for setting up LLM API (OpenAI, Azure, Anthropic, etc.) and other components can be found in the Setup section.

We use environment variables for a quick demo. For formal usage of MetaGPT, we recommend using a config or key file. See Setup.

Develop software with a one-line requirement

Note:

Below is a breakdown of the software startup example. If you install MetaGPT with the git clone approach, simply run

python startup.py --idea "write a cli blackjack game"
python startup.py --idea "write a cli blackjack game"

(Starting v0.5, use metagpt "write a cli blackjack game" instead)

Now, let's get started! We will create a team of agents to write software based on one line of our instruction.

First, import off-the-shelf roles

python
import asyncio
from metagpt.roles import (
    Architect,
    Engineer,
    ProductManager,
    ProjectManager,
)
from metagpt.team import Team
import asyncio
from metagpt.roles import (
    Architect,
    Engineer,
    ProductManager,
    ProjectManager,
)
from metagpt.team import Team

Next, initiate the team, equip it with agents, set their budget, and provide our requirement of writing a small game

python
async def startup(idea: str):
    company = Team()
    company.hire(
        [
            ProductManager(),
            Architect(),
            ProjectManager(),
            Engineer(),
        ]
    )
    company.invest(investment=3.0)
    company.start_project(idea=idea)

    await company.run(n_round=5)
async def startup(idea: str):
    company = Team()
    company.hire(
        [
            ProductManager(),
            Architect(),
            ProjectManager(),
            Engineer(),
        ]
    )
    company.invest(investment=3.0)
    company.start_project(idea=idea)

    await company.run(n_round=5)

Finally, run it and get the code!

python
await startup(idea="write a cli blackjack game")
await startup(idea="write a cli blackjack game")

You may expect similar outputs below:

Try this example on the spot:

Open In Colab

Released under the MIT License.