The MetaGPT Project
- The MetaGPT Site
- The MetaGPT Code at Github
- License: MIT ❤️
A F/OSS Multi Agent Framework that will power your next Projects.
MetaGPT with Python
It all comes down to The MetaGPT Python Package 🐍
You can try it with:
sudo apt install python3-pip
pip install --upgrade metagpt #from Pypi
#from Github (2 ways) =>
#pip install --upgrade git+https://github.com/geekan/MetaGPT.git
#or this one =>
# git clone https://github.com/geekan/MetaGPT ./MetaGPT
# cd MetaGPT
# pip install --upgrade -e .
How to Configure MetaGPT
# Check https://docs.deepwisdom.ai/main/en/guide/get_started/configuration.html for more details
metagpt --init-config # it will create ~/.metagpt/config2.yaml, just modify it to your needs
Using MetaGPT with OpenAI
export OPENAI_API_KEY=your-api-key # on Linux/Mac
This is not a fully open source way, but you can test that it works.
Using MetaGPT with Ollama
Now, this is where the we get this project to work fully Open Source.
You can get Ollama installed with Docker and then use it as end point (instead of the OpenAI with its API key).
Selfhosting AI Agents with MetaGPT
Pre-Requisites - Get Docker! 🐋👇
Important step and quite recommended for any SelfHosting Project - Get Docker Installed
It will be one command, this one, if you are in Linux:
apt-get update && sudo apt-get upgrade && curl -fsSL https://get.docker.com -o get-docker.sh
sh get-docker.sh && docker version
These instructions outline how to pull the official metagpt/metagpt:latest
Docker image, prepare a configuration file (config2.yaml
), and run the Metagpt application in a Docker container to execute specific tasks or commands.
You can find it here.
Prepare the Configuration
- Pull the Official Image: This step downloads the latest version of the
metagpt/metagpt
image from Docker Hub (or another configured registry) to your local machine.
docker pull metagpt/metagpt:latest
- Create Directories: This creates two directories on your host system: one for configuration files (
config
) and another for the workspace (workspace
). These directories will be used to store persistent data outside of the Docker container.
mkdir -p /opt/metagpt/config
- Extract Default Configuration File: This command runs a temporary container from the
metagpt/metagpt:latest
image, extracts the defaultconfig2.yaml
file from within the container, and saves it to the newly createdconfig
directory on your host. This is a read-only operation (--rm
flag ensures the container is removed after the command runs).
docker run --rm metagpt/metagpt:latest cat /app/metagpt/config/config2.yaml | sudo tee /opt/metagpt/config/config2.yaml > /dev/null
- Edit the Configuration File: Using
vim
(or any other text editor), you can modify theconfig2.yaml
file according to your needs. This step is crucial for customizing the behavior of the Metagpt application.
vim /opt/metagpt/config/config2.yaml
Run Metagpt in a Container
- Run Metagpt with a Specific Command: This command starts a container with the
metagpt/metagpt:latest
image, mounting the host’sconfig2.yaml
andworkspace
directory into the container. It then executes a predefined Metagpt task (in this case, “Write a cli snake game”). The--rm
flag means the container will be automatically removed after it stops.
docker run --rm \
--privileged \
-v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
metagpt/metagpt:latest \
metagpt "Write a cli snake game"
- Start a Persistent Container: This alternative approach starts a named (
--name metagpt
) and detached (-d
) container with the same volume mounts. The container remains running in the background.
docker run --name metagpt -d \
--privileged \
-v /opt/metagpt/config/config2.yaml:/app/metagpt/config/config2.yaml \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
metagpt/metagpt:latest
- Interact with the Running Container: After the container is started, you can use
docker exec
to attach to it and run commands within the container environment. This allows for interactive tasks or further configuration.
docker exec -it metagpt /bin/bash
Once inside, you can execute Metagpt tasks or commands, such as writing a CLI snake game.
metagpt "Write a cli snake game"
Key Points:
- The
--privileged
flag grants the container extended permissions, which might be necessary for certain operations within the Metagpt application. - Volume mounts (
-v
) are used to persist data and configurations outside the container, allowing for data retention across container restarts or updates.
Example Usage MetaGPT
If you have performed previous step, from now on you can just do:
docker run --rm \
--privileged \
-v /opt/metagpt/config:/app/metagpt/config \
-v /opt/metagpt/workspace:/app/metagpt/workspace \
metagpt/metagpt:latest \
metagpt "Write a cli snake game" #now this will be any of your ideas
At the time of writing, this operation cost me 0.7$.
The results are in a persistant folder:
- Inside the container at: app/metagpt/workspace/cli_snake_game
- Which is mapped to /opt/metagpt/workspace/cli_snake_game
- From here you can run the app and iterate further