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-1106-preview"
import os
os.environ["OPENAI_API_KEY"] = "sk-..."
os.environ["OPENAI_API_MODEL"] = "gpt-4-1106-preview"

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

metagpt "write a cli blackjack game"
metagpt "write a cli blackjack game"

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.run_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.run_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.